From: David Rientjes <rientjes@google.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Oleg Nesterov <oleg@redhat.com>,
KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
Rik van Riel <riel@redhat.com>,
linux-mm@kvack.org
Subject: [patch -mm 1/5 v2] oom: hold tasklist_lock when dumping tasks
Date: Thu, 1 Apr 2010 12:44:28 -0700 (PDT) [thread overview]
Message-ID: <alpine.DEB.2.00.1004011242420.13247@chino.kir.corp.google.com> (raw)
In-Reply-To: <alpine.DEB.2.00.1004011240370.13247@chino.kir.corp.google.com>
dump_header() always requires tasklist_lock to be held because it calls
dump_tasks() which iterates through the tasklist. There are a few places
where this isn't maintained, so make sure tasklist_lock is always held
whenever calling dump_header().
This also fixes the pagefault case where oom_kill_process() is called on
current without tasklist_lock. It is necessary to hold a readlock for
both calling dump_header() and iterating its children.
Reported-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: David Rientjes <rientjes@google.com>
---
mm/oom_kill.c | 23 ++++++++++-------------
1 files changed, 10 insertions(+), 13 deletions(-)
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -395,6 +395,9 @@ static void dump_tasks(const struct mem_cgroup *mem)
} while_each_thread(g, p);
}
+/*
+ * Call with tasklist_lock read-locked.
+ */
static void dump_header(struct task_struct *p, gfp_t gfp_mask, int order,
struct mem_cgroup *mem)
{
@@ -641,8 +644,8 @@ retry:
/* Found nothing?!?! Either we hang forever, or we panic. */
if (!p) {
- read_unlock(&tasklist_lock);
dump_header(NULL, gfp_mask, order, NULL);
+ read_unlock(&tasklist_lock);
panic("Out of memory and no killable processes...\n");
}
@@ -675,11 +678,6 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
/* Got some memory back in the last second. */
return;
- if (sysctl_panic_on_oom == 2) {
- dump_header(NULL, gfp_mask, order, NULL);
- panic("out of memory. Compulsory panic_on_oom is selected.\n");
- }
-
/*
* Check if there were limitations on the allocation (only relevant for
* NUMA) that may require different handling.
@@ -688,15 +686,12 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
&totalpages);
read_lock(&tasklist_lock);
if (unlikely(sysctl_panic_on_oom)) {
- /*
- * panic_on_oom only affects CONSTRAINT_NONE, the kernel
- * should not panic for cpuset or mempolicy induced memory
- * failures.
- */
- if (constraint == CONSTRAINT_NONE) {
+ if (sysctl_panic_on_oom == 2 || constraint == CONSTRAINT_NONE) {
dump_header(NULL, gfp_mask, order, NULL);
read_unlock(&tasklist_lock);
- panic("Out of memory: panic_on_oom is enabled\n");
+ panic("Out of memory: %s panic_on_oom is enabled\n",
+ sysctl_panic_on_oom == 2 ? "compulsory" :
+ "system-wide");
}
}
__out_of_memory(gfp_mask, order, totalpages, constraint, nodemask);
@@ -724,8 +719,10 @@ void pagefault_out_of_memory(void)
if (try_set_system_oom()) {
constrained_alloc(NULL, 0, NULL, &totalpages);
+ read_lock(&tasklist_lock);
err = oom_kill_process(current, 0, 0, 0, totalpages, NULL,
"Out of memory (pagefault)");
+ read_unlock(&tasklist_lock);
if (err)
out_of_memory(NULL, 0, 0, NULL);
clear_system_oom();
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2010-04-01 19:44 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-01 19:44 [patch -mm 0/5] oom: fixes and cleanup David Rientjes
2010-04-01 19:44 ` David Rientjes [this message]
2010-04-02 0:38 ` [patch -mm 1/5 v2] oom: hold tasklist_lock when dumping tasks KAMEZAWA Hiroyuki
2010-04-01 19:44 ` [patch -mm 2/5 v2] oom: give current access to memory reserves if it has been killed David Rientjes
2010-04-02 0:40 ` KAMEZAWA Hiroyuki
2010-04-01 19:44 ` [patch -mm 3/5] oom: avoid sending exiting tasks a SIGKILL David Rientjes
2010-04-02 0:41 ` KAMEZAWA Hiroyuki
2010-04-01 19:44 ` [patch -mm 4/5] oom: cleanup oom_kill_task David Rientjes
2010-04-02 0:42 ` KAMEZAWA Hiroyuki
2010-04-01 19:44 ` [patch -mm 5/5] oom: cleanup oom_badness David Rientjes
2010-04-02 0:44 ` KAMEZAWA Hiroyuki
2010-04-02 9:18 ` David Rientjes
2010-04-02 11:30 ` [patch -mm 0/5] oom: fixes and cleanup Oleg Nesterov
2010-04-05 7:36 ` KOSAKI Motohiro
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=alpine.DEB.2.00.1004011242420.13247@chino.kir.corp.google.com \
--to=rientjes@google.com \
--cc=akpm@linux-foundation.org \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-mm@kvack.org \
--cc=oleg@redhat.com \
--cc=riel@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