52

When running top, I get:

top - 09:10:52 up 18:37,  1 user,  load average: 1.56, 1.33, 1.15
Tasks:  39 total,   1 running,  38 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.1%us,  0.6%sy,  1.0%ni, 92.5%id,  5.8%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   4194304k total,  3045460k used,  1148844k free,        0k buffers
Swap:        0k total,        0k used,        0k free,  2256128k cached

See the part: 2256128k cached? What exactly does that mean?

I am comparing two VPS from two provider, this one always has a large amount there (70% of the used memory) and the other VPS provider always shows 0.

2 Answers 2

128

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 :)

4
  • 6
    Love the answer, but due to lack in reputation I can't upgrade it (yet). Sorry.
    – KKK
    Oct 10, 2012 at 14:18
  • 4
    Don't worry, I'm just glad to be of help. Hope the information is useful!
    – roadmr
    Oct 10, 2012 at 15:19
  • THIS should be the accepted answer. Oh, well . . . :(
    – ankush981
    Jan 30, 2018 at 16:52
  • definitely should be the accepted answer. linuxatemyram is great info! Jan 30, 2018 at 16:59
19

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.

4
  • and I can influence this anyhow, e.g. limit it or disable completely?
    – KKK
    Oct 10, 2012 at 13:51
  • 2
    Why do you want to do that?! what shall you do with?! its about how file system cache in phyiscal memory.
    – user61928
    Oct 10, 2012 at 13:56
  • Cause most of the filesystem is a DB, the DB has its own cache, so I assume it would be good to limit this part somehow.
    – KKK
    Oct 10, 2012 at 13:59
  • You can do it with some search but i don't advice you. This will limit the performance of th FS
    – user61928
    Oct 10, 2012 at 14:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .