I absolutely HATE *nix memory metrics

Today was yet another day at the office and large scale PANIC erupted. Managers running around as if the end of the world was just around the corner. All the fuzz came from the interpretation of free in our production system, the server had only 85 MB free memory left and the end was near! When taking a closer look it was obvious that the PANIC was unmotivated and that the server had 6.3 GB "free". 

Still every time it has been a few weeks since I looked at the metrics I have to go through the following mental process to sort it out:
"CRAP!!!  The end is near ... wait! ... calm down .. its linux ... its the second line that counts. ... so ... this .. is .. good?! .... sigh of relief

Thus I think that its in its place to repeat the memory metrics, what they mean and how to interpret them in yet another blog entry.




free -m
             total       used       free     shared    buffers     cached
Mem:          5963       5581        381          0        420       3235
-/+ buffers/cache:       1926       4037
Swap:         2047          0       2047


All the numbers are reported in MB.

Looking at the above with free 381 MB still makes me shiver.
But there is no need to PANIC. The free above shows that its 381 MB free-free and 4037 MB sort of free.

In a more detailed breakdown the three rows Mem, -/+ buffers/cache and Swap can be explained as follows:
  • Mem this row is the only one using all of the headers total, used, free, shared, buffers and cached. The total tells us that we have a system with 5963 MB total (about ~6G) of physical RAM. The used column tells us that 5581 MB (about ~5.6 GB) is currently in use. (this is the point where i usually freak out for a moment :-) ). But as briefly explained it can be OK.  The free tells us that 381 MB actually is free. The shared column lists the amount of physical memory shared between multiple processes. Here, we see that 0 MB of pages are being shared and in my experience this value is usually 0. Then the, in my eyes most interesting column, is buffers, it shows the amount of memory being used by the kernel buffer cache. The buffer cache is used to greatly speed up disk operations, by allowing disk reads and writes to be serviced directly from memory. The buffer cache size will increase or decrease as memory usage on the system changes; this memory is reclaimed if it is needed by applications thus it can be viewed as free, sort of. Last we have the cached column indicates how many memory pages the kernel has cached for faster access later.
The BIG take away so far, and in total is that memory used for buffers and cache can easily be reclaimed for use by applications and thus its free - sort of.
  • -/+ buffers/cache, provides an information about the amount of memory actually used by applications and the memory available. The used column 1926 MB  i.e. already consumed by applications and not free and the free column 4037 MB - available to applications if buffers and/or cache is reclaimed. If we sum the two up 1926(used)+4037(free) we get 5963 and that is the same number as we have for total!


Comments

Popular posts from this blog

Possible SYN flooding on port 3306 (MySQL)

Part 1 - Disaster Recovery with SRM and vSphere Replication

Part 2 - Disaster Recovery with SRM and vSphere Replication