How to determine the available memory for applications in linux


To determine the memory usage use the free command as follows. (-m gives the results in MB).

free -m

             total       used       free     shared    buffers     cached
Mem:         40219      36564       3655          0        420      30733
-/+ buffers/cache:       5411      34808
Swap:         2047       2047          0

The top row in this example shows that the total amount of available memory is 40219 MB, and that 36564MB of this memory is in use. However this used figure of 36564MB includes the memory used by applications and also memory used by buffers and cache.

The second row may be more useful as it shows 5411MB is currently in use by processes (applications) and 34808 MB is in use by buffers and cache. Importantly if space is needed by programs or applications, then Linux will free up the buffers and cache to yield memory for the applications, hence why 34808MB is in the free column.

Using available memory for buffers (file system metadata) and cache (pages with actual contents of files or block devices) helps the system to run faster because disk information is already in memory which saves I/O; RAM is wasted if it isn't used.

So if your system runs for a while you will usually see a small number under the field "free" on the first row, but it is the amount free in the second row that shows how much memory is available for applications should it be required.