linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Fix race between oom kill and task exit
@ 2013-11-28  5:09 Ma, Xindong
  2013-11-28  6:35 ` Johannes Weiner
  2013-11-28 18:37 ` Oleg Nesterov
  0 siblings, 2 replies; 17+ messages in thread
From: Ma, Xindong @ 2013-11-28  5:09 UTC (permalink / raw)
  To: akpm, mhocko, rientjes, hannes, rusty, linux-mm, linux-kernel,
	'Peter Zijlstra', 'gregkh@linuxfoundation.org'
  Cc: Ma, Xindong, Tu, Xiaobing

From: Leon Ma <xindong.ma@intel.com>
Date: Thu, 28 Nov 2013 12:46:09 +0800
Subject: [PATCH] Fix race between oom kill and task exit

There is a race between oom kill and task exit. Scenario is:
   TASK  A                      TASK  B
TASK B is selected to oom kill
in oom_kill_process()
check PF_EXITING of TASK B
                            task call do_exit()
                            task set PF_EXITING flag
                            write_lock_irq(&tasklist_lock);
                            remove TASK B from thread group in __unhash_process()
                            write_unlock_irq(&tasklist_lock);
read_lock(&tasklist_lock);
traverse threads of TASK B
read_unlock(&tasklist_lock);

After that, the following traversal of threads in TASK B will not end because TASK B is not in the thread group:
do {
....
} while_each_thread(p, t);

Signed-off-by: Leon Ma <xindong.ma@intel.com>
Signed-off-by: xiaobing tu <xiaobing.tu@intel.com>
---
 mm/oom_kill.c |   20 ++++++++++----------
 1 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 1e4a600..32ec88d 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -412,16 +412,6 @@ void oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
 	static DEFINE_RATELIMIT_STATE(oom_rs, DEFAULT_RATELIMIT_INTERVAL,
 					      DEFAULT_RATELIMIT_BURST);
 
-	/*
-	 * If the task is already exiting, don't alarm the sysadmin or kill
-	 * its children or threads, just set TIF_MEMDIE so it can die quickly
-	 */
-	if (p->flags & PF_EXITING) {
-		set_tsk_thread_flag(p, TIF_MEMDIE);
-		put_task_struct(p);
-		return;
-	}
-
 	if (__ratelimit(&oom_rs))
 		dump_header(p, gfp_mask, order, memcg, nodemask);
 
@@ -437,6 +427,16 @@ void oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
 	 * still freeing memory.
 	 */
 	read_lock(&tasklist_lock);
+	/*
+	 * If the task is already exiting, don't alarm the sysadmin or kill
+	 * its children or threads, just set TIF_MEMDIE so it can die quickly
+	 */
+	if (p->flags & PF_EXITING) {
+		set_tsk_thread_flag(p, TIF_MEMDIE);
+		put_task_struct(p);
+		read_unlock(&tasklist_lock);
+		return;
+	}
 	do {
 		list_for_each_entry(child, &t->children, sibling) {
 			unsigned int child_points;
-- 
1.7.4.1


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

end of thread, other threads:[~2013-12-06 17:55 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-28  5:09 [PATCH] Fix race between oom kill and task exit Ma, Xindong
2013-11-28  6:35 ` Johannes Weiner
2013-11-28  8:41   ` William Dauchy
2013-11-28 12:00     ` Michal Hocko
2013-11-28 17:57       ` Vladimir Murzin
2013-11-28 18:38       ` Oleg Nesterov
2013-11-29  2:06         ` Ma, Xindong
2013-11-29  2:08           ` Tu, Xiaobing
2013-12-02 14:12         ` Oleg Nesterov
2013-12-05  0:56           ` David Rientjes
2013-12-05 17:29             ` Oleg Nesterov
2013-12-05 23:35               ` David Rientjes
2013-12-06 15:19                 ` Oleg Nesterov
2013-12-06 15:52                   ` Oleg Nesterov
2013-12-06 17:54                   ` Sameer Nanda
2013-11-28  9:18   ` azurIt
2013-11-28 18:37 ` Oleg Nesterov

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