Linux VM: Overcommit Memory and Ratio

Rashkae ubuntu at tigershaunt.com
Wed Mar 18 19:01:20 UTC 2009


Anthony M. Rasat wrote:
> Heya guys,
> 
> I had a OOM (Out Of Memory) situation. This machine have 512 MB RAM and 1 GB swap running Apache MySQL PHP. Something went wrong in PHP (which I'm not gonna discuss) and MySQL ended up wanted memory more than system ever owned.
> 
> Now, to avoid that incident in future, I readjusted /proc/sys/vm/overcommit_memory to 2 (default 0) and /proc/sys/vm/overcommit_ratio to 50 (default 50 too).
> 
> My question is what side effect will showed up? Will MySQL start to slowing down? Will Apache begin to fail? I know more RAM is better idea but what if PHP gone berserk again? Will it better if OOM killer kept loose otherwise? Thanks for your insights.
> 

The side effect is that OOM will never kill memory hogging process.

In practice, if PHP goes wild, it requests more memory, the kernel
denies it, PHP crashes, and released all that was already leaked, so all
is good.

In theory however, nothing says that PHP, (or any other memory hog) has
to crash if memory allocation fails.  A process can consume all
available memory, and continue running so long as it's coded to handle
the failure when Malloc doesn't work anymore.  As a consequence however,
 you won't be able to log in to fix things, since you won't even be able
to allocate memory to open a new terminal, and will likely have to reboot.

The more graceful solution would be to ulimit to restrict the amount of
memory your PHP running terminal (or whatever you call the top level
process for something started in init) is allowed to have.




More information about the ubuntu-users mailing list