Why does my server show

            total      used      free   shared buffers    cached
    Mem: 12286456  11715372    571084        0   81912   6545228
-/+ buffers/cache:  5088232   7198224
   Swap: 24571408     54528  24516880

I have no idea on calculating the memory in linux. I think it says that 5088232 is used where as 7198224 is free, meaning it is actually consuming 5GB of RAM?

up vote 215 down vote accepted

Meaning of the values

The first line means:

  • total: Your total (physical) RAM (excluding a small bit that the kernel permanently reserves for itself at startup); that's why it shows ca. 11.7 GiB , and not 12 GiB, which you probably have.
  • used: memory in use by the OS.
  • free: memory not in use.

total = used + free

  • shared / buffers / cached: This shows memory usage for specific purposes, these values are included in the value for used.

The second line gives first line values adjusted. It gives the original value for used minus the sum buffers+cached and the original value for free plus the sum buffers+cached, hence its title. These new values are often more meaningful than those of first line.

The last line (Swap:) gives information about swap space usage (i.e. memory contents that have been temporarily moved to disk).

Background

To actually understand what the numbers mean, you need a bit of background about the virtual memory (VM) subsystem in Linux. Just a short version: Linux (like most modern OS) will always try to use free RAM for caching stuff, so Mem: free will almost always be very low. Therefore the line -/+ buffers/cache: is shown, because it shows how much memory is free when ignoring caches; caches will be freed automatically if memory gets scarce, so they do not really matter.

A Linux system is really low on memory if the free value in -/+ buffers/cache: line gets low.

For more details about the meaning of the numbers, see e.g. the questions:

Changes in procps 3.3.10

Note that the output of free was changed in procps 3.3.10 (released in 2014). The columns reported are now "total", "used", "free", "shared", "buff/cache", "available", and the meanings of some of the values changed, mainly to better account for the Linux kernel's slab cache.

See Debian Bug report #565518 for the motivation, and What do the changes in free output from 14.04 to 16.04 mean? for more details information.

  • Could you expand on what kinds of things Linux may be caching? Would it be files that have been accessed or network stuff? – CMCDragonkai Aug 2 '15 at 13:08
  • @CMCDragonkai: The answer to serverfault.com/questions/23433/… addresses in detail what constitues "cache" and "buffer". – sleske Aug 2 '15 at 16:03
  • 4
    I do not think the statement "total = used + free" is correct, see the following output on my machine: $ free -h total used free shared buff/cache available Mem: 3.4G 585M 152M 11M 2.6G 2.5G Swap: 4.0G 84M 3.9G – Sebastian Feb 13 '17 at 9:35
  • @Sebastian: Ah, interesting. It seems the ouput of free was changed (in 3.3.10). I edited my answer to mention this. If you are interested in this change, consider asking a new question :-). – sleske Feb 13 '17 at 10:17
  • 1
    total = used + free + buff/cache – danger89 Oct 26 at 17:41

For anyone needing an even more simple, step-by-step explanation, check http://thoughtsbyclayg.blogspot.com/2008/09/display-free-memory-on-linux-ubuntu.html, his explanation helped me a lot.

The buffers/cache line shows you how much memory is used by programs (first of those columns), and is free for programs to use (second column). It's a fairly esoteric number, and not something you'd really look at much in practice.

  • And what does the first line (mem line) means – Muahmmad Zeeshan Nov 17 '09 at 11:14
  • 8
    That you've got 12GB of RAM installed in the system, 11.5GB of which is used and 0.5GB or so is currently unused. Approximately 82MB of the used memory is used for buffers (network connections, etc), whilst about 6.5GB is being used to store copies of data on disk, so that data won't have to be re-read if it's needed again. – womble Nov 17 '09 at 11:33
  • 3
    @Muhammad: "82MB is free." - no, 57MiB is free (but that doesn't really matter, see my answer). "Now it all means that the system has reached its limits" - No, not at all. The system has 6.9GiB in use for caching, which it will readily give to applications, so there's lots of room. Also, swap usage is very low (ony ca. 50MiB). If memory starts getting tight, swap usage will rise. At present you're barely using half the RAM you have. – sleske Nov 17 '09 at 11:50
  • 4
    Have you considered asking a new question at some point? – womble Nov 17 '09 at 13:27
  • 2
    I disagree, the buffers/cache line is the actual free memory of the system and therefore most relevant if you want to know if the system has room for programs. – eckes Jul 4 '15 at 15:27

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.