views:

300

answers:

5

Hi there

if I run

top

on a Linux system, I can see a lot of information about memory usage.

Mem:  15736360k total,  8415332k used,  7321028k free,   174876k buffers
Swap:        0k total,        0k used,        0k free,  2630508k cached

I was wondering: What is the "cached" attribute telling me? Seems like this is not being freed at all - is this normal behavior?

We're running memcached for our web apps. Has this anything to do with it?

Matt

+3  A: 

I believe that "Cached" is the memory being used for the block device (i.e. disk) cache - if needed, this memory can be immediately converted to free memory so that apps can use it. So in summary, think of it as "free" :)

Paul Betts
+7  A: 

You can (and maybe should) also use the free command to print memory status:

             total       used       free     shared    buffers     cached
Mem:        515568     504740      10828          0      44248     427800
-/+ buffers/cache:      32692     482876
Swap:       915664      64820     850844

The "buffers/cache" line tells you how much RAM the kernel has currently used for various buffers and caches, mainly for disk I/O I think. This memory is available to programs if they need it, but until they do, it's better utilized if the kernel uses it to buffer I/O than if just left to idle.

unwind
+1  A: 

If my memory serves me correctly, the Linux kernel will holds on to this memory for other purposes until an application needs it. This is completely normal. The following is a brief explanation: http://www.novell.com/coolsolutions/feature/18990.html

Jordan S. Jones
+2  A: 

There is a wonderful answer to your question here. In short the linux swap system can have the same pages in memory and on disk. This can happen when a page is brought in from swap and not changed - when that happens the system prefers not to erase the page from disk because it may need to rewrite it unnecessarily. A data structure is needed to keep track of the state of the swap, and caching and which pages are swapped out which are not etc. The details are in the link, but the swap cache is the data structure that handles this bookkeeping, and it's size depends on how big your page table is.

Aftermathew
+2  A: 

Just letting you know good stuff:

ServerFault launches - it's StackOverflow for sysadmins

Janis Veinbergs