Skip to contentSkip to conversation

mm, oom: keep oom_adj under or at upper limit when printing

PATCH In review Charles Haithcock 2 participants 2 messages Oct 19, 2020 – Oct 20, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm, oom: keep oom_adj under or at upper limit when printing

For oom_score_adj values in the range [942,999], the current calculations will print 16 for oom_adj. This patch simply limits the output so output is inline with docs.

---
 fs/proc/base.c | 2 ++
 1 file changed, 2 insertions(+)
fs/proc/base.c +2 -0
index 617db4e0faa0..37e57b21dbe5 100644
@@ -1048,6 +1048,8 @@ static ssize_t oom_adj_read(struct file *file, char __user *buf, size_t count,
 	else
 		oom_adj = (task->signal->oom_score_adj * -OOM_DISABLE) /
 			  OOM_SCORE_ADJ_MAX;
+	if (oom_adj > OOM_ADJUST_MAX)
+		oom_adj = OOM_ADJUST_MAX;
 	put_task_struct(task);
 	len = snprintf(buffer, sizeof(buffer), "%d\n", oom_adj);
 	return simple_read_from_buffer(buf, count, ppos, buffer, len);
Signature · 1 line
2.25.1
#1 lore raw

fs/proc/base.c static ssize_t oom_adj_read(struct file *file, char __user *buf, size_t count, · line 1053

Quoted 13 lines · Charles Haithcock

For oom_score_adj values in the range [942,999], the current calculations will print 16 for oom_adj. This patch simply limits the output so output is inline with docs.

fs/proc/base.c +2 -0
@@ -1048,6 +1048,8 @@ static ssize_t oom_adj_read(struct file *file, char __user *buf, size_t count,
 	else
 		oom_adj = (task->signal->oom_score_adj * -OOM_DISABLE) /
 			  OOM_SCORE_ADJ_MAX;
+	if (oom_adj > OOM_ADJUST_MAX)
+		oom_adj = OOM_ADJUST_MAX;
 	put_task_struct(task);

Should be done after PUT so that task is put as early as possible.

Quoted 2 lines
fs/proc/base.c +0 -0
 	len = snprintf(buffer, sizeof(buffer), "%d\n", oom_adj);
 	return simple_read_from_buffer(buf, count, ppos, buffer, len);