From: minyard@acm.org
To: Andrew Morton <akpm@linux-foundation.org>, linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org, Corey Minyard <cminyard@mvista.com>
Subject: [PATCH] oom_kill: oom_score_adj broken for processes with small memory usage
Date: Thu, 1 Jul 2021 07:54:30 -0500 [thread overview]
Message-ID: <20210701125430.836308-1-minyard@acm.org> (raw)
From: Corey Minyard <cminyard@mvista.com>
If you have a process with less than 1000 totalpages, the calculation:
adj = (long)p->signal->oom_score_adj;
...
adj *= totalpages / 1000;
will always result in adj being zero no matter what oom_score_adj is,
which could result in the wrong process being picked for killing.
Fix by adding 1000 to totalpages before dividing.
Signed-off-by: Corey Minyard <cminyard@mvista.com>
---
I ran across this trying to diagnose another problem where I set up a
cgroup with a small amount of memory and couldn't get a test program to
work right.
I'm not sure this is quite right, to keep closer to the current behavior
you could do:
if (totalpages >= 1000)
adj *= totalpages / 1000;
but that would map 0-1999 to the same value. But this at least shows
the issue. I can provide a test program the shows the issue, but I
think it's pretty obvious from the code.
mm/oom_kill.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index eefd3f5fde46..4ae0b6193bcd 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -233,8 +233,11 @@ long oom_badness(struct task_struct *p, unsigned long totalpages)
mm_pgtables_bytes(p->mm) / PAGE_SIZE;
task_unlock(p);
- /* Normalize to oom_score_adj units */
- adj *= totalpages / 1000;
+ /*
+ * Normalize to oom_score_adj units. You should never
+ * multiply by zero here, or oom_score_adj will not work.
+ */
+ adj *= (totalpages + 1000) / 1000;
points += adj;
return points;
--
2.25.1
next reply other threads:[~2021-07-01 12:54 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-01 12:54 minyard [this message]
2021-07-16 5:19 ` [PATCH] oom_kill: oom_score_adj broken for processes with small memory usage Michal Hocko
2021-07-16 12:25 ` Corey Minyard
2021-09-02 19:55 ` Andrew Morton
2021-09-03 1:52 ` Corey Minyard
2021-09-03 7:49 ` Michal Hocko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210701125430.836308-1-minyard@acm.org \
--to=minyard@acm.org \
--cc=akpm@linux-foundation.org \
--cc=cminyard@mvista.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).