linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: David Rientjes <rientjes@google.com>,
	Kyle Walker <kwalker@redhat.com>,
	Michal Hocko <mhocko@kernel.org>,
	Stanislav Kozina <skozina@redhat.com>,
	Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>,
	linux-kernel@vger.kernel.org
Subject: [PATCH -mm 3/3] mm/oom_kill: fix the wrong task->mm == mm checks in
Date: Tue, 29 Sep 2015 16:18:22 +0200	[thread overview]
Message-ID: <20150929141822.GA10962@redhat.com> (raw)
In-Reply-To: <20150929141758.GA10934@redhat.com>

Both "child->mm == mm" and "p->mm != mm" checks in oom_kill_process()
are wrong. ->mm can be if task is the exited group leader. This means
in particular that "kill sharing same memory" loop can miss a process
with a zombie leader which uses the same ->mm.

Note: the process_has_mm(child, p->mm) check is still not 100% correct,
p->mm can be NULL too. This is minor, but probably deserves a fix or a
comment anyway.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 mm/oom_kill.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 8e7bed2..8ecac2ef 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -483,6 +483,17 @@ void oom_killer_enable(void)
 	oom_killer_disabled = false;
 }
 
+static bool process_has_mm(struct task_struct *p, struct mm_struct *mm)
+{
+	struct task_struct *t;
+
+	for_each_thread(p, t)
+		if (t->mm)
+			return t->mm == mm;
+
+	return false;
+}
+
 #define K(x) ((x) << (PAGE_SHIFT-10))
 /*
  * Must be called while holding a reference to p, which will be released upon
@@ -530,7 +541,7 @@ void oom_kill_process(struct oom_control *oc, struct task_struct *p,
 		list_for_each_entry(child, &t->children, sibling) {
 			unsigned int child_points;
 
-			if (child->mm == p->mm)
+			if (process_has_mm(child, p->mm))
 				continue;
 			/*
 			 * oom_badness() returns 0 if the thread is unkillable
@@ -588,7 +599,7 @@ void oom_kill_process(struct oom_control *oc, struct task_struct *p,
 			continue;
 		if (same_thread_group(p, victim))
 			continue;
-		if (p->mm != mm)
+		if (!process_has_mm(p, mm))
 			continue;
 		if (p->signal->oom_score_adj == OOM_SCORE_ADJ_MIN)
 			continue;
-- 
2.4.3


  parent reply	other threads:[~2015-09-29 14:21 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-29 14:17 [PATCH -mm 0/3] mm/oom_kill: ensure we actually kill all tasks sharing the same mm Oleg Nesterov
2015-09-29 14:18 ` [PATCH -mm 1/3] mm/oom_kill: remove the wrong fatal_signal_pending() Oleg Nesterov
2015-09-29 22:36   ` David Rientjes
2015-09-30  1:42     ` Tetsuo Handa
2015-09-30 13:47       ` Oleg Nesterov
2015-09-30 15:20         ` [PATCH -mm 1/3] mm/oom_kill: remove the wrongfatal_signal_pending() Tetsuo Handa
2015-09-30 13:43     ` [PATCH -mm 1/3] mm/oom_kill: remove the wrong fatal_signal_pending() Oleg Nesterov
2015-09-29 14:18 ` [PATCH -mm 2/3] mm/oom_kill: cleanup the "kill sharing same memory" Oleg Nesterov
2015-09-29 22:39   ` David Rientjes
2015-09-30 13:49     ` Oleg Nesterov
2015-09-29 14:18 ` Oleg Nesterov [this message]
2015-09-29 22:41   ` [PATCH -mm 3/3] mm/oom_kill: fix the wrong task->mm == mm checks in David Rientjes
2015-09-30 13:50     ` Oleg Nesterov
2015-09-30  2:16   ` Tetsuo Handa
2015-09-30 13:59     ` Oleg Nesterov
2015-09-30 18:23 ` [PATCH -mm v2 0/3] mm/oom_kill: ensure we actually kill all tasks sharing the same mm Oleg Nesterov
2015-09-30 18:24   ` [PATCH -mm v2 1/3] mm/oom_kill: remove the wrong fatal_signal_pending() check in oom_kill_process() Oleg Nesterov
2015-09-30 21:14     ` David Rientjes
2015-10-01 10:52       ` [PATCH -mm v2 1/3] mm/oom_kill: remove the wrong fatal_signal_pending()check " Tetsuo Handa
2015-10-01 12:49     ` [PATCH -mm v2 1/3] mm/oom_kill: remove the wrong fatal_signal_pending() check " Michal Hocko
2015-10-01 15:00       ` Oleg Nesterov
2015-10-01 15:27         ` Michal Hocko
2015-10-01 15:41           ` Oleg Nesterov
2015-10-01 16:19             ` Michal Hocko
2015-10-01 17:53               ` Oleg Nesterov
2015-10-02 11:32                 ` Tetsuo Handa
2015-10-02 12:11                   ` Michal Hocko
2015-10-02 12:33                     ` Tetsuo Handa
2015-10-02 13:32                       ` Michal Hocko
2015-10-02 13:57                         ` Oleg Nesterov
2015-10-02 14:24                           ` Michal Hocko
2015-10-02 14:07                         ` Tetsuo Handa
2015-10-02 14:15                           ` Oleg Nesterov
2015-10-02 13:52                   ` Oleg Nesterov
2015-10-02 14:36                     ` Tetsuo Handa
2015-09-30 18:24   ` [PATCH -mm v2 2/3] mm/oom_kill: cleanup the "kill sharing same memory" loop Oleg Nesterov
2015-09-30 21:15     ` David Rientjes
2015-10-01 12:50     ` Michal Hocko
2015-09-30 18:24   ` [PATCH -mm v2 3/3] mm/oom_kill: fix the wrong task->mm == mm checks in oom_kill_process() Oleg Nesterov
2015-09-30 21:15     ` David Rientjes
2015-10-01 12:56     ` Michal Hocko
2015-10-01 22:24     ` Andrew Morton

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=20150929141822.GA10962@redhat.com \
    --to=oleg@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=kwalker@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhocko@kernel.org \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    --cc=rientjes@google.com \
    --cc=skozina@redhat.com \
    /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).