Tell me more ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

My VPS web server running on CentOS 5.4 (Linux kernel 2.6.16.33-xenU) irregularly (like once a month give or take a few weeks) becomes unresponsive due to oom-killer kicking in. Monitoring of the server shows that it doesn't normally run out of memory, just every so often.

I've read a couple of blogs that point to this page which discusses configuring the kernel to better manage overcommit using the following sysctl settings:

vm.overcommit_memory = 2
vm.overcommit_ratio = 80

My understanding of this (which may be wrong, but I can't find a canonical definition to clarify) is that this prevents the kernel over-allocating memory beyond swap + 80% of physical memory.

However, I have also read some other sources suggesting that these settings are not a good idea - although the critics of this approach seem to be saying "don't do things to break your system, rather than attempting this kludge" in the assumption that causation is always known.

So my question is, what are the pros and cons of this approach, in the context of an Apache2 web server hosting about 10 low traffic sites? In my specific case, the web server has 512Mb RAM, with 1024Mb swap space. This seems to be adequate for the vast majority of the time.

share|improve this question

1 Answer

up vote 8 down vote accepted

Setting overcommit_ratio to 80 is wrong. I cannot stress this enough. Any value less than 100 is wrong and will always be wrong.

The reason for this is that linux applications allocate more than they really need. Say they allocate 4kb to store a couple character string of text. Well thats several KB unused right there. Applications do this a lot, and this is what overcommit is designed for.
So basically with overcommit at 100, the kernel will not allow applications to allocate any more memory than you have (swap + ram). Setting it at less than 100 means that you will never use all your memory. If you are going to set this setting, you should set it higher than 100 because of the fore-mentioned scenario, which is quite common.

Now, as for your issue with the OOM killer triggering, manually setting overcommit will not likely fix this. The default setting (heuristic determination) is fairly intelligent.
If you wish to see if this is really the cause of the issue, look at /proc/meminfo when the OOM killer runs. If you see that Committed_AS is close to CommitLimit, but free is still showing free memory available, then yes you can manually adjust the overcommit for your scenario. Setting this value too low will cause the OOM killer to start killing applications when you still have plenty of memory free. Setting it too high can cause random applications to die when they try to use memory they were allocated, but isnt actually available (when all the memory does actually get used up).

share|improve this answer
1  
Thanks - I'm trying things with overcommit_ratio set to 100 to see what happens. The main problem I have is that when oom-killer starts it invariably kills sshd preventing me from accessing the server and seeing what is going on. I guess what I really need is to stop oom-killer from running and some means of recording what happens when it would have run so I can find the cause of the problem. – dunxd Feb 23 '12 at 9:41
2  
@dunxd you can use /proc/<PID>/oom_score_adj for this purpose. For example, if you set oom_score_adj to -1000 for sshd, the oom killer will never target sshd when it wants to kill something. Stopping oom killer entirely isnt a good idea as then your programs wont be able to malloc memory, and they'll die anyway. – Patrick Feb 24 '12 at 14:44
1  
That would be a great function if the PID for an app was static... – dunxd Feb 24 '12 at 22:40
3  
@dunxd its inherited. have your init script set it on itself, and anything started by the init script inherits it. – Patrick Feb 25 '12 at 0:49

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.