Ubuntu – How to get a good overview of RAM usage

freehtopram

I have installed Ubuntu 14.10 on a server. The server main task is running a MongoDB installation along with several NodeJS applications. The NodeJS applications will run continuously and will accept requests from outside.

Every now and then large requests will come in causing some NodeJS application to use a lot of RAM for a short amount of time. I have been trying to monitor this but am not sure what to make of my findings.

So far I have used two commands to get insights in the RAM usage. These are

free -m

and

sudo htop

The first shows this:

                        total       used       free     shared    buffers     cached                                           
Mem:                     3442       3158       283          6        111       1203                                           
-/+ buffers/cache:                  1842       1599                                                                         
Swap:                    0          0          0    

When I look at this I would say that about 280MB of RAM is free. Which does not seem like a lot.

htop tells me the following:

  1  [|||                                         0.8%]     Tasks: 61, 129 thr; 2 running
  2  [|||                                         1.0%]     Load average: 1.16 1.15 0.93
  Mem[|||||||||||||||||||||||||||||||||||||1979/3442MB]     Uptime: 29 days, 00:23:31
  Swp[                                           0/0MB]   

I don't really now how to read this. Can anyone help me out here?

I guess my question in the end boils down to these:

  • How can I get some insight in how much RAM is available?
  • When is the RAM memory too little? Is 300MB considered very little? Dangerously so?

Best Answer

TL;DR: You don't have to worry as long as the -/+ buffers/cache row shows enough free memory. If it shows low free memory and you are continuously being swapped to disk then you need to be concerned.

Explanation:

You are good with your current RAM usage scenario. Lets take the output of free -m to break it down:

All columns of free -m is self explanatory. The important thing to note that you don't need to be alarmed when the memory usage is high without seeing the amount of memory cached and buffered.

From the output, you have used 3158 MB of your 3442 MB RAM, a plain subtraction would say that you have only 283 MB free to be allocated to new programs. This is not right, you need to look at the cached and buffers columns too, cached will show the a mount of disk data cached by RAM for faster access to the commonly used files and buffered shows the amount of data to be written to the disk.

As you know, disk access is much slower that RAM, so to improve performance its a good thing to store some of disks data into RAM. You have 1203 MB of cached and 111 MB of buffered data. This is a good thing that your memory is caching this amount without just keeping this amount of RAM idle. It will improve your performance greatly.

To get the actual amount of RAM that is being used without caching/buffering, look at the -/+ buffers/cache: row. This result is shown subtracting the cached/buffered amount. As you can see you have 1599 MB free, so everything seems Ok at this state. If you see the values in this row is low, then you need to be concerned and take a look at the RAM usage.

Also note that, when a new program is to be started and there is not sufficient memory after caching, the older caches will be cleared automatically to make space for the new program. So, as long as the actual memory usage is not high and your are continuously being swapped to disk, it's a good thing to have substantial amount at cache as it is "using" your memory efficiently.

Related Question