diff --git a/kernel/sysctl.c b/kernel/sysctl.c index b2a2d68..3b132ee 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -67,6 +67,7 @@ extern int sysctl_overcommit_ratio; extern int sysctl_panic_on_oom; extern int sysctl_oom_kill_allocating_task; extern int sysctl_oom_dump_tasks; +extern int sysctl_would_have_oomkilled; extern int max_threads; extern int core_uses_pid; extern int suid_dumpable; @@ -861,6 +862,14 @@ static struct ctl_table vm_table[] = { .proc_handler = &proc_dointvec, }, { + .ctl_name = CTL_UNNUMBERED, + .procname = "would_have_oomkilled", + .data = &sysctl_would_have_oomkilled, + .maxlen = sizeof(sysctl_would_have_oomkilled), + .mode = 0644, + .proc_handler = &proc_dointvec, + }, + { .ctl_name = VM_OVERCOMMIT_RATIO, .procname = "overcommit_ratio", .data = &sysctl_overcommit_ratio, diff --git a/mm/oom_kill.c b/mm/oom_kill.c index f255eda..3335a94 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -31,6 +31,7 @@ int sysctl_panic_on_oom; int sysctl_oom_kill_allocating_task; int sysctl_oom_dump_tasks; +int sysctl_would_have_oomkilled; static DEFINE_SPINLOCK(zone_scan_lock); /* #define DEBUG */ @@ -321,6 +322,12 @@ static void __oom_kill_task(struct task_struct *p, int verbose) return; } + if (sysctl_would_have_oomkilled == 1) { + printk(KERN_ERR "Would have killed process %d (%s). But continuing instead.\n", + task_pid_nr(p), p->comm); + return; + } + if (verbose) printk(KERN_ERR "Killed process %d (%s)\n", task_pid_nr(p), p->comm); @@ -363,6 +370,12 @@ static int oom_kill_task(struct task_struct *p) return 1; } while_each_thread(g, q); + if (sysctl_would_have_oomkilled == 1) { + printk(KERN_ERR "Would have killed process %d (%s). But continuing instead.\n", + task_pid_nr(p), p->comm); + return 1; + } + __oom_kill_task(p, 1); /*