Exclude user from OOM killer in unix

out of memory

Is there anyway to exclude some users from the out-of- memory killer in Unix? On the other way, can I set priority for user?

Best Answer

There is no way to instruct OOM to ignore specific user processes. Though you can instruct it to ignore a specific process and based on that you can construct a loop which will check all processes for specific user and update it via cron or whatever way you like. Cycle itself will look something like that:

while read r_pid ; do 
    echo -16 | sudo tee /proc/$r_pid/oom_adj ; 
done < <(pgrep -U Yoki)

you can wrap it in script and schedule to be run once per minute or any interval you like.

or you can completely disable OOM with

sysctl vm.overcommit_memory=2
echo "vm.overcommit_memory=2" >> /etc/sysctl.conf

though it is not recommended way at all, as it might lead to unexpected behaviour such as kernel panics or system hang.

Related Question