Dumping Linux Buffer Cache

TOP screenshot

A useful command to check linux system resources is "top".  However with the buffer cache you may see almost no available memory (see attached screenshot).  But how can that be?  All you have running may be a java app, apache, and a few other services.  There is no way that should be using ALL of that RAM.  In my case, I have the Nagios "check_mem" plugin querying for available memory and throwing alerts quite regularly.

The "free -mt" command can show you how much memory is cached.  That eases my mind a bit.  While googling about buffer cache, I stumbled upon this article:


This article gives a good rundown of what the buffer cache is all about.  Also it mentions a nice little trick to dump the entire cache.

echo 1 > /proc/sys/vm/drop_caches

VOILA!  Cache dumped and Nagios is happy.  Just dumping the cache shouldn't be taken lightly as it MAY have some adverse effects depending on your server.  However the cache should slowly start to build back up. 

Looking into the actual check_mem script, you can have it exclude the buffers in the calculation of free memory.  Check this line and make sure the value is "1":