Commit fe071d7e8aae5745c009c808bb8933f22a9e305a

Authored by David Rientjes
Committed by Linus Torvalds
1 parent ff0ceb9deb

oom: add oom_kill_allocating_task sysctl

Adds a new sysctl, 'oom_kill_allocating_task', which will automatically kill
the OOM-triggering task instead of scanning through the tasklist to find a
memory-hogging target.  This is helpful for systems with an insanely large
number of tasks where scanning the tasklist significantly degrades
performance.

Cc: Andrea Arcangeli <andrea@suse.de>
Acked-by: Christoph Lameter <clameter@sgi.com>
Signed-off-by: David Rientjes <rientjes@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 3 changed files with 39 additions and 5 deletions Side-by-side Diff

Documentation/sysctl/vm.txt
... ... @@ -31,6 +31,7 @@
31 31 - min_unmapped_ratio
32 32 - min_slab_ratio
33 33 - panic_on_oom
  34 +- oom_kill_allocating_task
34 35 - mmap_min_address
35 36 - numa_zonelist_order
36 37  
... ... @@ -219,6 +220,27 @@
219 220 The default value is 0.
220 221 1 and 2 are for failover of clustering. Please select either
221 222 according to your policy of failover.
  223 +
  224 +=============================================================
  225 +
  226 +oom_kill_allocating_task
  227 +
  228 +This enables or disables killing the OOM-triggering task in
  229 +out-of-memory situations.
  230 +
  231 +If this is set to zero, the OOM killer will scan through the entire
  232 +tasklist and select a task based on heuristics to kill. This normally
  233 +selects a rogue memory-hogging task that frees up a large amount of
  234 +memory when killed.
  235 +
  236 +If this is set to non-zero, the OOM killer simply kills the task that
  237 +triggered the out-of-memory condition. This avoids the expensive
  238 +tasklist scan.
  239 +
  240 +If panic_on_oom is selected, it takes precedence over whatever value
  241 +is used in oom_kill_allocating_task.
  242 +
  243 +The default value is 0.
222 244  
223 245 ==============================================================
224 246  
... ... @@ -63,6 +63,7 @@
63 63 extern int sysctl_overcommit_memory;
64 64 extern int sysctl_overcommit_ratio;
65 65 extern int sysctl_panic_on_oom;
  66 +extern int sysctl_oom_kill_allocating_task;
66 67 extern int max_threads;
67 68 extern int core_uses_pid;
68 69 extern int suid_dumpable;
... ... @@ -777,6 +778,14 @@
777 778 .procname = "panic_on_oom",
778 779 .data = &sysctl_panic_on_oom,
779 780 .maxlen = sizeof(sysctl_panic_on_oom),
  781 + .mode = 0644,
  782 + .proc_handler = &proc_dointvec,
  783 + },
  784 + {
  785 + .ctl_name = CTL_UNNUMBERED,
  786 + .procname = "oom_kill_allocating_task",
  787 + .data = &sysctl_oom_kill_allocating_task,
  788 + .maxlen = sizeof(sysctl_oom_kill_allocating_task),
780 789 .mode = 0644,
781 790 .proc_handler = &proc_dointvec,
782 791 },
... ... @@ -27,6 +27,7 @@
27 27 #include <linux/notifier.h>
28 28  
29 29 int sysctl_panic_on_oom;
  30 +int sysctl_oom_kill_allocating_task;
30 31 static DEFINE_MUTEX(zone_scan_mutex);
31 32 /* #define DEBUG */
32 33  
33 34  
... ... @@ -471,14 +472,16 @@
471 472 "No available memory (MPOL_BIND)");
472 473 break;
473 474  
474   - case CONSTRAINT_CPUSET:
475   - oom_kill_process(current, points,
476   - "No available memory in cpuset");
477   - break;
478   -
479 475 case CONSTRAINT_NONE:
480 476 if (sysctl_panic_on_oom)
481 477 panic("out of memory. panic_on_oom is selected\n");
  478 + /* Fall-through */
  479 + case CONSTRAINT_CPUSET:
  480 + if (sysctl_oom_kill_allocating_task) {
  481 + oom_kill_process(current, points,
  482 + "Out of memory (oom_kill_allocating_task)");
  483 + break;
  484 + }
482 485 retry:
483 486 /*
484 487 * Rambo mode: Shoot down a process and hope it solves whatever