5

I use free to get the amount of free space on some of my servers. Its output is something like:

$ free -m
             total       used       free     shared    buffers     cached
Mem:           374        366          8          0         58         98
-/+ buffers/cache:        209        165
Swap:         1906        120       1785

How much free space do I really have?

  • 1
    free tells you about memory usage, not storage. df tells you about storage (which is what I, at least, read into "free space on a server"). – a CVn Mar 6 '12 at 12:21
15

The first line of the free output lists:

  • total Your total, physical (assuming no virtualization) memory
  • used How much of that is currently used (by anything)
  • free How much of that is completely free (not used at all)
  • shared Memory used (mostly) by tmpfs (for Linux, kernel >= 2.6.32)
  • buffers Memory used by kernel buffers
  • cached Memory used for cache

The last two items, cache and buffers, is memory that is not allocated to specific user processes. It is memory reserved by the kernel to improve performance overall, but is not "application" memory. These areas will grow or shrink depending on kernel policies with respect to caching, memory pressure, application I/O patterns, etc.

Since these two columns are not user-allocated memory, and the zones can shrink (practically to zero) if user allocations require it, they are in a sense "free" - there's RAM there that can be freed up by the kernel if your apps actively need it.

That's what the second line tells you. It removes the buffer and cache memory from the used column (that's what the - means), and adds (+) them to the free column. (Rounding issue will happen.)

(The last line shows the state of your swap space.)

  • And having no free memory is a good thing (this for people coming from the Windows world). Memory is a very expensive, limited resource. Linux uses all of it. If your applications don't, the kenrel will use it to improve performance (this is covered by @Mat's answer above). – Alexios Mar 6 '12 at 12:53
  • "Never anything there; ignore that column." Maybe for some people, but not for everyone! shared lists memory used by tmpfs mounts, such as when /tmp is treated as a ramdisk. – frabjous Feb 6 '18 at 20:44
1

Without swap your real free space is 165. With cache you have 8MB free space. Without cache you have 165MB free. -/+ line is without cache. first line is with cache.

  • What's the meaning of the -/+? – Adam Matan Mar 6 '12 at 6:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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