From: "Chris Swiedler" <chris.swiedler@sevista.com>
To: "Linux-Kernel" <linux-kernel@vger.kernel.org>,
"Rik van Riel" <riel@conectiva.com.br>
Subject: [PATCH] protect processes from OOM killer
Date: Tue, 7 Nov 2000 11:19:37 -0500 [thread overview]
Message-ID: <NDBBIAJKLMMHOGKNMGFNMEADCPAA.chris.swiedler@sevista.com> (raw)
Here's a small patch to allow a user to protect certain PIDs from death-
by-OOM-killer. It uses the proc entry '/proc/sys/vm/oom_protect'; echo the
PIDs to be protected:
echo 1 516 > /proc/sys/vm/oom_protect
The idea is that sysadmins can mark some daemon processes as off-limits for
the OOM killer. Stuff like syslogd, init, etc. Incidentally, this answers
Andrea's concern about the init process getting killed. In fact, it might
be a good idea to default the list of protected PIDs to be { 1 }.
Things I'd like to add:
- ability to append PIDs. Using the 'echo >>' syntax would be nice, but
/proc
files don't seem to support appending. (is this true?)
- symbolic process names as well as PIDs, maybe process groups too?
- perhaps a more complex interface, where instead of just marking a PID as
absolutely protected, you could specify a 'weight' which factored into the
OOM algorithm. Something like "nice":
-20 : unkillable
-19 to -1: try not to kill
1 to 19: try to kill these first
echo netscape:10 > /proc/sys/vm/oom_protect
...would suggest that "netscape" is a process which is a good candidate
for OOM killing.
I don't think that we should make the OOM heuristic any more complex.
However,
letting the user make suggestions about what should and should not be killed
is a Good Thing.
This is my very first patch, so please be considerate.
Against 2.4.0-test10. Comments and suggestions appreciated!
chris
--- official/linux-2.4.0-test10/mm/oom_kill.c Mon Nov 6 23:40:52 2000
+++ work/linux-2.4.0-test10/mm/oom_kill.c Mon Nov 6 23:37:47 2000
@@ -20,9 +20,32 @@
#include <linux/swap.h>
#include <linux/swapctl.h>
#include <linux/timex.h>
+#include <linux/ctype.h>
+
+#define MAX_OOM_PROTECTS 256
+
+int sysctl_oom_protects[MAX_OOM_PROTECTS];
/* #define DEBUG */
+int is_oom_protected(int pid)
+{
+ int i;
+ for (i = 0; i < MAX_OOM_PROTECTS; i++) {
+ int ppid = sysctl_oom_protects[i];
+
+ #ifdef DEBUG
+ printk("Protected pid: %d\n",ppid);
+ #endif
+
+ if (ppid == pid)
+ return 1;
+ if (ppid == 0)
+ return 0;
+ }
+ return 0;
+}
+
/**
* int_sqrt - oom_kill.c internal function, rough approximation to sqrt
* @x: integer of which to calculate the sqrt
@@ -124,6 +147,19 @@
read_lock(&tasklist_lock);
for_each_task(p)
{
+ #ifdef DEBUG
+ printk("Testing pid %d\n",p->pid);
+ #endif
+
+ if (is_oom_protected(p->pid))
+
+ #ifdef DEBUG
+ printk("Pid %d is protected\n",p->pid);
+ #endif
+
+ continue;
+ }
+
if (p->pid)
points = badness(p);
if (points > maxpoints) {
--- official/linux-2.4.0-test10/kernel/sysctl.c Mon Nov 6 23:40:52 2000
+++ work/linux-2.4.0-test10/kernel/sysctl.c Mon Nov 6 23:30:08 2000
@@ -85,6 +85,8 @@
extern int pgt_cache_water[];
+extern int sysctl_oom_protects [];
+
static int parse_table(int *, int, void *, size_t *, void *, size_t,
ctl_table *, void **);
static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
@@ -241,6 +243,10 @@
&bdflush_min, &bdflush_max},
{VM_OVERCOMMIT_MEMORY, "overcommit_memory", &sysctl_overcommit_memory,
sizeof(sysctl_overcommit_memory), 0644, NULL, &proc_dointvec},
+
+ {VM_OVERCOMMIT_MEMORY, "oom_protect", &sysctl_oom_protects,
+ 256, 0644, NULL, &proc_dointvec},
+
{VM_BUFFERMEM, "buffermem",
&buffer_mem, sizeof(buffer_mem_t), 0644, NULL, &proc_dointvec},
{VM_PAGECACHE, "pagecache",
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/
next reply other threads:[~2000-11-07 16:16 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-11-07 16:19 Chris Swiedler [this message]
2000-11-07 20:47 ` [PATCH] protect processes from OOM killer Ingo Oeser
2000-11-07 21:44 ` Frank van Maarseveen
2000-12-02 2:20 ` Path: for oom_kill.c hugang
2000-12-04 16:57 ` Rik van Riel
2000-12-04 17:52 ` Jeff Epler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=NDBBIAJKLMMHOGKNMGFNMEADCPAA.chris.swiedler@sevista.com \
--to=chris.swiedler@sevista.com \
--cc=linux-kernel@vger.kernel.org \
--cc=riel@conectiva.com.br \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).