Setting tag linux-2.6-27-38
[linux-2.6.git] / linux-2.6-540-oom-kill.patch
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.
8  
9 +config OOM_PANIC
10 +       bool "OOM Panic"
11 +       default y
12 +       ---help---
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
17 +         make sense.
18 +
19 +         If unsure, say N.
20 +
21 +config OOM_KILL
22 +       bool
23 +       depends on !OOM_PANIC
24 +       default y
25 +
26  config CPUSETS
27         bool "Cpuset support"
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
34         return points;
35  }
36  
37 +#if defined(CONFIG_OOM_PANIC) && defined(CONFIG_OOM_KILLER)
38 +#warning Only define OOM_PANIC or OOM_KILLER; not both
39 +#endif
40 +
41 +#ifdef CONFIG_OOM_KILLER
42  /*
43   * Determine the type of allocation constraint.
44   */
45 @@ -454,6 +459,7 @@ out:
46         read_unlock(&tasklist_lock);
47         cgroup_unlock();
48  }
49 +
50  #endif
51  
52  static BLOCKING_NOTIFIER_HEAD(oom_notify_list);
53 @@ -519,6 +525,7 @@ void clear_zonelist_oom(struct zonelist 
54         }
55         spin_unlock(&zone_scan_mutex);
56  }
57 +EXPORT_SYMBOL_GPL(clear_zonelist_oom);
58  
59  /**
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);
64  }
65 +#endif /* CONFIG_OOM_KILLER */
66 +
67 +#ifdef CONFIG_OOM_PANIC
68 +/**
69 + * out_of_memory - panic if the system out of memory?
70 + */
71 +void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask, int order)
72 +{
73 +       /*
74 +        * oom_lock protects out_of_memory()'s static variables.
75 +        * It's a global lock; this is not performance-critical.
76 +        */
77 +       static spinlock_t oom_lock = SPIN_LOCK_UNLOCKED;
78 +       static unsigned long count;
79 +
80 +       spin_lock(&oom_lock);
81 +
82 +       /*
83 +        * If we have gotten only a few failures,
84 +        * we're not really oom. 
85 +        */
86 +       if (++count >= 10) {
87 +               /*
88 +                * Ok, really out of memory. Panic.
89 +                */
90 +
91 +               printk("oom-killer: gfp_mask=0x%x\n", gfp_mask);
92 +               show_free_areas();
93 +
94 +               panic("Out Of Memory");
95 +       }
96 +       spin_unlock(&oom_lock);
97 +}
98 +
99 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
100 +void mem_cgroup_out_of_memory(struct mem_cgroup *mem, gfp_t gfp_mask)
101 +{
102 +       cgroup_lock();
103 +       panic("Memory cgroup out Of Memory");
104 +       cgroup_unlock();
105 +}
106 +
107 +#endif
108 +#endif /*  CONFIG_OOM_PANIC */
109 Index: linux-2.6.27.y/mm/oom_panic.c
110 ===================================================================
111 --- /dev/null
112 +++ linux-2.6.27.y/mm/oom_panic.c
113 @@ -0,0 +1,51 @@
114 +/* 
115 + * Just panic() instead of the default behavior of selecting processes
116 + * for death.
117 + *
118 + * Based on
119 + * Modular OOM handlers for 2.6.4 (C) 2003,2004 Tvrtko A. Ursulin
120 + * and
121 + * linux/mm/oom_kill.c (C) 1998,2000 Rik van Riel.
122 + *
123 + * Mark Huang <mlhuang@cs.princeton.edu>
124 + *
125 + * $Id: oom_panic.c,v 1.1 2004/10/01 17:54:48 mlhuang Exp $
126 + */
127 +
128 +#include <linux/mm.h>
129 +#include <linux/sched.h>
130 +#include <linux/swap.h>
131 +
132 +/**
133 + * out_of_memory - is the system out of memory?
134 + */
135 +void out_of_memory(int gfp_mask)
136 +{
137 +       /*
138 +        * oom_lock protects out_of_memory()'s static variables.
139 +        * It's a global lock; this is not performance-critical.
140 +        */
141 +       static spinlock_t oom_lock = SPIN_LOCK_UNLOCKED;
142 +       static unsigned long count;
143 +
144 +       spin_lock(&oom_lock);
145 +
146 +       /*
147 +        * If we have gotten only a few failures,
148 +        * we're not really oom. 
149 +        */
150 +       if (++count < 10)
151 +               goto out_unlock;
152 +
153 +       /*
154 +        * Ok, really out of memory. Panic.
155 +        */
156 +
157 +       printk("oom-killer: gfp_mask=0x%x\n", gfp_mask);
158 +       show_free_areas();
159 +
160 +       panic("Out Of Memory");
161 +
162 +out_unlock:
163 +       spin_unlock(&oom_lock);
164 +}
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:
170                 if (page)
171                         goto got_pg;
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);
176                         goto restart;
177                 }
178 -
179 +#endif
180                 /*
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);
186                 if (page) {
187 +#ifdef CONFIG_OOM_KILLER
188                         clear_zonelist_oom(zonelist, gfp_mask);
189 +#endif
190                         goto got_pg;
191                 }
192  
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);
197 +#endif
198                         goto nopage;
199                 }
200  
201                 out_of_memory(zonelist, gfp_mask, order);
202 +#ifdef CONFIG_OOM_KILLER
203                 clear_zonelist_oom(zonelist, gfp_mask);
204 +#endif
205                 goto restart;
206         }
207