There is a saying in Linux community: “Free memory is wasted memory.” This statement seems to confuse newbies, resulting in the Linux ate all my RAM myth. Reality is that the kernel borrows unused chunk of memory for disk caching (alias “Buffers”) and file caching (alias “Cached”). This behavior improve significantly the overall performances.
Whenever an application needs more memory, borrowed chunks are “returned”. The website linuxatemyram.com explain this mechanism in more detail.
Confusion arise because people don’t read the right line when using the free
command:
$ free -m
total used free shared buffers cached
Mem: 5863 5541 321 569 107 1203
-/+ buffers/cache: 4231 1632
Swap: 7323 3435 3888
You think this host only have 321MB of ‘free’ memory ? Wrong !
This host have 321MB of non-used memory, that true. But the total amount of memory that the kernel can “reclaim” (and therefore give for applications) is much higher.
The right answer is 1632MB.
In your scripts if you want to get the amount of ‘free’ memory, use the following one liner:
free -m | sed -n -e '3p' | grep -Po "\d+$"