How to reliably measure available memory in Linux? How to reliably measure available memory in Linux? linux linux

How to reliably measure available memory in Linux?


Since what “available memory” precisely means depends on your purpose, and your purpose is to avoid OOM situations:

Check out how Qt Extended (previously Qtopia) anticipates OOM situations.

There are two events:

  • (MemFree + Buffers + Cached) / MemTotal < treshold (in /proc/meminfo)
  • Major pagefaults > treshold (pgmajfault in /proc/vmstat I think)

The first is an early warning that memory is low, and triggers more frequent monitoring of pagefaults. The second signals trashing, which kills system performance and is a good hint the OOM killer will run.


At first I found your question easy, as in practice output from free in the columns '+ buffers/cache' is the one I use and it normally works.

But one of the situations in which it does not work is when you have heavy read to the same blocks. E.g. reading the same 1 gb_file over and over:

while true; do cat 1gb_file >/dev/null; done

If your system has > 1 GB cache then this will run fast. But if you start using some of that cache for something else it will smash the performance of the system.

So when you evaluate your solutions try the above and see if the solution takes that into account.


From linux-3.14 there is new metric MemAvailable in /proc/meminfo.

And check line '-/+ buffers/cache:' in output of utility free.