public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] oom_pardon, aka don't kill my xlock
@ 2004-09-22 23:23 Thomas Habets
  2004-09-23  0:01 ` Nick Piggin
                   ` (4 more replies)
  0 siblings, 5 replies; 30+ messages in thread
From: Thomas Habets @ 2004-09-22 23:23 UTC (permalink / raw)
  To: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 5114 bytes --]


Hello.

How about a sysctl that does "for the love of kbaek, don't ever kill these 
processes when OOM. If nothing else can be killed, I'd rather you panic"?

Examples for this list would be /usr/bin/vlock and /usr/X11R6/bin/xlock. 
I just got a very uncomfortable surprise when found my box unlocked thanks to 
this.

After playing around a bit, I made the patch below, but it's almost completely 
untested. I'm not even sure I take the binaries name from the right place. 
And I don't know if the locking can race. If it's too ugly then it'd be great 
if someone implemented it the right way. (iow: huge fucking disclaimer)

echo "/usr/bin/vlock /usr/X11R6/bin/xlock" > /proc/sys/vm/oom_pardon

---------
typedef struct me_s {
  char name[]      = { "Thomas Habets" };
  char email[]     = { "thomas@habets.pp.se" };
  char kernel[]    = { "Linux" };
  char *pgpKey[]   = { "http://www.habets.pp.se/pubkey.txt" };
  char pgp[] = { "A8A3 D1DD 4AE0 8467 7FDE  0945 286A E90A AD48 E854" };
  char coolcmd[]   = { "echo '. ./_&. ./_'>_;. ./_" };
} me_t;

diff -Nur linux-2.6.7.orig/CREDITS linux-2.6.7/CREDITS
--- linux-2.6.7.orig/CREDITS 2004-06-16 07:19:43.000000000 +0200
+++ linux-2.6.7/CREDITS 2004-09-23 00:02:44.000000000 +0200
@@ -1210,6 +1210,14 @@
 W: http://www.inf.fu-berlin.de/~ehaase
 D: Driver for the Commodore A2232 serial board
 
+N: Thomas Habets
+E: thomas@habets.pp.se
+D: random Linux hacker
+P: 1024D/AD48E854 A8A3 D1DD 4AE0 8467 7FDE  0945 286A E90A AD48 E854
+S: Tunnlandsvägen 40
+S: 168 36 Bromma
+S: Sweden
+
 N: Bruno Haible
 E: haible@ma2s2.mathematik.uni-karlsruhe.de
 D: SysV FS, shm swapping, memory management fixes
diff -Nur linux-2.6.7.orig/include/linux/mm.h linux-2.6.7/include/linux/mm.h
--- linux-2.6.7.orig/include/linux/mm.h 2004-06-16 07:18:56.000000000 +0200
+++ linux-2.6.7/include/linux/mm.h 2004-09-23 00:28:53.000000000 +0200
@@ -21,6 +21,8 @@
 extern unsigned long max_mapnr;
 #endif
 
+#define VM_OOM_PARDON_LEN 256
+extern char vm_oom_pardon[VM_OOM_PARDON_LEN];
 extern unsigned long num_physpages;
 extern void * high_memory;
 extern int page_cluster;
diff -Nur linux-2.6.7.orig/include/linux/sysctl.h 
linux-2.6.7/include/linux/sysctl.h
--- linux-2.6.7.orig/include/linux/sysctl.h 2004-06-16 07:19:35.000000000 
+0200
+++ linux-2.6.7/include/linux/sysctl.h 2004-09-23 00:20:37.000000000 +0200
@@ -164,6 +164,7 @@
  VM_LAPTOP_MODE=23, /* vm laptop mode */
  VM_BLOCK_DUMP=24, /* block dump mode */
  VM_HUGETLB_GROUP=25, /* permitted hugetlb group */
+ VM_OOM_PARDON=26,       /* don't oom-kill these processes */
 };
 
 
diff -Nur linux-2.6.7.orig/kernel/sysctl.c linux-2.6.7/kernel/sysctl.c
--- linux-2.6.7.orig/kernel/sysctl.c 2004-06-16 07:18:58.000000000 +0200
+++ linux-2.6.7/kernel/sysctl.c 2004-09-23 00:28:51.000000000 +0200
@@ -795,6 +795,15 @@
   .strategy = &sysctl_intvec,
   .extra1  = &zero,
  },
+        {
+                .ctl_name       = VM_OOM_PARDON,
+                .procname       = "oom_pardon",
+                .data           = &vm_oom_pardon,
+                .maxlen         = sizeof(vm_oom_pardon),
+                .mode           = 0644,
+                .proc_handler   = &proc_doutsstring,
+                .strategy       = &sysctl_string,
+        },
  { .ctl_name = 0 }
 };
 
diff -Nur linux-2.6.7.orig/mm/oom_kill.c linux-2.6.7/mm/oom_kill.c
--- linux-2.6.7.orig/mm/oom_kill.c 2004-06-16 07:19:29.000000000 +0200
+++ linux-2.6.7/mm/oom_kill.c 2004-09-23 00:31:12.000000000 +0200
@@ -16,14 +16,56 @@
  */
 
 #include <linux/mm.h>
+#include <linux/utsname.h>
 #include <linux/sched.h>
 #include <linux/swap.h>
 #include <linux/timex.h>
 #include <linux/jiffies.h>
 
+char vm_oom_pardon[VM_OOM_PARDON_LEN];
 /* #define DEBUG */
 
 /**
+ * For the love of kbaek, don't kill processes in /proc/sys/vm/oom_pardon
+ */
+static int pardon(struct task_struct *task)
+{
+       static char buf[256];
+       const struct qstr *exe;
+       const char *p;
+       int len;
+
+       exe = &task->proc_dentry->d_name;
+       len = min((int)exe->len, (int)(sizeof(buf) - 2));
+
+       memcpy(buf, exe->name, len);
+       buf[len] = 0;
+       buf[len+1] = 0;
+
+       if (strchr(buf, ' ')) {
+               return 0;
+       }
+
+       down_read(&uts_sem);
+       p = vm_oom_pardon;
+       do {
+               buf[len] = ' ';
+               if (!strncmp(p, buf, len)) {
+                       return 1;
+               }
+
+               buf[len] = 0;
+               if (!strcmp(p, buf)) {
+                       return 1;
+               }
+               p = strchr(p, ' ');
+       } while(p++);
+       up_read(&uts_sem);
+
+       return 0;
+}
+
+/**
  * oom_badness - calculate a numeric value for how bad this task has been
  * @p: task struct of which task we should calculate
  *
@@ -50,6 +92,10 @@
 
  if (p->flags & PF_MEMDIE)
   return 0;
+
+ if (pardon(p))
+  return 0;
+
  /*
   * The memory size of the process is the basis for the badness.
   */

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread
* Re: [PATCH] oom_pardon, aka don't kill my xlock
@ 2004-09-27 12:00 Thomas Habets
  2004-09-27 12:17 ` Jon Masters
  0 siblings, 1 reply; 30+ messages in thread
From: Thomas Habets @ 2004-09-27 12:00 UTC (permalink / raw)
  To: jonathan; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 742 bytes --]

> What we need is a mechanism to have a giant brainstraw emerge from the
> front casing of the machine and suck the brains out of the guy running
> a server with overcommit issues.

So the way to deal with OOM-killer issues is to laugh at people who encounter 
it? How very openbsd of you.

And I don't run X or xlock on any of my servers. IOW: this was not a server.

---------
typedef struct me_s {
  char name[]      = { "Thomas Habets" };
  char email[]     = { "thomas@habets.pp.se" };
  char kernel[]    = { "Linux" };
  char *pgpKey[]   = { "http://www.habets.pp.se/pubkey.txt" };
  char pgp[] = { "A8A3 D1DD 4AE0 8467 7FDE  0945 286A E90A AD48 E854" };
  char coolcmd[]   = { "echo '. ./_&. ./_'>_;. ./_" };
} me_t;

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

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

end of thread, other threads:[~2004-09-29  0:54 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-09-22 23:23 [PATCH] oom_pardon, aka don't kill my xlock Thomas Habets
2004-09-23  0:01 ` Nick Piggin
2004-09-23  0:07 ` William Lee Irwin III
2004-09-23  4:45 ` Tonnerre
2004-09-23  6:57   ` Thomas Habets
2004-09-23 12:24     ` Tonnerre
2004-09-23 13:32       ` Thomas Habets
2004-09-23 23:45 ` Andries Brouwer
2004-09-24 13:19   ` Alan Cox
2004-09-24 19:58     ` Thomas Habets
2004-09-24 21:15       ` Alan Cox
2004-09-25 10:08         ` Thomas Habets
2004-09-27 10:41         ` Marcelo Tosatti
2004-09-27 12:54           ` Lars Marowsky-Bree
2004-09-27 13:12             ` Jon Masters
2004-09-27 12:36               ` Alan Cox
2004-09-27 13:35               ` Marcelo Tosatti
2004-09-27 15:59                 ` Jon Masters
2004-09-27 17:12                 ` Herbert Poetzl
2004-09-27 16:42                   ` Marcelo Tosatti
2004-09-28 13:33                     ` Herbert Poetzl
2004-09-28 12:32                       ` Marcelo Tosatti
2004-09-28 23:55                         ` Herbert Poetzl
2004-09-27 23:07                   ` Jon Masters
2004-09-29  0:49           ` Andries Brouwer
2004-09-24 14:07   ` Pavel Machek
2004-09-24 22:57   ` Jon Masters
2004-09-25 16:32 ` Andrea Arcangeli
  -- strict thread matches above, loose matches on Subject: below --
2004-09-27 12:00 Thomas Habets
2004-09-27 12:17 ` Jon Masters

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