One thing I’ve always have difficulty keeping straight is what the free command in Linux tells you about buffers and cache memory. Is that buffers and cache used and free (making you do the math of how much real free memory you have) or does the free command do the math for you? In tuning a Nagios setup, I researched it to make sure I had it right.

Misunderstandings about how Linux uses RAM are common and those misconceptions can lead to quite a few false positives in monitoring machines for memory pressure conditions. Linux doesn’t eat RAM, although it will try to use as much RAM as possible to cache block devices which makes your machine much faster.

Remember, free does the math for you. Its goal is to inform you about free memory, not make you do math. :

\$ free -m
total       used       free     shared    buffers     cached
Mem:        257948     256570       1377          0       3336     238963
-/+ buffers/cache:      14270     243677
Swap:       262127          1     262126


The -/+ buffers/cache line’s two values are:

1. Buffer/cache memory used subtracted from total used memory.
2. Buffer/cache memory used added to total free memory.

So, in the above example, the value 243677 is the value you want to monitor with Nagios / Graphite and what us humans would like to see as the free memory metric.

More precisely the two values above are calculated like so:

1. Total Used Memory - Buffers - Cached
2. Total RAM - Value obtained in #1

See /proc/meminfo for the gory details.