How do I use oom_score_adj?
On 11.04, /proc/[pid]
contains oom_score_adj
, but man proc
describes the old oom_adj
. I have googled unsuccessfully for any information on how to use this.
What I need to arrange is that processes started by 'pbs' or 'gridengine' are killed before anything else gets killed. How can I do that?
Based on my own Q&A on Unix&Linux on a similar question.
As Stuart pointed out very well in his answer, valid values are integers in the range of -1000 to 1000 for oom_score_adj
. The lower the value, the lower the chance that it's going to be killed.
It's very inconvenient to have to change this value over and over again once you restart the application. The information is simply lost after the process has terminated. Upstart (the init daemon in Ubuntu), has a nice option for this to configure for daemons to make sure it's set whenever it has (re)started:
oom score
[...] snip [...]
Example:
# this application is a "resource hog" oom score 1000 expect daemon respawn exec /usr/bin/leaky-app
So, basically, you can edit the /etc/init/myservice.conf
configuration file for the services you like to change, to include a line oom score -1000
. I do assume that the services 'pbs' or 'gridengine' you're talking about in your question is Upstart-enabled, otherwise you'll need another way to change this permanently.
If you can modify the start script spawning the process that you want to prioritize for oom-killer, add the following to the start script:
echo 1000 > /proc/self/oom_score_adj
The value is inherited for child processes.