3

I am trying to set the oom_adj value for the out of memory killer, and each time I do (regardless of the process) I get back exactly one less than I set (at least for positive integers. I haven't tried negative integers since I want these processes to be killed by OOM Killer first).

[root@server ~]# echo 10 > /proc/12581/oom_adj
[root@server ~]# cat /proc/12581/oom_adj
9
[root@server ~]# echo 9 > /proc/12581/oom_adj
[root@server ~]# cat /proc/12581/oom_adj
8
[root@server ~]# echo 8 > /proc/12581/oom_adj
[root@server ~]# cat /proc/12581/oom_adj
7
[root@server ~]# echo 7 > /proc/12581/oom_adj
[root@server ~]# cat /proc/12581/oom_adj
6
[root@server ~]# 

Is this expected behavior? If not, why is this happening?

  • 1
    You probably want to be using oom_score_adj instead. oom_adj is deprecated. – Patrick May 5 '14 at 20:16
  • That's actually kind of interesting. I'm not seeing that when I modify oom_adj on any of my systems. What kernel version are you running? – Bratchley May 5 '14 at 21:31
  • @JoelDavis I'm current running Fedora 19, 3.13.9 (3.13.9-100.fc19.x86_64) – Freedom_Ben May 6 '14 at 16:15
5

oom_adj is deprecated and provided for legacy purposes only. Internally Linux uses oom_score_adj which has a greater range: oom_adj goes up to 15 while oom_score_adj goes up to 1000.

Whenever you write to oom_adj (let's say 9) the kernel does this:

oom_adj = (oom_adj * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE;

and stores that to oom_score_adj. OOM_SCORE_ADJ_MAX is 1000 and OOM_DISABLE is -17.

So for 9 you'll get oom_adj=(9 * 1000) / 17 ~= 529.411 and since these values are integers, oom_score_adj will hold 529.

Now when you read oom_adj the kernel will do this:

oom_adj = (task->signal->oom_score_adj * -OOM_DISABLE) / OOM_SCORE_ADJ_MAX;

So for 529 you'll get: oom_adj = (529 * 17) / 1000 = 8.993 and since the kernel is using integers and integer arithmetic, this will become 8.

So there... you write 9 and you get 8 because of fixed point / integer arithmetic.

  • Nice well researched answer. This is exactly the stuff we need here on U&L. – Patrick May 6 '14 at 1:16
  • Wow, that is really interesting and makes perfect sense. Thank you! – Freedom_Ben May 6 '14 at 16:16

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.