Friday, March 11, 2011

Preventing OOM killer from terminating your vmware session

The linux-kernel comes with a mechanism (OOM-Killer) that will terminate processes in order to free up memory when it runs out of memory. After upgrading my Ubuntu 10.10 setup to a 2.6.36 kernel, my vmware session repeatedly got terminated, despite plenty of free memory and swap.
In order to prevent this from happening I figured out that you can change the the value of the /proc/[id_of_vmware_vmx_process]/oom_adj to -17.  I have made a small shell script that checks whether the vmware process is running and if this is the case, adjust the oom_adj value:

contents of /usr/bin/vmware-protect-from-oom.sh:

#!/bin/bash
pid=$(pidof vmware-vmx)
if [ $pid > 0 ]; then
sudo echo "-17" > /proc/$pid/oom_adj
fi


In order to run this automatically, add the following line to the end of your root user's cronjob list:  sudo crontab -e):

* * * * * /usr/bin/vmware-protect-from-oom.sh