proc: fix conversion of oom_score_adj to oom_adj
Ensure that oom_score_adj values are properly converted to oom_adj values by rounding appropriately. When there is an attempt to calculate an oom_adj value from its oom_score_adj value the lack of precision results in an oom_adj value that is one less than it should be. For example the oom_adj calculated from oom_score_adj 117 is calculated as 1.989 (117*17 / 1000), and this is rounded to 1 (and not 2 as it should be). By properly generating oom_adj values backward compatibility is better supported. Change-Id: I7f102cf445e572b8e855a9d6b0cf91e3c438eabf Signed-off-by: Liam Mark <lmark@codeaurora.org> Signed-off-by: Vinayak Menon <vinmenon@codeaurora.org>
This commit is contained in:
parent
3ba1a36ad8
commit
334dad34a6
1 changed files with 9 additions and 4 deletions
|
@ -1018,15 +1018,20 @@ static ssize_t oom_adj_read(struct file *file, char __user *buf, size_t count,
|
|||
int oom_adj = OOM_ADJUST_MIN;
|
||||
size_t len;
|
||||
unsigned long flags;
|
||||
int mult = 1;
|
||||
|
||||
if (!task)
|
||||
return -ESRCH;
|
||||
if (lock_task_sighand(task, &flags)) {
|
||||
if (task->signal->oom_score_adj == OOM_SCORE_ADJ_MAX)
|
||||
if (task->signal->oom_score_adj == OOM_SCORE_ADJ_MAX) {
|
||||
oom_adj = OOM_ADJUST_MAX;
|
||||
else
|
||||
oom_adj = (task->signal->oom_score_adj * -OOM_DISABLE) /
|
||||
OOM_SCORE_ADJ_MAX;
|
||||
} else {
|
||||
if (task->signal->oom_score_adj < 0)
|
||||
mult = -1;
|
||||
oom_adj = roundup(mult * task->signal->oom_score_adj *
|
||||
-OOM_DISABLE, OOM_SCORE_ADJ_MAX) /
|
||||
OOM_SCORE_ADJ_MAX * mult;
|
||||
}
|
||||
unlock_task_sighand(task, &flags);
|
||||
}
|
||||
put_task_struct(task);
|
||||
|
|
Loading…
Add table
Reference in a new issue