Memory Management with free


Memory management with free

Basic monitoring should be done on a regular basis. This keeps you informed as to the general condition of your server and may warn of impending problems.

This article concentrates on memory management using the command 'free'.  For additional information on infrastructure monitoring, see Getting Started With Remote Monitoring.

Memory management is actually very easy to do. What you do about any problem is a different matter and we'll look at monitoring what is actually using the memory and how much it's using in a later article.


To start with, log into your server and give the 'free' command:


The output consists of four lines:


Well, for a start, that's all a bit confusing as the answer is in Kb. I don't know about you but dividing the reported figures by 1024 is a bit of a pain.

Free -m

Let's make it more readable by adding the '-m' option which will displays the output in megabytes:

free -m

That's better:


One of the aliases in my .bash_profile is:

alias free="free -m"

So I only have to enter 'free' to get a readable output.

Buffers and Cache

The first line gives the column headers: total, used, free and so on.

A common mistake is to read the second line and have a panic attack as that line reports:

.                total       used       free     shared    buffers     cached
Mem:         254        249          5          0             15             181

However, the figure of 249MB out of 254MB includes cached and buffered memory.

Unless you are particularly interested in the buffers and cached figures, ignore this line.

Actual Usage

Concentrate on the third line:

.                total       used       free     shared    buffers     cached
Mem:         254        249          5          0         15        181
-/+ buffers/cache:    51         202

This tells us what memory is being used and is not available for another process.

So it reports 51MB of 254MB being used by various tasks and applications. I have 202MB to play with and for my application to grow into.

Not bad, but then I don't have anything installed on this demo Cloud Server - this was just after a base install and update.


Swap is disk-based memory space that can be configured on some servers (it's not present by default on newer cloud servers). Since I have swap configured, the final line tells me how much swap space I am using:

.                total       used       free     shared    buffers     cached
Mem:         254        249          5          0         15        181
-/+ buffers/cache:    51         202
Swap:        511          0          511

As you can see, I have 511MB of swap available and have used none of it.

If you are using swap space then you need to investigate what is using so much memory that it had to resort to hard drive swapping to work. Often it's a case of your application 'outgrowing' your Cloud Server and you may need to upgrade it to include more RAM.

The odd bit of swapping is fine as it is, after all, there to be used. However, consistent swapping or very high levels of swapping does mean your Cloud Server is struggling and it will make your web application slow down.

Regular monitoring

Actually, that's a good example as to why regular monitoring of your Cloud Server is a good idea - your site may be up and running but it may be struggling and becoming slower and slower.

It's a lot better to catch any issues before they result in downtime and a non-operational site.

That's it - quick and easy. Next time we'll look at system monitoring with 'top' which will pinpoint what processes are actually using the memory and, more importantly, how much each process is using.

Was this content helpful?

© 2015 Rackspace US, Inc.

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License

See license specifics and DISCLAIMER