Python Psutil and the differences between free and available memory

In this blog post I am talking about the difference between free and available memory in the psutil python module.

Python psutil module

The python psutil module is a cross platform library that allows reading various process and system metrics. In the Raspberry Pi Cluster I am using this to read basic information about the host such as the CPU, ram and swap information.

As it is cross platform its use is widespread as it makes it simple to access some of these system values.

Differences between Available and Free memory

On Windows these two values are the same so it wont matter which you use, however Linux they may different greatly.

Free Memory

This is the amount of memory that is not being used by the computer. This will typically be the amount of memory at its base state (zeroed).

When you start your system the majority of your memory will be classed as free, however as more is accessed it will be marked as not-free.

Although it is not free, it might no longer contain data and may be able to be used by other programs. An operating system will attempt to keep itself fast by ensuring that it keeps as much of the work in memory. This leads it to keeping hold of memory that it is not currently using, even if its no longer needed.

This means that although there may not be much free memory there may still be a lot available to use.

Available Memory

This is the total memory available to any program if it requests more memory. This is available to be used without removing anything else from memory.

This is the value you would expect to see when you see the “free” memory in Windows.

Psutil recommends using available memory over free because it is typically the value most people will want.

Summary

If you are using psutil or any similar linux based memory information tools, you most likely want to request the amount of available memory and not the free memory.

This represents the amount of memory available to a program that needs more.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.