www ~: free
             total       used       free     shared    buffers     cached
Mem:          2048       1848        199          0         21        274
-/+ buffers/cache:       1552        496
Swap:         4095       4086          9

On my Ubuntu production webserver that runs apache/nginx/MySQL and services lots of web customers, it looks like our free Swap memory space is almost all used up. What does this mean? I know that we should add more RAM/memory to the server, but I want to know how bad it will be if current usage continues? We were going to wait until this weekend, when Swap space runs out will the server crash? Grind to a halt? Run really slow?


It means you are low on memory. If it isn't already running ungodly slow because of constant disk activity, then you may have some process that has allocated memory but isn't using it, and then it is getting swapped out. If it runs out the system will start somewhat randomly killing processes (search for OOM killer for lots of discussion about how exactly the OOM chooses what is to die).

So what are some remedies solutions to this problem?

Use a command like top to figure out what is using up all the memory. Determine if the memory hog actually needs the memory, or if it is a bug. If it is a bug, try and track down a fix.

If you can't afford the outage to add memory you might check if you can afford a short outage and just kill kill/restart that process.

With Linux you can create swap files, swap doesn't need to be on its own partition. So if you want/need to add more swap you can do it pretty easily without rebooting.

  • So what are some remedies solutions to this problem? – MikeN Aug 4 '10 at 16:33
  • 1
    Get more memory or run fewer processes (or fix the ones which may be hogging the RAM. Find out with 'top') – Matt Simmons Aug 4 '10 at 16:54
  • 1
    Thanks for the advice. I actually had tons of zombie processes I had to kill, my webserver spawned off a lot of pdftk instances that seemed to stall and tie up memory due to disk permissions. Killing them all freed up a lot of swap space before it ran out. – MikeN Aug 4 '10 at 17:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.