In Linux, what is the difference between “buffers” and “cache” reported by the free command?

The “cached” total will also include some other memory allocations, such as any tmpfs filesytems. To see this in effect try:

mkdir t
mount -t tmpfs none t
dd if=/dev/zero of=t/zero.file bs=10240 count=10240
sync; echo 3 > /proc/sys/vm/drop_caches; free -m
umount t
sync; echo 3 > /proc/sys/vm/drop_caches; free -m

and you will see the “cache” value drop by the 100Mb that you copied to the ram-based filesystem (assuming there was enough free RAM, you might find some of it ended up in swap if the machine is already over-committed in terms of memory use). The “sync; echo 3 > /proc/sys/vm/drop_caches” before each call to free should write anything pending in all write buffers (the sync) and clear all cached/buffered disk blocks from memory so free will only be reading other allocations in the “cached” value.

The RAM used by virtual machines (such as those running under VMWare) may also be counted in free’s “cached” value, as will RAM used by currently open memory-mapped files (this will vary depending on the hypervisor/version you are using and possibly between kernel versions too).

So it isn’t as simple as “buffers counts pending file/network writes and cached counts recently read/written blocks held in RAM to save future physical reads”, though for most purposes this simpler description will do.

Leave a Comment