Free memory on Linux: free -m vs /proc/meminfo

Server Monitoring.png

Updated version of an article first published on January 11th, 2010.

How much memory is really available on your Linux box? Don't use /proc/meminfo to find out, use free -m instead. You may have more memory available than you thought.

Here's an example. /proc/meminfo says about 330MB is free:

    ~ $cat /proc/meminfo 
    MemFree:        340996 kB
    ..

free -m gives the following:

    ~ $free -m
                             total       used       free     shared    buffers     cached
    Mem:          1024        691        332          0         86        288
    -/+ buffers/cache:        316        708
    Swap:         2047         68       1979

You'll see the "buffers" and "cached" columns, which tell you about the amount of memory that the kernel is using for filesystem buffers, etc.

This sort of cached data will be freed by the kernel when an application tries to allocate more than what is "free", which is why the "-/+ buffers/cache" line is really the important line to pay attention to when you're checking out the free memory on a system.

So in this example, 708MB is how much memory is technically available for allocation should an application need it. The "buffers" (86MB) and "cached" (288MB) will be released by the kernal if they are needed.

All credit for this post goes to Eric Lindvall, who also wrote the memory profiler plugin.

Subscribe to our RSS feed or follow us on Twitter for more insights on Linux performance.

More servers? Or faster code?

Adding servers can be a band-aid for slow code. Scout APM helps you find and fix your inefficient and costly code. We automatically identify N+1 SQL calls, memory bloat, and other code-related issues so you can spend less time debugging and more time programming. 

Ready to optimize your site? Sign up for a free trial.