Trying to determine how much memory is free on a Linux machine is not as straight forward as it is on Windows. While Windows attempts to keep as much memory free as possible, Linux trys to keep as much memory used as possible. Here is how to determine how much memory is actually free and in use on your Linux machine.
Free memory is how much memory is unused. But this is only part of the memory that is available to applications. Here is a simple explanation of the Linux memory model. Linux has free memory and when an application asks for memory Linux pulls from there. When an application gives up its memory, that memory is NOT returned to the “free” pool. Linux holds it in case the app needs it again. When the free memory gets really low, THEN Linux goes to the used, but unallocated memory and reclaims that.
Now let us define a few terms
free = Memory that is not allocated used = Memory in use and previously used buffers = Memory associated with block devices and can be reclaimed cached = Memory associated with files and can be reclaimed
In order to see how much memory is available you need to look at the whole picture. Here is an example of memory usage using the free
command:
total used free shared buffers cached Mem: 24673380 24446828 226552 0 574568 19046408 -/+ buffers/cache: 4825852 19847528 Swap: 2104504 0 2104504
This machine only has 226552 (.9%) free. Though this might look like the machine is running out of memory, actually there is 19847528 (80.4%) available. To determine how much memory is available for use and how much is currently being used, you can use the following formulas:
Available Memory = free + buffers + cached = 226552 + 574568 + 19046408 = 19847528 Unavailable Memory = used - (buffers + cached) = 24446828 - (574568 + 19046408) = 4825852
You can see that free
already does these calculations for you on the second line. You can also see that the SWAP use is 0, meaning that we have not run out of RAM and needed to hit the SWAP file.
Reference:
Linux System Administrator’s Guide – 6.6 The buffer cache
Overview of memory management
One Response to “Linux Free Memory”
Leave a Reply
You must be logged in to post a comment.
September 1st, 2014 at 14:30
[…] Linux Free Memory […]