Recently in doing Prometheus monitoring, combined with Grafana to do front-end display, which involves memory time, there are many people on the memories of free and memory avaliable These two parameters are more confused, Here I use the Linux under the common view of memory usage of the free command, to do the next solution collation.
Linux View memory usage, you can view/proc/meminfo and use the free command.
root@prometheus-01:~# cat /proc/meminfo && free
MemTotal: 16433020 kB
MemFree: 14714596 kB
MemAvailable: 15812952 kB
Buffers: 197912 kB
Cached: 1020632 kB
SwapCached: 0 kB
Active: 1168468 kB
Inactive: 328608 kB
Active(anon): 278888 kB
Inactive(anon): 376 kB
Active(file): 889580 kB
Inactive(file): 328232 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 8388604 kB
SwapFree: 8388604 kB
Dirty: 36 kB
Writeback: 0 kB
AnonPages: 278524 kB
Mapped: 63220 kB
Shmem: 740 kB
Slab: 124140 kB
SReclaimable: 98956 kB
SUnreclaim: 25184 kB
KernelStack: 3232 kB
PageTables: 3012 kB
NFS_Unstable: 0 kB
Bonce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 16605112 kB
Committed_AS: 408132 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 173540 kB
VmallocChunk: 34359557144 kB
HardwareCorrupted: 0 kB
AnonHugePages: 231424 kB
CmaTotal: 0 kB
CmaFree: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
DirectMap4k: 106432 kB
DirectMap2M: 4087808 kB
DirectMap1G: 14680064 kB
total used free shared buffers cached
Mem: 16433020 1718720 14714300 740 197912 1020632
-/+ buffers/cache: 500176 15932844
Swap: 8388604 0 8388604
From the results, the memtotal, Memfree, buffers, and cached in the/proc/meminfo correspond to the "Mem" line one by one, which is capable of outputting the results respectively.
noun explanation
Here are some key words to explain:
1. Memtotal: Total Memory
The system from power-up to boot completion, BIOS and so on to retain some memory, the kernel to retain some memory, and finally the rest of the system to control the memory is memtotal. This value is generally fixed during system operation.
2. Memfree: Number of free memory
Represents memory that is not yet in use by the system. Memused=memtotal-memfree is the memory that has been used.
3, Memavailable: The number of available memory
The number of available memory for the application. Some of the memory in the system is used but can be recycled, such as cache/buffer, Slab have a part can be recycled, so memfree can not represent all available memory, this part of the recoverable memory plus Memfree is the system available memory, namely: Memavailable≈memfree+buffers+cached, which is computed by the kernel using a specific algorithm, is an estimate. The key difference between it and Memfree is that Memfree is said to be the system level, memavailable is said to be the application level.
4. Buffer: Number of buffers in memory
5, Cache: Buffer Memory number
6, shared: Multiple processes shared memory space, not commonly used, temporarily not discussed.
The difference between buffer and cache:
Here, the difference between buffer and cache,
First, in the literal sense, buffer is the meaning of buffering, cache is the meaning of caching. As a practical example, it is called cushioning than a spring-like thing on a railroad head; a safe deposit box for emergency supplies deployed in the forest, called Food Cache, is similar to a storage box.
Second, the common argument, called Write-buffer and read-cache,buffer generally used as a write operation, the cache is generally used in reading operations, but also not static;
For example , to write 100 times per second hard disk, The impact on the system is huge, wasting a lot of time busy processing start writing and ending writing these two things. Using buffer to temporarily save the hard drive every 10 seconds, the impact on the system is very small, the writing efficiency is high; the cache is the middle tier introduced to compensate for the gap between high-speed equipment and low-speed devices, and ultimately accelerates the speed of the process.
For example, you have a very complex calculation done, the next time you have to use the results, the results will be a good place to hold, the next time no more forget, speed up the speed of data access. (You can refer to the answer above:
https://www.zhihu.com/question/26190832)
Calculation formula:
Referring to the output of free, here are a few calculation formulas:
root@prometheus-02:~# free
total used free shared buffers cached
Mem: 16433020 1827360 14605660 740 203540 1051400
-/+ buffers/cache: 572420 15860600
Swap: 8388604 0 8388604
To illustrate, put line 2nd, Mem line I call this OS Mem, the third line Buffers/cache line, called App Buffer/cache:
OS mem total = OS mem used + OS mem free
APP Buffers/cache used = OS mem Used-os mem Buffers-os Mem Cached
APP Buffers/cache free = OS mem free + OS mem buffers + OS mem Cached
App Buffers/cache total = app Buffers/cache used + apps buffers/cache free = OS Mem Total
This article is from the "XUJPXM" blog, make sure to keep this source http://xujpxm.blog.51cto.com/8614409/1961072
The difference between Linux Memfree and memavailable