aboutsummaryrefslogtreecommitdiffstats
path: root/mm/oom_kill.c
diff options
context:
space:
mode:
authorDavid Rientjes <rientjes@google.com>2012-03-21 19:34:04 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-03-21 20:54:58 -0400
commit08ab9b10d43aca091fdff58b69fc1ec89c5b8a83 (patch)
tree73abfd3a257f3feadc0fa28c3117aaa9d95af596 /mm/oom_kill.c
parentb76437579d1344b612cf1851ae610c636cec7db0 (diff)
mm, oom: force oom kill on sysrq+f
The oom killer chooses not to kill a thread if: - an eligible thread has already been oom killed and has yet to exit, and - an eligible thread is exiting but has yet to free all its memory and is not the thread attempting to currently allocate memory. SysRq+F manually invokes the global oom killer to kill a memory-hogging task. This is normally done as a last resort to free memory when no progress is being made or to test the oom killer itself. For both uses, we always want to kill a thread and never defer. This patch causes SysRq+F to always kill an eligible thread and can be used to force a kill even if another oom killed thread has failed to exit. Signed-off-by: David Rientjes <rientjes@google.com> Acked-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Acked-by: Pekka Enberg <penberg@kernel.org> Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/oom_kill.c')
-rw-r--r--mm/oom_kill.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 517299c808cb..f23f33454645 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -310,7 +310,7 @@ static enum oom_constraint constrained_alloc(struct zonelist *zonelist,
310 */ 310 */
311static struct task_struct *select_bad_process(unsigned int *ppoints, 311static struct task_struct *select_bad_process(unsigned int *ppoints,
312 unsigned long totalpages, struct mem_cgroup *memcg, 312 unsigned long totalpages, struct mem_cgroup *memcg,
313 const nodemask_t *nodemask) 313 const nodemask_t *nodemask, bool force_kill)
314{ 314{
315 struct task_struct *g, *p; 315 struct task_struct *g, *p;
316 struct task_struct *chosen = NULL; 316 struct task_struct *chosen = NULL;
@@ -336,7 +336,8 @@ static struct task_struct *select_bad_process(unsigned int *ppoints,
336 if (test_tsk_thread_flag(p, TIF_MEMDIE)) { 336 if (test_tsk_thread_flag(p, TIF_MEMDIE)) {
337 if (unlikely(frozen(p))) 337 if (unlikely(frozen(p)))
338 __thaw_task(p); 338 __thaw_task(p);
339 return ERR_PTR(-1UL); 339 if (!force_kill)
340 return ERR_PTR(-1UL);
340 } 341 }
341 if (!p->mm) 342 if (!p->mm)
342 continue; 343 continue;
@@ -354,7 +355,7 @@ static struct task_struct *select_bad_process(unsigned int *ppoints,
354 if (p == current) { 355 if (p == current) {
355 chosen = p; 356 chosen = p;
356 *ppoints = 1000; 357 *ppoints = 1000;
357 } else { 358 } else if (!force_kill) {
358 /* 359 /*
359 * If this task is not being ptraced on exit, 360 * If this task is not being ptraced on exit,
360 * then wait for it to finish before killing 361 * then wait for it to finish before killing
@@ -572,7 +573,7 @@ void mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask)
572 check_panic_on_oom(CONSTRAINT_MEMCG, gfp_mask, 0, NULL); 573 check_panic_on_oom(CONSTRAINT_MEMCG, gfp_mask, 0, NULL);
573 limit = mem_cgroup_get_limit(memcg) >> PAGE_SHIFT; 574 limit = mem_cgroup_get_limit(memcg) >> PAGE_SHIFT;
574 read_lock(&tasklist_lock); 575 read_lock(&tasklist_lock);
575 p = select_bad_process(&points, limit, memcg, NULL); 576 p = select_bad_process(&points, limit, memcg, NULL, false);
576 if (p && PTR_ERR(p) != -1UL) 577 if (p && PTR_ERR(p) != -1UL)
577 oom_kill_process(p, gfp_mask, 0, points, limit, memcg, NULL, 578 oom_kill_process(p, gfp_mask, 0, points, limit, memcg, NULL,
578 "Memory cgroup out of memory"); 579 "Memory cgroup out of memory");
@@ -687,6 +688,7 @@ static void clear_system_oom(void)
687 * @gfp_mask: memory allocation flags 688 * @gfp_mask: memory allocation flags
688 * @order: amount of memory being requested as a power of 2 689 * @order: amount of memory being requested as a power of 2
689 * @nodemask: nodemask passed to page allocator 690 * @nodemask: nodemask passed to page allocator
691 * @force_kill: true if a task must be killed, even if others are exiting
690 * 692 *
691 * If we run out of memory, we have the choice between either 693 * If we run out of memory, we have the choice between either
692 * killing a random task (bad), letting the system crash (worse) 694 * killing a random task (bad), letting the system crash (worse)
@@ -694,7 +696,7 @@ static void clear_system_oom(void)
694 * don't have to be perfect here, we just have to be good. 696 * don't have to be perfect here, we just have to be good.
695 */ 697 */
696void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask, 698void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
697 int order, nodemask_t *nodemask) 699 int order, nodemask_t *nodemask, bool force_kill)
698{ 700{
699 const nodemask_t *mpol_mask; 701 const nodemask_t *mpol_mask;
700 struct task_struct *p; 702 struct task_struct *p;
@@ -738,7 +740,8 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask,
738 goto out; 740 goto out;
739 } 741 }
740 742
741 p = select_bad_process(&points, totalpages, NULL, mpol_mask); 743 p = select_bad_process(&points, totalpages, NULL, mpol_mask,
744 force_kill);
742 /* Found nothing?!?! Either we hang forever, or we panic. */ 745 /* Found nothing?!?! Either we hang forever, or we panic. */
743 if (!p) { 746 if (!p) {
744 dump_header(NULL, gfp_mask, order, NULL, mpol_mask); 747 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
@@ -770,7 +773,7 @@ out:
770void pagefault_out_of_memory(void) 773void pagefault_out_of_memory(void)
771{ 774{
772 if (try_set_system_oom()) { 775 if (try_set_system_oom()) {
773 out_of_memory(NULL, 0, 0, NULL); 776 out_of_memory(NULL, 0, 0, NULL, false);
774 clear_system_oom(); 777 clear_system_oom();
775 } 778 }
776 if (!test_thread_flag(TIF_MEMDIE)) 779 if (!test_thread_flag(TIF_MEMDIE))