diff options
author | Oleg Nesterov <oleg@redhat.com> | 2014-12-12 19:56:24 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-12-13 15:42:49 -0500 |
commit | d003f371b27016354c392464819530d47a915765 (patch) | |
tree | 0615df29b862f71b0ef14d8079218ba9edb201fd | |
parent | ba914f481507a0542a7c8a3fc15d89414bc2ebf3 (diff) |
oom: don't assume that a coredumping thread will exit soon
oom_kill.c assumes that PF_EXITING task should exit and free the memory
soon. This is wrong in many ways and one important case is the coredump.
A task can sleep in exit_mm() "forever" while the coredumping sub-thread
can need more memory.
Change the PF_EXITING checks to take SIGNAL_GROUP_COREDUMP into account,
we add the new trivial helper for that.
Note: this is only the first step, this patch doesn't try to solve other
problems. The SIGNAL_GROUP_COREDUMP check is obviously racy, a task can
participate in coredump after it was already observed in PF_EXITING state,
so TIF_MEMDIE (which also blocks oom-killer) still can be wrongly set.
fatal_signal_pending() can be true because of SIGNAL_GROUP_COREDUMP so
out_of_memory() and mem_cgroup_out_of_memory() shouldn't blindly trust it.
And even the name/usage of the new helper is confusing, an exiting thread
can only free its ->mm if it is the only/last task in thread group.
[akpm@linux-foundation.org: add comment]
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Cc: Cong Wang <xiyou.wangcong@gmail.com>
Acked-by: David Rientjes <rientjes@google.com>
Acked-by: Michal Hocko <mhocko@suse.cz>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | include/linux/oom.h | 11 | ||||
-rw-r--r-- | mm/memcontrol.c | 2 | ||||
-rw-r--r-- | mm/oom_kill.c | 6 |
3 files changed, 15 insertions, 4 deletions
diff --git a/include/linux/oom.h b/include/linux/oom.h index e8d6e1058723..853698c721f7 100644 --- a/include/linux/oom.h +++ b/include/linux/oom.h | |||
@@ -92,6 +92,17 @@ static inline bool oom_gfp_allowed(gfp_t gfp_mask) | |||
92 | 92 | ||
93 | extern struct task_struct *find_lock_task_mm(struct task_struct *p); | 93 | extern struct task_struct *find_lock_task_mm(struct task_struct *p); |
94 | 94 | ||
95 | static inline bool task_will_free_mem(struct task_struct *task) | ||
96 | { | ||
97 | /* | ||
98 | * A coredumping process may sleep for an extended period in exit_mm(), | ||
99 | * so the oom killer cannot assume that the process will promptly exit | ||
100 | * and release memory. | ||
101 | */ | ||
102 | return (task->flags & PF_EXITING) && | ||
103 | !(task->signal->flags & SIGNAL_GROUP_COREDUMP); | ||
104 | } | ||
105 | |||
95 | /* sysctls */ | 106 | /* sysctls */ |
96 | extern int sysctl_oom_dump_tasks; | 107 | extern int sysctl_oom_dump_tasks; |
97 | extern int sysctl_oom_kill_allocating_task; | 108 | extern int sysctl_oom_kill_allocating_task; |
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index c6ac50e7d1c2..998fb1756d43 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c | |||
@@ -1559,7 +1559,7 @@ static void mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask, | |||
1559 | * select it. The goal is to allow it to allocate so that it may | 1559 | * select it. The goal is to allow it to allocate so that it may |
1560 | * quickly exit and free its memory. | 1560 | * quickly exit and free its memory. |
1561 | */ | 1561 | */ |
1562 | if (fatal_signal_pending(current) || current->flags & PF_EXITING) { | 1562 | if (fatal_signal_pending(current) || task_will_free_mem(current)) { |
1563 | set_thread_flag(TIF_MEMDIE); | 1563 | set_thread_flag(TIF_MEMDIE); |
1564 | return; | 1564 | return; |
1565 | } | 1565 | } |
diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 864bba992735..f694ef0d9f9a 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c | |||
@@ -281,7 +281,7 @@ enum oom_scan_t oom_scan_process_thread(struct task_struct *task, | |||
281 | if (oom_task_origin(task)) | 281 | if (oom_task_origin(task)) |
282 | return OOM_SCAN_SELECT; | 282 | return OOM_SCAN_SELECT; |
283 | 283 | ||
284 | if (task->flags & PF_EXITING && !force_kill) { | 284 | if (task_will_free_mem(task) && !force_kill) { |
285 | /* | 285 | /* |
286 | * If this task is not being ptraced on exit, then wait for it | 286 | * If this task is not being ptraced on exit, then wait for it |
287 | * to finish before killing some other task unnecessarily. | 287 | * to finish before killing some other task unnecessarily. |
@@ -443,7 +443,7 @@ void oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order, | |||
443 | * If the task is already exiting, don't alarm the sysadmin or kill | 443 | * If the task is already exiting, don't alarm the sysadmin or kill |
444 | * its children or threads, just set TIF_MEMDIE so it can die quickly | 444 | * its children or threads, just set TIF_MEMDIE so it can die quickly |
445 | */ | 445 | */ |
446 | if (p->flags & PF_EXITING) { | 446 | if (task_will_free_mem(p)) { |
447 | set_tsk_thread_flag(p, TIF_MEMDIE); | 447 | set_tsk_thread_flag(p, TIF_MEMDIE); |
448 | put_task_struct(p); | 448 | put_task_struct(p); |
449 | return; | 449 | return; |
@@ -649,7 +649,7 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask, | |||
649 | * select it. The goal is to allow it to allocate so that it may | 649 | * select it. The goal is to allow it to allocate so that it may |
650 | * quickly exit and free its memory. | 650 | * quickly exit and free its memory. |
651 | */ | 651 | */ |
652 | if (fatal_signal_pending(current) || current->flags & PF_EXITING) { | 652 | if (fatal_signal_pending(current) || task_will_free_mem(current)) { |
653 | set_thread_flag(TIF_MEMDIE); | 653 | set_thread_flag(TIF_MEMDIE); |
654 | return; | 654 | return; |
655 | } | 655 | } |