Free vs. Available Memory in Linux

At times we will need to know precisely how our Linux systems use memory. This article will examine how to use the free command-line utility to view memory usage on a Linux system. In doing so, we will clearly define the difference between free vs. available memory on Linux systems.

 

Free vs. Available memory explained.

Ok, let’s get right to it then. What exactly is free memory and how is it different from available memory?

Free memory is the amount of memory that is currently not used for anything. For this reason, especially on servers, I like to consider free memory as wasted memory. Once your applications/processes have launched and considerable uptime has passed, this number should almost always be small.

Available memory is the amount of memory that is available for allocation to new or existing processes. Available memory is then an estimation of how much memory is available for use without swapping.

The difference between free memory vs. available memory in Linux is, that free memory is not in use and sits there doing nothing. While available memory is used memory that includes but is not limited to caches and buffers, that can be freed without the performance penalty of using swap space.

 

Free vs. Available memory compared.

With this in mind, let’s look at two 60GB memory Linux servers. Server A and Server B. We are going to use the go-to command: free

To view free vs. available memory in Linux, login to your server and enter the following command:

free -h

The result should look something like these two screenshots below. I also ran the uptime command to confirm that both systems have been online for some time.

Free vs. Available Memory Server A
Server A: Has less than 1% free (wasted memory), 13GB available memory.

Free vs. Available Memory Server B
Server B: After 153 days of uptime, 30GB of memory is still wasted (free). 

Above lies the difference between free vs. available memory in Linux. When you compare both systems, even though the load averages are similar (processing the same workloads), it is evident that one server is making use of almost 100% of its memory (Server A) while the other server is wasting more than 50% of its memory (Server B). Note, that both of these servers have 12 CPU cores and swap to RAID 10 NVMe storage – thanks to StackLinux.com.

Please note that the Linux Kernel will move memory pages least frequently used into swap space even if there is available memory.

When analyzing these systems, a sysadmin may ask a few pertinent questions: Is swapping slowing the performance of Server A? Or, is it opportunistic swapping? Should we downgrade memory on server B? Or, is traffic/workload growth expected soon? Should Server A be upgraded with more memory? Or, during peak hours/swap, does “load average” stay well below 12.00? Can Server B be configured to use more buffers and cache? Would such a change improve performance (is it worth changing)?

These are the questions that resulted in the current state of those above servers. Each admin will have to answer those questions and others, case by case, or hire an expert to do so.

 

Conclusion

Free vs. Available Memory Linux

Don’t be caught looking at “free” memory on your Linux system and jumping to conclusions because you should also consider available memory, buffers/caches and other factors as outlined.

I’ve written some other articles on this topic that you may find helpful:

In addition to the free command, you can also use the following commands to check your Linux system’s memory usage:

  • top – shows an overall system view.
  • htop – interactive process viewer and manager.
  • atop – For Linux server performance analysis.
  • Glances and nmon – htop and top Alternatives.
  • vmstat – shows system memory, processes, interrupts, paging, block I/O, and CPU info.
  • cat /proc/meminfo and others.

Thanks for reading. I am looking forward to hearing from you!

 

Published: September 7th, 2021 | Last updated: July 27th, 2022

Tags: , , , , ,

Comments

  1. For most monitoring tools, the free memory is what is being used without considering cache/buffers. For example a server configured with 64GB and having free memory to be 5GB and available to be 30GB will be flagged as being under memory pressure. How do you think this gap can be resolved ?

  2. Having 5GB not in use and a healthy 30GB of cache and buffers can be further improved by tweaking the kernels cache pressure.

    I’m on mobile this morning, but if I didn’t include how to tweak cache pressure to hold more data rather than swap or be removed I will edit this reply with a link to another article which details how to do so.

    Oh and welcome to the community!

    Edit: To make full use of memory on a system with more than adequate RAM installed. See the this article:

    Quote:

    Consider adjusting your server’s cache pressure and tendency to swap (vm.swappiness) by following the guide below, which is from the previous article: Linux server needs a RAM upgrade? Check with top, free, vmstat, and sar:

    vfs_cache_pressure – Controls the kernel’s tendency to reclaim the memory, which is used for caching of directory and inode objects. (default = 100, recommend value 50 to 200)

    swappiness – This control is used to define how aggressive the kernel will swap memory pages. Higher values will increase aggressiveness; lower values decrease the amount of swap. (default = 60, recommended values between 1 and 60) Remove your swap for 0 value, but usually not recommended in most cases.

    Specific to your case:

    On a healthy server with lots of available memory, use the following:

    vm.swappiness=10
    vm.vfs_cache_pressure=50

    This will decrease the cache pressure [uses MORE memory for cache]. Since caching is good for performance, we want to keep cached data in memory longer. Since the cache will grow larger, we still want to reduce swapping to not cause increased swap I/O. [still promote opportunistic swapping]

    To check current values using these commands use:

    sudo cat /proc/sys/vm/swappiness
    sudo cat /proc/sys/vm/vfs_cache_pressure

    To enable these settings temporarily without rebooting, use the following commands:

    sudo sysctl -w vm.swappiness=10
    sudo sysctl -w vm.vfs_cache_pressure=50

    To make these settings permanent:
    Add or edit these lines in /etc/sysctl.conf file:

    vm.swappiness=10 
    vm.vfs_cache_pressure=50
    
  3. please will the recommended setting help in below scenario ?

  4. You cropped out if the command used was free or free -m.

    It that’s 377G total, you don’t need to do anything. Looks healthy to me. Lots of “available memory”. Are you having issues?

    It would not hurt to add, say 2G to 4Gb of swap and then monitor if it’s used.

  5. They should be looking at the available column. Free = wasted memory. So there’s no issue with the server. Looks fine.

    Free -h would return Gi or Mi at the end of figures. So it’s not free -h (human readable) more likely free -m

    -h, --human

    Show all output fields automatically scaled to
    shortest three digit unit and display the units of
    print out.

    Following units are used.

                B = bytes
                Ki = kibibyte
                Mi = mebibyte
                Gi = gibibyte
                Ti = tebibyte
                Pi = pebibyte
    

Join the discussion - post a comment.

2 more replies

Participants