1 Index: linux-2.6.27.y/init/Kconfig
2 ===================================================================
3 --- linux-2.6.27.y.orig/init/Kconfig
4 +++ linux-2.6.27.y/init/Kconfig
5 @@ -306,6 +306,23 @@ config CGROUP_DEVICE
6 Provides a cgroup implementing whitelists for devices which
7 a process in the cgroup can mknod or open.
13 + This option enables panic() to be called when a system is out of
14 + memory. This feature along with /proc/sys/kernel/panic allows a
15 + different behavior on out-of-memory conditions when the standard
16 + behavior (killing processes in an attempt to recover) does not
23 + depends on !OOM_PANIC
28 depends on SMP && CGROUPS
29 Index: linux-2.6.27.y/mm/oom_kill.c
30 ===================================================================
31 --- linux-2.6.27.y.orig/mm/oom_kill.c
32 +++ linux-2.6.27.y/mm/oom_kill.c
33 @@ -177,6 +177,11 @@ unsigned long badness(struct task_struct
37 +#if defined(CONFIG_OOM_PANIC) && defined(CONFIG_OOM_KILLER)
38 +#warning Only define OOM_PANIC or OOM_KILLER; not both
41 +#ifdef CONFIG_OOM_KILLER
43 * Determine the type of allocation constraint.
45 @@ -454,6 +459,7 @@ out:
46 read_unlock(&tasklist_lock);
52 static BLOCKING_NOTIFIER_HEAD(oom_notify_list);
53 @@ -519,6 +525,7 @@ void clear_zonelist_oom(struct zonelist
55 spin_unlock(&zone_scan_mutex);
57 +EXPORT_SYMBOL_GPL(clear_zonelist_oom);
60 * out_of_memory - kill the "best" process when we run out of memory
61 @@ -602,3 +609,47 @@ out:
62 if (!test_thread_flag(TIF_MEMDIE))
63 schedule_timeout_uninterruptible(1);
65 +#endif /* CONFIG_OOM_KILLER */
67 +#ifdef CONFIG_OOM_PANIC
69 + * out_of_memory - panic if the system out of memory?
71 +void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask, int order)
74 + * oom_lock protects out_of_memory()'s static variables.
75 + * It's a global lock; this is not performance-critical.
77 + static spinlock_t oom_lock = SPIN_LOCK_UNLOCKED;
78 + static unsigned long count;
80 + spin_lock(&oom_lock);
83 + * If we have gotten only a few failures,
84 + * we're not really oom.
86 + if (++count >= 10) {
88 + * Ok, really out of memory. Panic.
91 + printk("oom-killer: gfp_mask=0x%x\n", gfp_mask);
94 + panic("Out Of Memory");
96 + spin_unlock(&oom_lock);
99 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
100 +void mem_cgroup_out_of_memory(struct mem_cgroup *mem, gfp_t gfp_mask)
103 + panic("Memory cgroup out Of Memory");
108 +#endif /* CONFIG_OOM_PANIC */
109 Index: linux-2.6.27.y/mm/oom_panic.c
110 ===================================================================
112 +++ linux-2.6.27.y/mm/oom_panic.c
115 + * Just panic() instead of the default behavior of selecting processes
119 + * Modular OOM handlers for 2.6.4 (C) 2003,2004 Tvrtko A. Ursulin
121 + * linux/mm/oom_kill.c (C) 1998,2000 Rik van Riel.
123 + * Mark Huang <mlhuang@cs.princeton.edu>
125 + * $Id: oom_panic.c,v 1.1 2004/10/01 17:54:48 mlhuang Exp $
128 +#include <linux/mm.h>
129 +#include <linux/sched.h>
130 +#include <linux/swap.h>
133 + * out_of_memory - is the system out of memory?
135 +void out_of_memory(int gfp_mask)
138 + * oom_lock protects out_of_memory()'s static variables.
139 + * It's a global lock; this is not performance-critical.
141 + static spinlock_t oom_lock = SPIN_LOCK_UNLOCKED;
142 + static unsigned long count;
144 + spin_lock(&oom_lock);
147 + * If we have gotten only a few failures,
148 + * we're not really oom.
154 + * Ok, really out of memory. Panic.
157 + printk("oom-killer: gfp_mask=0x%x\n", gfp_mask);
160 + panic("Out Of Memory");
163 + spin_unlock(&oom_lock);
165 Index: linux-2.6.27.y/mm/page_alloc.c
166 ===================================================================
167 --- linux-2.6.27.y.orig/mm/page_alloc.c
168 +++ linux-2.6.27.y/mm/page_alloc.c
169 @@ -1588,11 +1588,12 @@ nofail_alloc:
172 } else if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY)) {
173 +#ifdef CONFIG_OOM_KILLER
174 if (!try_set_zone_oom(zonelist, gfp_mask)) {
175 schedule_timeout_uninterruptible(1);
181 * Go through the zonelist yet one more time, keep
182 * very high watermark here, this is only to catch
183 @@ -1603,18 +1604,24 @@ nofail_alloc:
184 order, zonelist, high_zoneidx,
185 ALLOC_WMARK_HIGH|ALLOC_CPUSET);
187 +#ifdef CONFIG_OOM_KILLER
188 clear_zonelist_oom(zonelist, gfp_mask);
193 /* The OOM killer will not help higher order allocs so fail */
194 if (order > PAGE_ALLOC_COSTLY_ORDER) {
195 +#ifdef CONFIG_OOM_KILLER
196 clear_zonelist_oom(zonelist, gfp_mask);
201 out_of_memory(zonelist, gfp_mask, order);
202 +#ifdef CONFIG_OOM_KILLER
203 clear_zonelist_oom(zonelist, gfp_mask);