Checking Memory usage using free command

Linux uses it's memory in a very efficient way . Here I am not going to write on memory management in Linux , but would try to understand how to view the memory usage in a Linux box. Linux will always try to use free RAM for caching stuff, so "free" will report almost always very low free memory . We have the free command as a reporting tool for memory usage . Let us now look at the output of free command .

-bash-3.00$ free -m
                     total        used        free     shared     buffers     cached
Mem:           2007       1902        105          0          150           761
-/+ buffers/cache:        990       1016
Swap:         1963          0       1963


Initially was having the understanding that the free column in the above output gives me the free memory in my box and my box is really low in memory. But this is not exactly the case. We will see how .

Interpreting output of free Command:

Let's now understand the headers from the output of the above command.

Total: The total amount of RAM on the system minus the amount has been used in loading the kernel.
Used: The amount of memory used by applications in the system . This does not mean that all these
           memory are used by the current running applications in the system but this also includes
           memory reserved for caching and buffering purpose.
Free : The amount of free memory in the system .
Shared : This is the  shared memory . An indication of how much memory is common to more than
              one process.
Buffers: This entry indicates how much of the memory in use is currently being used for disk
              buffering. File system metadata and other block reads are cached in the buffer cache.
Cached: This entry indicates how much of the memory in use is currently being used for caching
              purpose. Applications which are not running but was running few minutes back is cached in
              memory with the idea that it will make the application running faster when it runs again. This
              memory can be reclaimed .
-/+ buffers/cache: This shows the cached data and buffers for IO.  The free section actually gives us
                             how much memory is available for use on the system. Caches will be freed
                             automatically if memory gets scarce, so they do not really matter.


Now let us see how we can calculate these values provided by the free command for the above output .

Buffers + Cache  =  150 + 761 =  911

Used - Buffers - Cache = 1902 - 911 = 991 

The lower value gives us the actual amount of memory used by the applications . This value is equal to the first row in the second column.  Rest of the used memory will be released by the OS if memory becomes scarce.

Buffers + Cache + free =  911 + 105 = 1016

The above value is the actual amount of memory that can be allocated to the  applications by the OS depending on usage. This value is equal to the free column in the second row . We should began to worry when this value is low. The OS will start paging after that and hence system performance will be impacted because disk is many times slow than memory.
 

Comments