6

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!

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

5 Answers 5

12

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.

4
  • 1
    Assuming it's Linux, yeah.
    – Chris S
    Mar 14, 2012 at 19:07
  • Is OOM killer actually implemented in typical distributions like Debian/Ubuntu/RHEL?
    – Daniel
    Mar 14, 2012 at 19:56
  • Yes it's present there Mar 14, 2012 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? Oct 17, 2014 at 5:12
5

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.

2

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.)

1

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:

SELECT ID, USER, HOST, DB, COMMAND, TIME, STATE, LEFT(INFO, 51200) AS Info FROM information_schema.PROCESSLIST;

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

1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .