Hi, I'm Chris Moyer's Blog.

Am I Running out of Memory?

This was originally authored as a reply to a linode forum poster asking if they needed a virtual server with a larger memory allocation.

I think this tends to be one of those things that nobody can agree on, partially because various common linux tools tend to report memory usage in fairly obtuse and different ways. It's often difficult to find out how much memory you are actually using, because of shared libraries, memory, disk buffers, etc.

I find that using several tools helps to give you a better picture of what's going on with your system.

To see the different output, here's a couple different commands on my linode 450:

:::: cdmoyer:5 ~ :::: free -m

             total       used       free     shared    buffers     cached

Mem:           439        430          8          0         80        224

-/+ buffers/cache:        125        313

Swap:          899          0        899

:::: cdmoyer:5 ~ :::: vmstat a -S M
procs -
————-memory————— —swap- -—io—— system- --cpu——
r b swpd free inact active si so bi bo in cs us sy id wa
2 0 0 8 65 328 0 0 0 1 10 2 0 0 100 0

:::: cdmoyer:5 ~ :::: vmstat S M
procs -
————-memory————— —swap- -—io—— system- --cpu——
r b swpd free buff cache si so bi bo in cs us sy id wa
1 0 0 8 80 224 0 0 0 1 10 2 0 0 100 0

:::: cdmoyer:5 ~ :::: cat /proc/meminfo
MemTotal: 449604 kB
MemFree: 8604 kB
Buffers: 82828 kB
Cached: 229456 kB
SwapCached: 548 kB
Active: 336360 kB
Inactive: 66676 kB
HighTotal: 0 kB
HighFree: 0 kB
LowTotal: 449604 kB
LowFree: 8604 kB
SwapTotal: 921592 kB
SwapFree: 920992 kB
Dirty: 44 kB
Writeback: 0 kB
AnonPages: 90204 kB
Mapped: 37308 kB
Slab: 27536 kB
SReclaimable: 20232 kB
SUnreclaim: 7304 kB
PageTables: 1508 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
CommitLimit: 1146392 kB
Committed_AS: 195216 kB
VmallocTotal: 397304 kB
VmallocUsed: 2836 kB
VmallocChunk: 394468 kB

What you'll see, the longer your system runs, the less free memory you'll have, even if you don't add any processes. This is because of the cache and buffers. These are used by the kernel to speed things up, and not necessarily memory “used” by the system. Especially the cache. The kernel is just taking advantage of the fact that you have spare memory and keeping things read from disk in memory, for performance. Should you fire up more processes (or they start automatically under load), the kernel will give up parts of that space holding older files that haven't been used in a while.

The other thing to note, is in that both of your cases, basically no swap has been or is being used. That's indicative that even though free claims you have limited memory free, you actually have a lot more headroom. If you start to use swap regularly, or have little free memory without it being used by cache, then you need to consider upgrading your RAM.

Back to Blog Home »