All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm, oom: Fix race when selecting process to kill
@ 2013-11-05 23:26 ` Sameer Nanda
  0 siblings, 0 replies; 51+ messages in thread
From: Sameer Nanda @ 2013-11-05 23:26 UTC (permalink / raw)
  To: akpm, mhocko, rientjes, hannes, rusty
  Cc: linux-mm, linux-kernel, Sameer Nanda

The selection of the process to be killed happens in two spots -- first
in select_bad_process and then a further refinement by looking for
child processes in oom_kill_process. Since this is a two step process,
it is possible that the process selected by select_bad_process may get a
SIGKILL just before oom_kill_process executes. If this were to happen,
__unhash_process deletes this process from the thread_group list. This
then results in oom_kill_process getting stuck in an infinite loop when
traversing the thread_group list of the selected process.

Fix this race by holding the tasklist_lock across the calls to both
select_bad_process and oom_kill_process.

Change-Id: I8f96b106b3257b5c103d6497bac7f04f4dff4e60
Signed-off-by: Sameer Nanda <snanda@chromium.org>
---
 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 6738c47..7bd3587 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -436,7 +436,6 @@ void oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
 	 * parent.  This attempts to lose the minimal amount of work done while
 	 * still freeing memory.
 	 */
-	read_lock(&tasklist_lock);
 	do {
 		list_for_each_entry(child, &t->children, sibling) {
 			unsigned int child_points;
@@ -456,7 +455,6 @@ void oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
 			}
 		}
 	} while_each_thread(p, t);
-	read_unlock(&tasklist_lock);
 
 	rcu_read_lock();
 	p = find_lock_task_mm(victim);
@@ -641,6 +639,7 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
 	mpol_mask = (constraint == CONSTRAINT_MEMORY_POLICY) ? nodemask : NULL;
 	check_panic_on_oom(constraint, gfp_mask, order, mpol_mask);
 
+	read_lock(&tasklist_lock);
 	if (sysctl_oom_kill_allocating_task && current->mm &&
 	    !oom_unkillable_task(current, NULL, nodemask) &&
 	    current->signal->oom_score_adj != OOM_SCORE_ADJ_MIN) {
@@ -663,6 +662,7 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
 		killed = 1;
 	}
 out:
+	read_unlock(&tasklist_lock);
 	/*
 	 * Give the killed threads a good chance of exiting before trying to
 	 * allocate memory again.
-- 
1.8.4.1


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

end of thread, other threads:[~2013-11-14 17:04 UTC | newest]

Thread overview: 51+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-05 23:26 [PATCH] mm, oom: Fix race when selecting process to kill Sameer Nanda
2013-11-05 23:26 ` Sameer Nanda
2013-11-06  1:18 ` David Rientjes
2013-11-06  1:18   ` David Rientjes
2013-11-06  1:25   ` Luigi Semenzato
2013-11-06  1:25     ` Luigi Semenzato
2013-11-06  1:27     ` David Rientjes
2013-11-06  1:27       ` David Rientjes
2013-11-06  3:00       ` Vladimir Murzin
2013-11-06  3:00         ` Vladimir Murzin
2013-11-06  3:04       ` Sameer Nanda
2013-11-06  4:45         ` Luigi Semenzato
2013-11-06  4:45           ` Luigi Semenzato
2013-11-06  7:17           ` Luigi Semenzato
2013-11-06  7:17             ` Luigi Semenzato
2013-11-06 16:58             ` Sameer Nanda
2013-11-06 16:58               ` Sameer Nanda
2013-11-07  0:35               ` David Rientjes
2013-11-07  0:35                 ` David Rientjes
2013-11-07 19:34                 ` Sameer Nanda
2013-11-07 19:34                   ` Sameer Nanda
2013-11-08 18:07                 ` [PATCH v2] " Sameer Nanda
2013-11-08 18:07                   ` Sameer Nanda
2013-11-08 18:45                   ` Oleg Nesterov
2013-11-08 18:45                     ` Oleg Nesterov
2013-11-08 19:49                     ` [PATCH v3] " Sameer Nanda
2013-11-08 19:49                       ` Sameer Nanda
2013-11-09 15:16                       ` Oleg Nesterov
2013-11-09 15:16                         ` Oleg Nesterov
2013-11-11 23:15                         ` Sameer Nanda
2013-11-12  0:21                         ` [PATCH v4] " Sameer Nanda
2013-11-12  0:21                           ` Sameer Nanda
2013-11-12 15:13                           ` Michal Hocko
2013-11-12 15:13                             ` Michal Hocko
2013-11-12 20:01                           ` Oleg Nesterov
2013-11-12 20:01                             ` Oleg Nesterov
2013-11-12 20:08                             ` Sameer Nanda
2013-11-12 20:08                               ` Sameer Nanda
2013-11-12 20:23                               ` [PATCH v5] " Sameer Nanda
2013-11-12 20:23                                 ` Sameer Nanda
2013-11-13  2:33                                 ` David Rientjes
2013-11-13  2:33                                   ` David Rientjes
2013-11-13 16:46                                   ` Sameer Nanda
2013-11-13 16:46                                     ` Sameer Nanda
2013-11-13 17:18                                     ` [PATCH v6] " Sameer Nanda
2013-11-13 17:18                                       ` Sameer Nanda
2013-11-13 17:29                                       ` Oleg Nesterov
2013-11-13 17:29                                         ` Oleg Nesterov
2013-11-14 13:43                                       ` dserrg
2013-11-14 17:03                                         ` Sameer Nanda
2013-11-14 17:03                                           ` Sameer Nanda

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.