public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] protect processes from OOM killer
@ 2000-11-07 16:19 Chris Swiedler
  2000-11-07 20:47 ` Ingo Oeser
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Chris Swiedler @ 2000-11-07 16:19 UTC (permalink / raw)
  To: Linux-Kernel, Rik van Riel

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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] protect processes from OOM killer
  2000-11-07 16:19 [PATCH] protect processes from OOM killer Chris Swiedler
@ 2000-11-07 20:47 ` Ingo Oeser
  2000-11-07 21:44 ` Frank van Maarseveen
  2000-12-02  2:20 ` Path: for oom_kill.c hugang
  2 siblings, 0 replies; 6+ messages in thread
From: Ingo Oeser @ 2000-11-07 20:47 UTC (permalink / raw)
  To: Chris Swiedler; +Cc: Linux-Kernel, Rik van Riel

On Tue, Nov 07, 2000 at 11:19:37AM -0500, Chris Swiedler wrote:
> 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:

Please base it upon my OOM-Killer-API patch.

        http://www.tu-chemnitz.de/~ioe/oom_kill_api.patch

This will reduce your patch to an simple module (but you have to
manage refcounting yourself!) and give the user a choice, which
one to use.

If someone provides an OOM-Handler himself, please use my API to
allow better testing and comparing.

PS: Of course it applies cleanly against test10 as well ;-)

Thanks and Regards

Ingo Oeser
-- 
To the systems programmer, users and applications
serve only to provide a test load.
<esc>:x
-
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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] protect processes from OOM killer
  2000-11-07 16:19 [PATCH] protect processes from OOM killer Chris Swiedler
  2000-11-07 20:47 ` Ingo Oeser
@ 2000-11-07 21:44 ` Frank van Maarseveen
  2000-12-02  2:20 ` Path: for oom_kill.c hugang
  2 siblings, 0 replies; 6+ messages in thread
From: Frank van Maarseveen @ 2000-11-07 21:44 UTC (permalink / raw)
  To: Chris Swiedler; +Cc: Linux-Kernel, Rik van Riel

On Tue, Nov 07, 2000 at 11:19:37AM -0500, Chris Swiedler wrote:
> 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
Hmm, I'd prefer "echo 1 >/proc/516/oom_protect". Guess that's
out of the question because only /proc/sys should be used for
setting parameters?

Then maybe /proc/sys/proc should be populated so we can do
"echo 1 >/proc/sys/proc/516/oom_protect".

-- 
Frank
-
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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Path: for oom_kill.c
  2000-11-07 16:19 [PATCH] protect processes from OOM killer Chris Swiedler
  2000-11-07 20:47 ` Ingo Oeser
  2000-11-07 21:44 ` Frank van Maarseveen
@ 2000-12-02  2:20 ` hugang
  2000-12-04 16:57   ` Rik van Riel
  2 siblings, 1 reply; 6+ messages in thread
From: hugang @ 2000-12-02  2:20 UTC (permalink / raw)
  To: linux-kernel

Hello all:
	
old    ---->     points = p->mm->total_vm;
       
change to --->   points = p->pid;


	I write a shell to test it,

cat > bin/hello
hello
^D

hello
before change it ,kernel will kill some pid, to change it kernel will kill hello(bash).
-
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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Path: for oom_kill.c
  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
  0 siblings, 1 reply; 6+ messages in thread
From: Rik van Riel @ 2000-12-04 16:57 UTC (permalink / raw)
  To: hugang; +Cc: linux-kernel

On Sat, 2 Dec 2000, hugang wrote:

> Hello all:
> 	
> old    ---->     points = p->mm->total_vm;
>        
> change to --->   points = p->pid;

Ummm, what exactly do you want to achieve with this?

> before change it ,kernel will kill some pid, to change it kernel
> will kill hello(bash).

Before the change, the kernel will try to kill a BIG process
(the obvious suspect for a memory leak). After the change,
the kernel will kill an almost random process ...

regards,

Rik
--
Hollywood goes for world dumbination,
	Trailer at 11.

		http://www.surriel.com/
http://www.conectiva.com/	http://distro.conectiva.com.br/

-
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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Path: for oom_kill.c
  2000-12-04 16:57   ` Rik van Riel
@ 2000-12-04 17:52     ` Jeff Epler
  0 siblings, 0 replies; 6+ messages in thread
From: Jeff Epler @ 2000-12-04 17:52 UTC (permalink / raw)
  To: linux-kernel

On Mon, Dec 04, 2000 at 02:57:34PM -0200, Rik van Riel wrote:
> On Sat, 2 Dec 2000, hugang wrote:
> 
> > Hello all:
> > 	
> > old    ---->     points = p->mm->total_vm;
> >        
> > change to --->   points = p->pid;
> 
> Ummm, what exactly do you want to achieve with this?

I suspect that hugang whishes to kill the newest process.  However,
this will not work after PID wrap.

Jeff
-
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/

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2000-12-04 18:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2000-11-07 16:19 [PATCH] protect processes from OOM killer Chris Swiedler
2000-11-07 20:47 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox