Commit f7844601 authored by Andrew Morton's avatar Andrew Morton Committed by Jens Axboe

[PATCH] thread-aware oom-killer

From Ingo

- performance optimization: do not kill threads in the same thread group
  as the OOM-ing thread. (it's still necessery to scan over every thread
  though, as it's possible to have CLONE_VM threads in a different thread
  group - we do not want those to escape the OOM-kill.)

- to not let newly created child threads slip out of the group-kill. Note
  that the 2.4 kernel's OOM handler has the same problem, and it could be
  the reason why forkbombs occasionally slip out of the OOM kill.
parent d08b03c5
...@@ -863,6 +863,14 @@ static struct task_struct *copy_process(unsigned long clone_flags, ...@@ -863,6 +863,14 @@ static struct task_struct *copy_process(unsigned long clone_flags,
/* Need tasklist lock for parent etc handling! */ /* Need tasklist lock for parent etc handling! */
write_lock_irq(&tasklist_lock); write_lock_irq(&tasklist_lock);
/*
* Check for pending SIGKILL! The new thread should not be allowed
* to slip out of an OOM kill. (or normal SIGKILL.)
*/
if (sigismember(&current->pending.signal, SIGKILL)) {
write_unlock_irq(&tasklist_lock);
goto bad_fork_cleanup_namespace;
}
/* CLONE_PARENT re-uses the old parent */ /* CLONE_PARENT re-uses the old parent */
if (clone_flags & CLONE_PARENT) if (clone_flags & CLONE_PARENT)
......
...@@ -175,9 +175,13 @@ static void oom_kill(void) ...@@ -175,9 +175,13 @@ static void oom_kill(void)
if (p == NULL) if (p == NULL)
panic("Out of memory and no killable processes...\n"); panic("Out of memory and no killable processes...\n");
/* kill all processes that share the ->mm (i.e. all threads) */ oom_kill_task(p);
/*
* kill all processes that share the ->mm (i.e. all threads),
* but are in a different thread group
*/
do_each_thread(g, q) do_each_thread(g, q)
if (q->mm == p->mm) if (q->mm == p->mm && q->tgid != p->tgid)
oom_kill_task(q); oom_kill_task(q);
while_each_thread(g, q); while_each_thread(g, q);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment