Skip to content

Commit fadd8fb

Browse files
hkamezawaLinus Torvalds
authored andcommitted
[PATCH] support for panic at OOM
This patch adds panic_on_oom sysctl under sys.vm. When sysctl vm.panic_on_oom = 1, the kernel panics intead of killing rogue processes. And if vm.panic_on_oom is 0 the kernel will do oom_kill() in the same way as it does today. Of course, the default value is 0 and only root can modifies it. In general, oom_killer works well and kill rogue processes. So the whole system can survive. But there are environments where panic is preferable rather than kill some processes. Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 67de648 commit fadd8fb

4 files changed

Lines changed: 26 additions & 0 deletions

File tree

‎Documentation/sysctl/vm.txt‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Currently, these files are in /proc/sys/vm:
2929
- drop-caches
3030
- zone_reclaim_mode
3131
- zone_reclaim_interval
32+
- panic_on_oom
3233

3334
==============================================================
3435

@@ -178,3 +179,15 @@ Time is set in seconds and set by default to 30 seconds.
178179
Reduce the interval if undesired off node allocations occur. However, too
179180
frequent scans will have a negative impact onoff node allocation performance.
180181

182+
=============================================================
183+
184+
panic_on_oom
185+
186+
This enables or disables panic on out-of-memory feature. If this is set to 1,
187+
the kernel panics when out-of-memory happens. If this is set to 0, the kernel
188+
will kill some rogue process, called oom_killer. Usually, oom_killer can kill
189+
rogue processes and system will survive. If you want to panic the system
190+
rather than killing rogue processes, set this to 1.
191+
192+
The default value is 0.
193+

‎include/linux/sysctl.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ enum
186186
VM_PERCPU_PAGELIST_FRACTION=30,/* int: fraction of pages in each percpu_pagelist */
187187
VM_ZONE_RECLAIM_MODE=31, /* reclaim local zone memory before going off node */
188188
VM_ZONE_RECLAIM_INTERVAL=32, /* time period to wait after reclaim failure */
189+
VM_PANIC_ON_OOM=33, /* panic at out-of-memory */
189190
};
190191

191192

‎kernel/sysctl.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ extern int proc_nr_files(ctl_table *table, int write, struct file *filp,
5959
extern int C_A_D;
6060
extern int sysctl_overcommit_memory;
6161
extern int sysctl_overcommit_ratio;
62+
extern int sysctl_panic_on_oom;
6263
extern int max_threads;
6364
extern int sysrq_enabled;
6465
extern int core_uses_pid;
@@ -701,6 +702,14 @@ static ctl_table vm_table[] = {
701702
.mode = 0644,
702703
.proc_handler = &proc_dointvec,
703704
},
705+
{
706+
.ctl_name = VM_PANIC_ON_OOM,
707+
.procname = "panic_on_oom",
708+
.data = &sysctl_panic_on_oom,
709+
.maxlen = sizeof(sysctl_panic_on_oom),
710+
.mode = 0644,
711+
.proc_handler = &proc_dointvec,
712+
},
704713
{
705714
.ctl_name = VM_OVERCOMMIT_RATIO,
706715
.procname = "overcommit_ratio",

‎mm/oom_kill.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/jiffies.h>
2323
#include <linux/cpuset.h>
2424

25+
int sysctl_panic_on_oom;
2526
/* #define DEBUG */
2627

2728
/**
@@ -344,6 +345,8 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask, int order)
344345
break;
345346

346347
case CONSTRAINT_NONE:
348+
if (sysctl_panic_on_oom)
349+
panic("out of memory. panic_on_oom is selected\n");
347350
retry:
348351
/*
349352
* Rambo mode: Shoot down a process and hope it solves whatever

0 commit comments

Comments
 (0)