[PATCH 05 of 16] avoid selecting already killed tasks

Andrea Arcangeli
2007-06-08T20:06:54Z

# HG changeset patch
# User Andrea Arcangeli <andrea@suse.de>
# Date 1181332960 -7200
# Node ID 2ebc46595ead0f1790c6ec1d0302dd60ffbb1978
# Parent baa866fedc79cb333b90004da2730715c145f1d5
avoid selecting already killed tasks

If the killed task doesn't go away because it's waiting on some other
task who needs to allocate memory, to release the i_sem or some other
lock, we must fallback to killing some other task in order to kill the
original selected and already oomkilled task, but the logic that kills
the childs first, would deadlock, if the already oom-killed task was
actually the first child of the newly oom-killed task.

Signed-off-by: Andrea Arcangeli <andrea@suse.de>

diff --git a/mm/oom_kill.c b/mm/oom_kill.c
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -366,6 +366,12 @@ static int oom_kill_process(struct task_
c = list_entry(tsk, struct task_struct, sibling);
if (c->mm == p->mm)
continue;
+ /*
+ * We cannot select tasks with TIF_MEMDIE already set
+ * or we'll hard deadlock.
+ */
+ if (unlikely(test_tsk_thread_flag(c, TIF_MEMDIE)))
+ continue;
if (!oom_kill_task(c))
return 0;
}