Kill specific processes first in OOM-killer
Subsystems (3)
PATCH 1/1 Kill specific processes first in OOM-killer
Hi,
one of our clients wanted the possibility to specify which processes do they want to get killed first by the OOM-killer in case of low memory. The agreement included posting the result upstream. The original was implemented on 2.6.27, it was adapted to 2.6.33-rc8 as well. Both patches are included.
There's a new /proc/sys/vm/oom_preferred_tasks file which accepts a string. E.g.:
# echo "/usr/bin/httpd,myforkbomb,oocalc" >/proc/sys/vm/oom_preferred_tasks
The string must contain comma separated process names or executable pathnames. Upon calling out_of_memory(), the processes are checked against the list of names. The process name matching is performed in this order:
1. full pathname of the executable using /proc/PID/exe link
2. executable name without full pathname
3. process name using get_task_comm()
If no such matching process is found, the usual badness check is performed.
Best regards,
Zoltán Böszörményi
Signature · 9 lines
Bible has answers for everything. Proof: "But let your communication be, Yea, yea; Nay, nay: for whatsoever is more than these cometh of evil." (Matthew 5:37) - basics of digital technology. "May your kingdom come" - superficial description of plate tectonics ---------------------------------- Zoltán Böszörményi Cybertec Schönig & Schönig GmbH http://www.postgresql.at/
include/linux/oom.h +1 -0
@@ -6,6 +6,7 @@/* inclusive */ #define OOM_ADJUST_MIN (-16)#define OOM_ADJUST_MAX 15 +#define OOM_PREF_TASKS_MAX_SIZE (4096)#ifdef __KERNEL__
kernel/sysctl.c +11 -0
@@ -48,6 +48,7 @@#include <linux/acpi.h> #include <linux/reboot.h> #include <linux/ftrace.h> +#include <linux/oom.h> #include <asm/uaccess.h> #include <asm/processor.h>
@@ -70,6 +71,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 char sysctl_oom_preferred_tasks[];extern int max_threads;extern int core_uses_pid;extern int suid_dumpable;
@@ -888,6 +890,15 @@ static struct ctl_table vm_table[] = { .proc_handler = &proc_dointvec, }, { + .ctl_name = CTL_UNNUMBERED, + .procname = "oom_preferred_tasks", + .data = sysctl_oom_preferred_tasks, + .maxlen = OOM_PREF_TASKS_MAX_SIZE, + .mode = 0644, + .proc_handler = &proc_dostring, + .strategy = &sysctl_string, + }, + { .ctl_name = VM_OVERCOMMIT_RATIO, .procname = "overcommit_ratio", .data = &sysctl_overcommit_ratio,
mm/oom_kill.c +106 -1
138 lines not on this page · raw message
include/linux/oom.h +1 -0
@@ -6,6 +6,7 @@/* inclusive */ #define OOM_ADJUST_MIN (-16)#define OOM_ADJUST_MAX 15 +#define OOM_PREF_TASKS_MAX_SIZE (4096)#ifdef __KERNEL__
kernel/sysctl.c +11 -0
@@ -50,6 +50,7 @@#include <linux/ftrace.h> #include <linux/slow-work.h> #include <linux/perf_event.h> +#include <linux/oom.h> #include <asm/uaccess.h> #include <asm/processor.h>
@@ -71,6 +72,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 char sysctl_oom_preferred_tasks[];extern int max_threads;extern int core_uses_pid;extern int suid_dumpable;
@@ -973,6 +975,15 @@ static struct ctl_table vm_table[] = { .proc_handler = proc_dointvec, }, { + .ctl_name = CTL_UNNUMBERED, + .procname = "oom_preferred_tasks", + .data = sysctl_oom_preferred_tasks, + .maxlen = OOM_PREF_TASKS_MAX_SIZE, + .mode = 0644, + .proc_handler = &proc_dostring, + .strategy = &sysctl_string, + }, + { .procname = "overcommit_ratio", .data = &sysctl_overcommit_ratio, .maxlen = sizeof(sysctl_overcommit_ratio),
mm/oom_kill.c +108 -2
141 lines not on this page · raw message