linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [patch] mm, oom: allow exiting tasks to have access to memory reserves
@ 2012-03-07  2:25 David Rientjes
  2012-03-07  6:39 ` KOSAKI Motohiro
  0 siblings, 1 reply; 6+ messages in thread
From: David Rientjes @ 2012-03-07  2:25 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, KAMEZAWA Hiroyuki, KOSAKI Motohiro

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,
so this saves time and prevents threads that haven't yet exited (although
their parent has been oom killed) from getting missed.

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 |   16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/mm/oom_kill.c b/mm/oom_kill.c
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -568,11 +568,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 +723,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>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-03-08 21:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-07  2:25 [patch] mm, oom: allow exiting tasks to have access to memory reserves David Rientjes
2012-03-07  6:39 ` KOSAKI Motohiro
2012-03-07  7:21   ` David Rientjes
2012-03-07  7:22     ` [patch v2] " David Rientjes
2012-03-08 20:08     ` [patch] " Andrew Morton
2012-03-08 21:59       ` David Rientjes

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).