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.
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
if you run top again you'll notice that 'cached' has grown by 128M
Now remove the file
Run top again and you'll see 'cached' has dropped by 128M
So for Mem:
total = used + free
andused = <all apps> + buffers + cached
(where buffers is basically metadata for the cached). A bit confusing of a UI.