- Just panic() instead of the default behavior of selecting processes
authorMark Huang <mlhuang@cs.princeton.edu>
Fri, 1 Oct 2004 17:54:48 +0000 (17:54 +0000)
committerMark Huang <mlhuang@cs.princeton.edu>
Fri, 1 Oct 2004 17:54:48 +0000 (17:54 +0000)
  for death.

mm/oom_panic.c [new file with mode: 0644]

diff --git a/mm/oom_panic.c b/mm/oom_panic.c
new file mode 100644 (file)
index 0000000..b782934
--- /dev/null
@@ -0,0 +1,51 @@
+/* 
+ * Just panic() instead of the default behavior of selecting processes
+ * for death.
+ *
+ * Based on
+ * Modular OOM handlers for 2.6.4 (C) 2003,2004 Tvrtko A. Ursulin
+ * and
+ * linux/mm/oom_kill.c (C) 1998,2000 Rik van Riel.
+ *
+ * Mark Huang <mlhuang@cs.princeton.edu>
+ *
+ * $Id$
+ */
+
+#include <linux/mm.h>
+#include <linux/sched.h>
+#include <linux/swap.h>
+
+/**
+ * out_of_memory - is the system out of memory?
+ */
+void out_of_memory(int gfp_mask)
+{
+       /*
+        * oom_lock protects out_of_memory()'s static variables.
+        * It's a global lock; this is not performance-critical.
+        */
+       static spinlock_t oom_lock = SPIN_LOCK_UNLOCKED;
+       static unsigned long count;
+
+       spin_lock(&oom_lock);
+
+       /*
+        * If we have gotten only a few failures,
+        * we're not really oom. 
+        */
+       if (++count < 10)
+               goto out_unlock;
+
+       /*
+        * Ok, really out of memory. Panic.
+        */
+
+       printk("oom-killer: gfp_mask=0x%x\n", gfp_mask);
+       show_free_areas();
+
+       panic("Out Of Memory");
+
+out_unlock:
+       spin_unlock(&oom_lock);
+}