Last Updated: February 25, 2016
· mattwillsh

Checking memory usage under Linux

A common performance issue on web servers is cause by running out of physical RAM.

Rather than use top, run:

$ free -m
             total       used       free     shared    buffers     cached
Mem:           996        925         71          0        173        493
-/+ buffers/cache:        258        738
Swap:         2015          5       2010

Look at the -/+ buffers/cache free field - 738 in this example above. This shows the absolute amount of RAM left in megabytes. If that's looking low, say <5-10% of Mem total, you're running out of RAM.

If Swap used is more that 10% of Mem total, you might have already run out and paging to disk has started - this can be fatal for a web application.

2 Responses
Add your response

You also have to be aware of the fact, that different server types have different memory usage needs. E.g. a database server should never swap at all, as this can quickly become a bottleneck, locking up the whole server.

Also there's a common practice now to remove any swap from VMs in Datacenters. Generally this is not bad, as you can save the (slow) Disk-IO, but it needs really careful planning and even more careful and tested configurations though, as you easily can run into OOM-situations where your kernel uses the OOM killer to (randomly) kill running applications. But if you are aware of this, it is very much tuneable and you can read more on that on

over 1 year ago ·

@mkzero Any system that needs near or at real-time response shouldn't page to disk those processes that it relies on to serve the those responses. Having some ancillary processes end up on disk isn't a killer, but tends to indicate low memory situations.

swap is a buffer - if you hit it, things slow down then more RAM can be added or config amended. Trying to prematurely optimise can be a bit of a minefield.

over 1 year ago ·