Sometimes we need to know exactly how our Linux system is using memory. In this article we will look at how to use the free
command line program to see how memory is being used on a Linux system. We will clearly define the difference between free free memory and free memory on a Linux system.
Understanding free memory and available memory
What is free memory and how is it different from available memory?
Free memory is the current amount of memory that is not being used for anything. For this reason, especially on servers, I like to think of free memory as wasted memory. Once your application has started and gone through a significant amount of uptime, this number is almost always small.
Free memory is the amount of memory available for allocation to new processes or existing processes. Free memory is an estimate of the amount of memory that can be used without swap swap space.
The difference between free memory and available memory in Linux is that, free memory is not in use and has nothing to do. While free memory is used memory, including but not limited to caches and buffers, it is possible to free them without the performance loss of using swap space swap.
Compare free memory with available memory
With this in mind, let’s look at two Linux servers with 60GB of RAM. Server A and Server B . We will use the free
command.
To see free memory versus free memory in Linux, log in to your server and enter the following command.
|
|
The result should look similar to these two screenshots below. I also ran the uptime
command to confirm that both systems have been online for a while.
Server A: Less than 1% free memory (wasted memory), 13GB free memory.
Server B: still wasting 30GB of memory (free) after 153 days of uptime.
The above is the difference between free memory and free memory in Linux. When you compare the two systems, even though the load averages are similar (handling the same workload), it is clear that one server is using almost 100% of its memory (Server A), while the other server is wasting more than 50% of its memory (Server B). Note that both servers have 12 CPU cores and can swap to RAID 10 NVMe storage.
Note that even with available memory, the Linux kernel moves the least used memory pages into the swap space.
Conclusion
Do not jump to conclusions by looking at “free” memory on your Linux system, as you should also consider available memory, buffers/caches, and other factors as outlined.