From: Dan Kegel <dank@kegel.com>
To: "Jörn Engel" <joern@wohnheim.fh-wedel.de>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Andrea VM changes
Date: Sun, 31 Aug 2003 09:19:35 -0700 [thread overview]
Message-ID: <3F522017.2060703@kegel.com> (raw)
In-Reply-To: <20030831154827.GE30196@wohnheim.fh-wedel.de>
Jörn Engel wrote:
> On Sun, 31 August 2003 08:51:55 -0700, Dan Kegel wrote:
>
>>In the test-and-measurement system I'm developing,
>>it turned out the sanest thing to do with OOM conditions
>>was to consider them user errors, and to handle them
>>by dumping memory usage info about processes and slab caches,
>>then halt. It's been very helpful because it turns flaky
>>conditions into rock-solid failures. Too bad this drastic
>>approach isn't appropriate for general use.
>
>
> Sound interesting. Can you send a patch for the interested and
> unafraid?
This is against 2.4.21 or so.
--- mm.old/oom_kill.c Mon Apr 28 17:23:19 2003
+++ mm/oom_kill.c Mon Apr 28 20:22:23 2003
@@ -20,9 +20,13 @@
#include <linux/swap.h>
#include <linux/swapctl.h>
#include <linux/timex.h>
+#include <asm/uaccess.h>
/* #define DEBUG */
+#define CONFIG_OOM_HALT
+#ifndef CONFIG_OOM_HALT
+
/**
* int_sqrt - oom_kill.c internal function, rough approximation to sqrt
* @x: integer of which to calculate the sqrt
@@ -193,6 +197,62 @@
return;
}
+#else
+
+/**
+ * oom_halt - log out of memory condition, then halt system.
+ *
+ * For embedded systems which can't tolerate the chance that
+ * the oom killer will kill the wrong process, and would rather
+ * simply log the event in detail and halt.
+ */
+static void
+oom_halt(void)
+{
+ struct task_struct *p;
+ struct file *file;
+ int ret;
+
+ printk(KERN_EMERG "oom: Out of memory!\n");
+
+ printk(KERN_EMERG "oom: VM and RSS in KB, pid, and mm ptr for each task:\n");
+ read_lock(&tasklist_lock);
+ for_each_task(p) {
+ if (p->mm)
+ printk(KERN_EMERG "oom> vm %5d rss %5d pid %5d mm %p (%s)\n",
+ p->mm->total_vm * (PAGE_SIZE / 1024),
+ p->mm->rss * (PAGE_SIZE / 1024), p->pid, p->mm, p->comm);
+ }
+ read_unlock(&tasklist_lock);
+
+ file = filp_open("/proc/slabinfo", O_RDONLY, 0);
+ if (IS_ERR(file) || !file->f_op || !file->f_op->read)
+ goto out;
+ printk(KERN_EMERG "oom: Contents of /proc/slabinfo:\n");
+ do {
+ char buf[128];
+ int pos;
+ mm_segment_t fs = get_fs();
+ /* read one line */
+ for (pos = 0; pos < sizeof (buf); pos++) {
+ set_fs(KERNEL_DS);
+ ret = file->f_op->read(file, buf + pos, 1, &file->f_pos);
+ set_fs(fs);
+ if (ret != 1 || buf[pos] == '\n')
+ break;
+ }
+ buf[pos] = 0;
+ printk(KERN_EMERG "oom> %s\n", buf);
+ } while (ret == 1);
+ /* filp_close(file, NULL); */
+out:
+ printk(KERN_EMERG "oom: Halting.\n");
+ cli();
+ machine_halt();
+}
+
+#endif
+
/**
* out_of_memory - is the system out of memory?
*/
@@ -237,7 +297,11 @@
/*
* Ok, really out of memory. Kill something.
*/
lastkill = now;
+#ifdef CONFIG_OOM_HALT
+ oom_halt();
+#else
oom_kill();
+#endif
reset:
first = now;
--
Dan Kegel
http://www.kegel.com
http://counter.li.org/cgi-bin/runscript/display-person.cgi?user=78045
next prev parent reply other threads:[~2003-08-31 16:00 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-08-31 15:51 Andrea VM changes Dan Kegel
2003-08-31 15:48 ` Jörn Engel
2003-08-31 16:19 ` Dan Kegel [this message]
2003-08-31 19:08 ` Jonathan Lundell
2003-08-31 19:22 ` Chris Frey
2003-08-31 23:42 ` Jamie Lokier
2003-09-01 11:47 ` Alan Cox
[not found] <Pine.LNX.4.44.0308311353170.15412-100000@logos.cnet>
2003-09-01 17:27 ` Marcelo Tosatti
2003-09-01 17:50 ` Andrea Arcangeli
[not found] <qL3q.1Pm.3@gated-at.bofh.it>
[not found] ` <qQ37.2q0.9@gated-at.bofh.it>
2003-09-01 9:15 ` Ihar 'Philips' Filipau
-- strict thread matches above, loose matches on Subject: below --
2003-09-01 1:02 Dan Kegel
2003-09-01 6:03 ` Rik van Riel
2003-08-31 17:34 Marcelo Tosatti
2003-08-31 17:34 Marcelo Tosatti
2003-08-31 22:46 ` Andrea Arcangeli
2003-09-01 6:01 ` Rik van Riel
2003-09-01 15:54 ` Andrea Arcangeli
2003-08-30 15:50 Marcelo Tosatti
2003-08-30 19:11 ` Marcelo Tosatti
2003-08-30 19:21 ` Marcelo Tosatti
2003-08-30 23:19 ` Andrea Arcangeli
2003-08-30 23:30 ` Marcelo Tosatti
2003-08-30 23:57 ` Andrea Arcangeli
2003-08-31 14:10 ` Alan Cox
2003-08-31 14:59 ` Andrea Arcangeli
2003-08-31 15:29 ` Alan Cox
2003-08-31 15:59 ` Andrea Arcangeli
2003-09-15 5:16 ` Greg Stark
2003-09-15 10:47 ` Andrea Arcangeli
2003-08-31 11:50 ` Matthias Andree
2003-09-01 19:52 ` Mike Fedyk
2003-09-01 17:59 ` Andrea Arcangeli
2003-08-30 15:13 Marcelo Tosatti
2003-08-30 15:41 ` Andrea Arcangeli
2003-09-01 18:26 ` Marcelo Tosatti
2003-09-01 18:36 ` Andrea Arcangeli
2003-09-01 19:00 ` Marcelo Tosatti
2003-09-01 19:05 ` Andrea Arcangeli
2003-09-02 20:51 ` Marcelo Tosatti
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=3F522017.2060703@kegel.com \
--to=dank@kegel.com \
--cc=joern@wohnheim.fh-wedel.de \
--cc=linux-kernel@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.