From: David Rientjes <rientjes@google.com>
To: Andrew Morton <akpm@linux-foundation.org>,
KOSAKI Motohiro <kosaki.motohiro@gmail.com>
Cc: linux-mm@kvack.org,
KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Subject: [patch v2] mm, oom: allow exiting tasks to have access to memory reserves
Date: Tue, 6 Mar 2012 23:22:36 -0800 (PST) [thread overview]
Message-ID: <alpine.DEB.2.00.1203062321590.4158@chino.kir.corp.google.com> (raw)
In-Reply-To: <alpine.DEB.2.00.1203062316430.4158@chino.kir.corp.google.com>
The tasklist iteration only checks processes and avoids individual
threads so it is possible that threads that are currently exiting may not
appropriately being selected for oom kill. This can lead to negative
results such as an innocent process being killed in the interim or, in
the worst case, the machine panicking because there is nothing else to kill.
We automatically select PF_EXITING threads during the tasklist iteration in
select_bad_process(), so this saves time and prevents threads that haven't
yet exited (although their parent has been oom killed) from getting missed.
It also allows that code to be removed from select_bad_process().
Note that by doing this we aren't actually oom killing an exiting thread
but rather giving it full access to memory reserves so it may quickly
exit and free its memory.
Signed-off-by: David Rientjes <rientjes@google.com>
---
mm/oom_kill.c | 40 +++++++++++++---------------------------
1 file changed, 13 insertions(+), 27 deletions(-)
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -342,26 +342,12 @@ static struct task_struct *select_bad_process(unsigned int *ppoints,
if (p->flags & PF_EXITING) {
/*
- * If p is the current task and is in the process of
- * releasing memory, we allow the "kill" to set
- * TIF_MEMDIE, which will allow it to gain access to
- * memory reserves. Otherwise, it may stall forever.
- *
- * The loop isn't broken here, however, in case other
- * threads are found to have already been oom killed.
+ * If this task is not being ptraced on exit, then wait
+ * for it to finish before killing some other task
+ * unnecessarily.
*/
- if (p == current) {
- chosen = p;
- *ppoints = 1000;
- } else {
- /*
- * If this task is not being ptraced on exit,
- * then wait for it to finish before killing
- * some other task unnecessarily.
- */
- if (!(p->group_leader->ptrace & PT_TRACE_EXIT))
- return ERR_PTR(-1UL);
- }
+ if (!(p->group_leader->ptrace & PT_TRACE_EXIT))
+ return ERR_PTR(-1UL);
}
points = oom_badness(p, memcg, nodemask, totalpages);
@@ -568,11 +554,11 @@ void mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask)
struct task_struct *p;
/*
- * If current has a pending SIGKILL, then automatically select it. The
- * goal is to allow it to allocate so that it may quickly exit and free
- * its memory.
+ * If current is exiting (or going to exit), then automatically select
+ * it. The goal is to allow it to allocate so that it may quickly exit
+ * and free its memory.
*/
- if (fatal_signal_pending(current)) {
+ if (fatal_signal_pending(current) || (current->flags & PF_EXITING)) {
set_thread_flag(TIF_MEMDIE);
return;
}
@@ -723,11 +709,11 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
return;
/*
- * If current has a pending SIGKILL, then automatically select it. The
- * goal is to allow it to allocate so that it may quickly exit and free
- * its memory.
+ * If current is exiting (or going to exit), then automatically select
+ * it. The goal is to allow it to allocate so that it may quickly exit
+ * and free its memory.
*/
- if (fatal_signal_pending(current)) {
+ if (fatal_signal_pending(current) || (current->flags & PF_EXITING)) {
set_thread_flag(TIF_MEMDIE);
return;
}
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2012-03-07 7:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-07 2:25 [patch] " David Rientjes
2012-03-07 6:39 ` KOSAKI Motohiro
2012-03-07 7:21 ` David Rientjes
2012-03-07 7:22 ` David Rientjes [this message]
2012-03-08 20:08 ` Andrew Morton
2012-03-08 21:59 ` David Rientjes
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.1203062321590.4158@chino.kir.corp.google.com \
--to=rientjes@google.com \
--cc=akpm@linux-foundation.org \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=kosaki.motohiro@gmail.com \
--cc=kosaki.motohiro@jp.fujitsu.com \
--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