Linux: How Much Memory is Really Free?

By Xah Lee. Date:

If you want to know quickly just how much memory is really free, type free -m. Sample output:

◆ free -m

             total       used       free     shared    buffers     cached
Mem:          5798       2068       3730          0        157       1053
-/+ buffers/cache:        857       4941
Swap:         5885          0       5885

the 4941 is memory free for applications, in mega bytes.

Alternatively, you can see the same figure if you call “htop”. 〔➤see Linux: Monitor Processes, “htop” Tutorial

Understanding Memory from 「top」 and 「free」

First, know that the outputs from top and free are basically the same.

Here's output from top:

Mem:   5937800k total,  2174256k used,  3763544k free,   163796k buffers
Swap:  6027260k total,        0k used,  6027260k free,  1131896k cached

Here's output from free:

             total       used       free     shared    buffers     cached
Mem:       5937800    2173968    3763832          0     163792    1131508
-/+ buffers/cache:     878668    5059132
Swap:      6027260          0    6027260

So, we can now just focus on studying the output from free.

First, understand this:

① Linux uses perm storage device (For example, hard-disk ) as virtual memory. The virtual memory on hard-disk is called swap space. Virtual memory means the perm storage is used as temp space for RAM. So, when your RAM is full, the OS can off-load parts of it currently not used data to disk, therefore free up memory for application that needs it.

② Also, Linux uses RAM as cache for file data (from hard-disk). (Because RAM's IO speed is a thousand times faster than hard disk, so OS will load disk data to RAM as cache)

Now, let's look at the output of free -m (“-m” means mega bytes).

             total       used       free     shared    buffers     cached
Mem:          5798       2145       3653          0        160       1121
-/+ buffers/cache:        862       4935
Swap:         5885          0       5885

in the first row Mem, the total 5798 is the total RAM.

used + free = total. Check: 2145 + 3653 = 5798.

“used” includes used for disk cache purposes.

“cached” is amount of disk data sitting in RAM for fast access.

So, real free should be “free + buffers + cached”, and in this example it is 3653 + 160 + 1121 = 4934.

and actually used should be “used - buffers - cached” (2145 - 160 - 1121 = 864).

And if we add 4934 and 864 we get the “total”.

The free command pretty much did this calculation for us, in the line:

                         used       free
-/+ buffers/cache:        862       4935