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?


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.

  • 1
    Change -17 to something like -16 and the user's processes will be picked before other "critical" system processes. – Otheus Jun 15 '15 at 20:50
  • Good point. Updated. Thx. – rush Jun 15 '15 at 20:51
  • There's nothing wrong with setting overcommit_memory=2, it's just that certain applications (java, browsers) try to gobble up more virtual memory than is available, so they fail. You might actually run out of memory, so monitor swap with a monitoring program, and if swap usage begins to climb, it might be a problem. – Otheus Jun 15 '15 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.