1 diff --git a/mm/oom_panic.c b/mm/oom_panic.c
8 + * Just panic() instead of the default behavior of selecting processes
12 + * Modular OOM handlers for 2.6.4 (C) 2003,2004 Tvrtko A. Ursulin
14 + * linux/mm/oom_kill.c (C) 1998,2000 Rik van Riel.
16 + * Mark Huang <mlhuang@cs.princeton.edu>
18 + * $Id: oom_panic.c,v 1.1 2004/10/01 17:54:48 mlhuang Exp $
21 +#include <linux/mm.h>
22 +#include <linux/sched.h>
23 +#include <linux/swap.h>
26 + * out_of_memory - is the system out of memory?
28 +void out_of_memory(int gfp_mask)
31 + * oom_lock protects out_of_memory()'s static variables.
32 + * It's a global lock; this is not performance-critical.
34 + static spinlock_t oom_lock = SPIN_LOCK_UNLOCKED;
35 + static unsigned long count;
37 + spin_lock(&oom_lock);
40 + * If we have gotten only a few failures,
41 + * we're not really oom.
47 + * Ok, really out of memory. Panic.
50 + printk("oom-killer: gfp_mask=0x%x\n", gfp_mask);
53 + panic("Out Of Memory");
56 + spin_unlock(&oom_lock);
58 diff --git a/init/Kconfig b/init/Kconfig
59 index 87fe242..cc782ea 100644
62 @@ -548,6 +548,23 @@ config CGROUP_DEVICE
63 Provides a cgroup implementing whitelists for devices which
64 a process in the cgroup can mknod or open.
70 + This option enables panic() to be called when a system is out of
71 + memory. This feature along with /proc/sys/kernel/panic allows a
72 + different behavior on out-of-memory conditions when the standard
73 + behavior (killing processes in an attempt to recover) does not
80 + depends on !OOM_PANIC
86 diff --git a/mm/oom_kill.c b/mm/oom_kill.c
87 index e0ba2e1..bb123cf 100644
90 @@ -209,6 +209,11 @@ unsigned long badness(struct task_struct *p, unsigned long uptime)
94 +#if defined(CONFIG_OOM_PANIC) && defined(CONFIG_OOM_KILLER)
95 +#warning Only define OOM_PANIC or OOM_KILLER; not both
98 +#ifdef CONFIG_OOM_KILLER
100 * Determine the type of allocation constraint.
102 @@ -479,6 +484,7 @@ retry:
104 read_unlock(&tasklist_lock);
109 static BLOCKING_NOTIFIER_HEAD(oom_notify_list);
110 @@ -544,6 +550,7 @@ void clear_zonelist_oom(struct zonelist *zonelist, gfp_t gfp_mask)
112 spin_unlock(&zone_scan_lock);
114 +EXPORT_SYMBOL_GPL(clear_zonelist_oom);
116 long vs_oom_action(unsigned int);
118 @@ -675,3 +682,47 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask, int order)
119 if (!test_thread_flag(TIF_MEMDIE))
120 schedule_timeout_uninterruptible(1);
122 +#endif /* CONFIG_OOM_KILLER */
124 +#ifdef CONFIG_OOM_PANIC
126 + * out_of_memory - panic if the system out of memory?
128 +void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask, int order)
131 + * oom_lock protects out_of_memory()'s static variables.
132 + * It's a global lock; this is not performance-critical.
134 + static spinlock_t oom_lock = SPIN_LOCK_UNLOCKED;
135 + static unsigned long count;
137 + spin_lock(&oom_lock);
140 + * If we have gotten only a few failures,
141 + * we're not really oom.
143 + if (++count >= 10) {
145 + * Ok, really out of memory. Panic.
148 + printk("oom-killer: gfp_mask=0x%x\n", gfp_mask);
151 + panic("Out Of Memory");
153 + spin_unlock(&oom_lock);
156 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
157 +void mem_cgroup_out_of_memory(struct mem_cgroup *mem, gfp_t gfp_mask)
160 + panic("Memory cgroup out Of Memory");
165 +#endif /* CONFIG_OOM_PANIC */
166 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
167 index 4b70600..4830639 100644
168 --- a/mm/page_alloc.c
169 +++ b/mm/page_alloc.c
170 @@ -1642,11 +1642,13 @@ __alloc_pages_may_oom(gfp_t gfp_mask, unsigned int order,
174 +#ifdef CONFIG_OOM_KILLER
175 /* Acquire the OOM killer lock for the zones in zonelist */
176 if (!try_set_zone_oom(zonelist, gfp_mask)) {
177 schedule_timeout_uninterruptible(1);
183 * Go through the zonelist yet one more time, keep very high watermark
184 @@ -1668,7 +1670,9 @@ __alloc_pages_may_oom(gfp_t gfp_mask, unsigned int order,
185 out_of_memory(zonelist, gfp_mask, order);
188 +#ifdef CONFIG_OOM_KILLER
189 clear_zonelist_oom(zonelist, gfp_mask);