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?

Adam Matan
  • 2,593
  • 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"). – user Mar 06 '12 at 12:21

2 Answers2

17

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.)

Mat
  • 52,586
  • 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 06 '12 at 12:53
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.

Majid Azimi
  • 3,098
FJRA
  • 111
  • 2