What is "cached" in the top command?

the Linux kernel will use available memory for disk caching, unless it's required by a running program.

This is considered good; say you have 4 GB RAM, and your programs are using only 1 GB. The other 3 GB are going to waste. Despite the "feel-good" impression from knowing you're only using 25% of your memory, the counterpart is that the other 75% is going unused. So the kernel uses that for caching files which significantly improves performance. It's automatic; unlike older operating systems you don't need to decide how much to devote to disk cache, or manually configure it.

"The Linux disk cache is very unobtrusive. It uses spare memory to greatly increase disk access speeds, and without taking any memory away from applications. A fully used store of ram on Linux is efficient hardware use, not a warning sign."

This is such a common question that there's an entire website devoted to it:

http://www.linuxatemyram.com

The website even has a way to empty the disk cache so you can then run some applications and see how much faster they are with the cache enabled :)


That number before cached is the amount of physical memory that is being used by cache buffers for your filesystems.

It's not actually related to SWAP, despite being on the "Swap:" line.

To verify my answer with a little experiment try the following:

Run top and note the value of 'cached'. Now run

dd if=/dev/zero of=~/trick bs=1M count=128

if you run top again you'll notice that 'cached' has grown by 128M

Now remove the file

rm ~/trick

Run top again and you'll see 'cached' has dropped by 128M

So for Mem:

total = used + free and

used = <all apps> + buffers + cached

(where buffers is basically metadata for the cached). A bit confusing of a UI.

Tags:

Memory

Top