How to determine Linux Memory Usage?

Free memory on Linux is a very different world to the one that most people would be used to. For years windows users have installed odd bits of memory management software in a desperate bid to see the biggest green segment of the memory pie chart. Well, it can be argued that any good operating system SHOULD make full use of the installed memory. Why continually unload and de-allocate memory when you are probably just going to have to load it up again shortly after?

The Linux kernel uses something known as lazy de-allocation – which means that although the memory pages may not be used, they are left un-wiped from memory in case they are needed again. Think about common linked libraries and such. Linux only keeps a few pages of memory actually free, so that it has the ability to load stuff quickly, and THEN think about de-allocating memory to make more space if it has to.This is why Linux is so efficient, and is used throughout the world in systems with limited memory capacity. That’s not to say Linux isn’t powerful – give it a big memory pool and a few dozen cpu cores and it will tear through computing tasks as fast if not faster than any commercial operating system (mentioning no names)…

the 'top' command can be misleading

the 'top' command can be misleading

Anyway, on with the show. Most people use the “top” command, and look at this part of the screen and panic, thinking they are low on memory. The above example would leave you thinking that your 2Gb server only has about 105Mb free. Well, strictly speaking, this is true. Linux is “making use” of all but 105Mb of memory. That’s not the same as saying all of that memory is being used by processes and is busy, it’s just saying that it has something useful in it.

A much better view of how much free memory your server has is to run the “free” command… or

free -m
the 'free' command gives us a much happier picture

the 'free' command gives us a much happier picture

This will show the results in Megabytes. Now the important bit to look for here is the -/+ buffers/cache line. This is telling us (in the above case) that Linux us actually using (buffering) 380Mb, and the free (cache) is actually more like 1646Mb – Plenty of space!

When things really start to get busy then you will see the Swap being used, but you really don’t want to get into this area if you can help it as disk access, as we all know, is much slower than RAM.

Anyway, I hope that’s helped explain a tiny bit about Linux memory usage and Linux free memory.


One Response to “How to determine Linux Memory Usage?”