Running MySQL on a box with 32 gigs of RAM. Swap is 99% full, and there is about 200 MB of RAM free. MySQL is the culprit of course. What happens when both RAM and swap are completely filled? Thanks!

  • 2
    Time to put a cap on max memory consumption for mysql, I think. – MDMarra Mar 14 '12 at 19:14
  • Yes, I forgot to mention running Linux. – cat pants Mar 14 '12 at 20:42
  • Ever gotten an OutOfMemoryException in Java? – Chris Thompson Mar 15 '12 at 5:20

9/10 OOM killer will come by and kill the program with the biggest memory consumption. Else your system will crash.

I'm assuming you are on Linux.

  • 1
    Assuming it's Linux, yeah. – Chris S Mar 14 '12 at 19:07
  • Is OOM killer actually implemented in typical distributions like Debian/Ubuntu/RHEL? – Daniel Mar 14 '12 at 19:56
  • Yes it's present there – Lucas Kauffman Mar 14 '12 at 20:04
  • What if the thing consuming the RAM+SWAP is /tmp mounted as TMPFS? Does the OOM killer start killing the tmp or other stuff? – CMCDragonkai Oct 17 '14 at 5:12

That depends on the OS, but when you actually run out something dies. More specifically, something says to the OS "please give me more memory", and the OS says "no".

(That can be by virtue of just touching some memory that it already got told was allocated, causing the page to copy-on-write, so it isn't as simple as "call the kernel memory allocator")

Technically, the process could handle those failures and recover, but practically it results in a crash.

Linux tries hard to guess what a good candidate to kill is, and I think Windows does the same, before you quite get to that state, though - kill something marginally more cleanly so that memory is freed up.


Since free RAM is wasted RAM, Linux tries to use as much of it as possible. It is possible that there are lots of cached disk pages and other things kept in RAM just because there was space. Run free -m to see the how the RAM is used on your machine. It will also show you the number of megs that could be used by applications if needed (column 'free', second row.)


Open some spare ssh sessions to the host until it's not too late. When system have no free RAM/swap, no new process can be launched.

Seems that some query produce unexpected amount of data stored in the temporary table(s) - in memory. Try to kill oldest thread launched by mysql:


Field TIME shows seconds mysql spent performing query. Those having largest TIME are likely the culprits.


Try deploying a custom agent like New Relic to see what processes are unnecessary and start killing them. That can save your server from crashing

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.