Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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!

share|improve this question
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

5 Answers 5

up vote 12 down vote accepted

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.

share|improve this answer
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 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.

share|improve this answer

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

share|improve this answer

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.

share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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