Skip to content

Commit fe071d7

Browse files
rientjesLinus Torvalds
authored andcommitted
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>
1 parent ff0ceb9 commit fe071d7

3 files changed

Lines changed: 39 additions & 5 deletions

File tree

‎Documentation/sysctl/vm.txt‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Currently, these files are in /proc/sys/vm:
3131
- min_unmapped_ratio
3232
- min_slab_ratio
3333
- panic_on_oom
34+
- oom_kill_allocating_task
3435
- mmap_min_address
3536
- numa_zonelist_order
3637

@@ -220,6 +221,27 @@ The default value is 0.
220221
1 and 2 are for failover of clustering. Please select either
221222
according to your policy of failover.
222223

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.
244+
223245
==============================================================
224246

225247
mmap_min_addr

‎kernel/sysctl.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ extern int print_fatal_signals;
6363
extern int sysctl_overcommit_memory;
6464
extern int sysctl_overcommit_ratio;
6565
extern int sysctl_panic_on_oom;
66+
extern int sysctl_oom_kill_allocating_task;
6667
extern int max_threads;
6768
extern int core_uses_pid;
6869
extern int suid_dumpable;
@@ -780,6 +781,14 @@ static ctl_table vm_table[] = {
780781
.mode = 0644,
781782
.proc_handler = &proc_dointvec,
782783
},
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),
789+
.mode = 0644,
790+
.proc_handler = &proc_dointvec,
791+
},
783792
{
784793
.ctl_name = VM_OVERCOMMIT_RATIO,
785794
.procname = "overcommit_ratio",

‎mm/oom_kill.c‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/notifier.h>
2828

2929
int sysctl_panic_on_oom;
30+
int sysctl_oom_kill_allocating_task;
3031
static DEFINE_MUTEX(zone_scan_mutex);
3132
/* #define DEBUG */
3233

@@ -471,14 +472,16 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask, int order)
471472
"No available memory (MPOL_BIND)");
472473
break;
473474

474-
case CONSTRAINT_CPUSET:
475-
oom_kill_process(current, points,
476-
"No available memory in cpuset");
477-
break;
478-
479475
case CONSTRAINT_NONE:
480476
if (sysctl_panic_on_oom)
481477
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+
}
482485
retry:
483486
/*
484487
* Rambo mode: Shoot down a process and hope it solves whatever

0 commit comments

Comments
 (0)