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] mm/oom_kill: change oom_kill_process() to bump ->mm_count rather than ->mm_users
Date: Mon, 5 Oct 2015 18:34:27 +0200 [thread overview]
Message-ID: <20151005163427.GA20595@redhat.com> (raw)
oom_kill_process() does atomic_inc(&mm->mm_users) to ensure that
this ->mm can't go away and this is wrong, change it to rely on
->mm_count and mmdrop().
Firstly, we do not want to delay exit_mmap/etc if the victim exits
before we do mmput(), but this is minor.
More importantly, we simply can not do mmput() in oom_kill_process(),
this can deadlock. For example, suppose that access_process_vm(tsk)
triggers OOM and oom-killer decides to kill this "tsk". If it exits
and does mmput() before us, ksm_exit() called by us may want to want
to take the same mmap_sem for writing.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
mm/oom_kill.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 034d219..52abb78 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -571,7 +571,7 @@ void oom_kill_process(struct oom_control *oc, struct task_struct *p,
/* Get a reference to safely compare mm after task_unlock(victim) */
mm = victim->mm;
- atomic_inc(&mm->mm_users);
+ atomic_inc(&mm->mm_count);
/*
* We should send SIGKILL before setting TIF_MEMDIE in order to prevent
* the OOM victim from depleting the memory reserves from the user
@@ -609,7 +609,7 @@ void oom_kill_process(struct oom_control *oc, struct task_struct *p,
}
rcu_read_unlock();
- mmput(mm);
+ mmdrop(mm);
put_task_struct(victim);
}
#undef K
--
2.4.3
next reply other threads:[~2015-10-05 16:37 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-05 16:34 Oleg Nesterov [this message]
2015-10-05 17:36 ` [PATCH -mm] mm/oom_kill: change oom_kill_process() to bump ->mm_count rather than ->mm_users Oleg Nesterov
2015-10-06 16:26 ` Oleg Nesterov
2015-10-06 16:28 ` [PATCH -mm] mmoom-fix-potentially-killing-unrelated-process-fix Oleg Nesterov
2015-10-06 16:56 ` Michal Hocko
2015-10-06 22:49 ` Hugh Dickins
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=20151005163427.GA20595@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.