Linux – real memory usage

linuxmemory

if I understand correctly, in the following output produced by free, 3535m is the actual free memory available to applications, only 413m is used, is this correct? need some clarification on the difference between Mem and -/+ buffers/cache row.

free -m
             total       used       free     shared    buffers     cached
Mem:          3949       3854         95          0          9       3431
-/+ buffers/cache:        413       3535
Swap:         2047       1322        725

Best Answer

The Mem: total figure is the total amount of RAM that can be used by applications. This is the total RAM installed on the system, minus:

  • memory reserved by hardware devices (often video memory if the graphics card doesn't have its own RAM);
  • memory used by the kernel itself.

That total includes:

  • free: memory that is currently used for any purpose;
  • shared: a concept that no longer exists. It's left in the output for backward compatibility (there are scripts that parse the output from free). (On current systems you'll typically see nonzero values because shared has been repurposed to show memory that's explicitly shared via a shared memory mechanism. On older systems, it included files mapped by more than one process and shareable memory that remained shared after fork().)
  • buffers: memory that is backed by files, and that can be written out to disk if needed;
  • cache: memory that is backed by files, and that can be reclaimed at any time (the difference with buffers is that buffers must be saved to disk before they're reused, whereas cache consists of things that can be reloaded from disk);
  • used -buffers/cache: memory used by applications (and not paged out to swap).

In a pinch, the system could run without buffers and cache, reserving RAM for applications and systematically performing disk reads and writes without any caching. The -/+ buffers/cache figures indicate the amount of RAM used directly by applications (used column) and the amount of RAM not used by applications (free column).

Although this can vary a lot, a healthy system typically has around half its RAM devoted to applications and half devoted to buffers and cache. Unless you're running a dedicated file server, your system has more RAM than it needs for what you're currently doing. If the free - buffers/cache figure was low, that would indicate a system that doesn't have enough RAM (contrary to a widespread belief, having a lot of memory devoted to buffers and cache is important for system performance, and trying to reserve more memory for applications would make 99.99% of systems slower).

The swap line is straightforward, it shows the amount of swap that's in use (either by applications or for tmpfs storage), and the amount that isn't.

Related Question