Bump tag level
[linux-2.6.git] / linux-2.6-540-oom-kill.patch
1 diff -NurpP --exclude '*.orig' --exclude '*.rej' linux-2.6.27.10-vs2.3.x-P/init/Kconfig linux-2.6.27.10-vs2.3.x-P540/init/Kconfig
2 --- linux-2.6.27.10-vs2.3.x-P/init/Kconfig      2008-10-13 14:52:09.000000000 +0200
3 +++ linux-2.6.27.10-vs2.3.x-P540/init/Kconfig   2009-01-12 01:18:23.000000000 +0100
4 @@ -306,6 +306,23 @@ config CGROUP_DEVICE
5           Provides a cgroup implementing whitelists for devices which
6           a process in the cgroup can mknod or open.
7  
8 +config OOM_PANIC
9 +       bool "OOM Panic"
10 +       default y
11 +       ---help---
12 +         This option enables panic() to be called when a system is out of
13 +         memory. This feature along with /proc/sys/kernel/panic allows a
14 +         different behavior on out-of-memory conditions when the standard
15 +         behavior (killing processes in an attempt to recover) does not
16 +         make sense.
17 +
18 +         If unsure, say N.
19 +
20 +config OOM_KILL
21 +       bool
22 +       depends on !OOM_PANIC
23 +       default y
24 +
25  config CPUSETS
26         bool "Cpuset support"
27         depends on SMP && CGROUPS
28 diff -NurpP --exclude '*.orig' --exclude '*.rej' linux-2.6.27.10-vs2.3.x-P/mm/oom_kill.c linux-2.6.27.10-vs2.3.x-P540/mm/oom_kill.c
29 --- linux-2.6.27.10-vs2.3.x-P/mm/oom_kill.c     2008-10-13 14:54:20.000000000 +0200
30 +++ linux-2.6.27.10-vs2.3.x-P540/mm/oom_kill.c  2009-01-12 01:18:23.000000000 +0100
31 @@ -176,6 +176,11 @@ unsigned long badness(struct task_struct
32         return points;
33  }
34  
35 +#if defined(CONFIG_OOM_PANIC) && defined(CONFIG_OOM_KILLER)
36 +#warning Only define OOM_PANIC or OOM_KILLER; not both
37 +#endif
38 +
39 +#ifdef CONFIG_OOM_KILLER
40  /*
41   * Determine the type of allocation constraint.
42   */
43 @@ -597,3 +602,37 @@ out:
44         if (!test_thread_flag(TIF_MEMDIE))
45                 schedule_timeout_uninterruptible(1);
46  }
47 +#endif /* CONFIG_OOM_KILLER */
48 +
49 +#ifdef CONFIG_OOM_PANIC
50 +/**
51 + * out_of_memory - panic if the system out of memory?
52 + */
53 +void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask, int order)
54 +{
55 +       /*
56 +        * oom_lock protects out_of_memory()'s static variables.
57 +        * It's a global lock; this is not performance-critical.
58 +        */
59 +       static spinlock_t oom_lock = SPIN_LOCK_UNLOCKED;
60 +       static unsigned long count;
61 +
62 +       spin_lock(&oom_lock);
63 +
64 +       /*
65 +        * If we have gotten only a few failures,
66 +        * we're not really oom. 
67 +        */
68 +       if (++count >= 10) {
69 +               /*
70 +                * Ok, really out of memory. Panic.
71 +                */
72 +
73 +               printk("oom-killer: gfp_mask=0x%x\n", gfp_mask);
74 +               show_free_areas();
75 +
76 +               panic("Out Of Memory");
77 +       }
78 +       spin_unlock(&oom_lock);
79 +}
80 +#endif /*  CONFIG_OOM_PANIC */
81 diff -NurpP --exclude '*.orig' --exclude '*.rej' linux-2.6.27.10-vs2.3.x-P/mm/oom_panic.c linux-2.6.27.10-vs2.3.x-P540/mm/oom_panic.c
82 --- linux-2.6.27.10-vs2.3.x-P/mm/oom_panic.c    1970-01-01 01:00:00.000000000 +0100
83 +++ linux-2.6.27.10-vs2.3.x-P540/mm/oom_panic.c 2009-01-12 01:18:23.000000000 +0100
84 @@ -0,0 +1,51 @@
85 +/* 
86 + * Just panic() instead of the default behavior of selecting processes
87 + * for death.
88 + *
89 + * Based on
90 + * Modular OOM handlers for 2.6.4 (C) 2003,2004 Tvrtko A. Ursulin
91 + * and
92 + * linux/mm/oom_kill.c (C) 1998,2000 Rik van Riel.
93 + *
94 + * Mark Huang <mlhuang@cs.princeton.edu>
95 + *
96 + * $Id: oom_panic.c,v 1.1 2004/10/01 17:54:48 mlhuang Exp $
97 + */
98 +
99 +#include <linux/mm.h>
100 +#include <linux/sched.h>
101 +#include <linux/swap.h>
102 +
103 +/**
104 + * out_of_memory - is the system out of memory?
105 + */
106 +void out_of_memory(int gfp_mask)
107 +{
108 +       /*
109 +        * oom_lock protects out_of_memory()'s static variables.
110 +        * It's a global lock; this is not performance-critical.
111 +        */
112 +       static spinlock_t oom_lock = SPIN_LOCK_UNLOCKED;
113 +       static unsigned long count;
114 +
115 +       spin_lock(&oom_lock);
116 +
117 +       /*
118 +        * If we have gotten only a few failures,
119 +        * we're not really oom. 
120 +        */
121 +       if (++count < 10)
122 +               goto out_unlock;
123 +
124 +       /*
125 +        * Ok, really out of memory. Panic.
126 +        */
127 +
128 +       printk("oom-killer: gfp_mask=0x%x\n", gfp_mask);
129 +       show_free_areas();
130 +
131 +       panic("Out Of Memory");
132 +
133 +out_unlock:
134 +       spin_unlock(&oom_lock);
135 +}
136
137 ; fixup
138 diff -NurpP --exclude '*.orig' --exclude '*.rej' linux-2.6.27.10-vs2.3.x-PS-02.0/mm/oom_kill.c linux-2.6.27.10-vs2.3.x-PS-02.1/mm/oom_kill.c
139 --- linux-2.6.27.10-vs2.3.x-PS-02.0/mm/oom_kill.c       2009-01-25 02:29:32.000000000 +0100
140 +++ linux-2.6.27.10-vs2.3.x-PS-02.1/mm/oom_kill.c       2009-01-25 02:05:07.000000000 +0100
141 @@ -454,6 +454,7 @@ out:
142         read_unlock(&tasklist_lock);
143         cgroup_unlock();
144  }
145 +
146  #endif
147  
148  static BLOCKING_NOTIFIER_HEAD(oom_notify_list);
149 @@ -519,6 +520,7 @@ void clear_zonelist_oom(struct zonelist 
150         }
151         spin_unlock(&zone_scan_mutex);
152  }
153 +EXPORT_SYMBOL_GPL(clear_zonelist_oom);
154  
155  /**
156   * out_of_memory - kill the "best" process when we run out of memory
157 @@ -635,4 +637,14 @@ void out_of_memory(struct zonelist *zone
158         }
159         spin_unlock(&oom_lock);
160  }
161 +
162 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
163 +void mem_cgroup_out_of_memory(struct mem_cgroup *mem, gfp_t gfp_mask)
164 +{
165 +       cgroup_lock();
166 +       panic("Memory cgroup out Of Memory");
167 +       cgroup_unlock();
168 +}
169 +
170 +#endif
171  #endif /*  CONFIG_OOM_PANIC */
172 diff -NurpP --exclude '*.orig' --exclude '*.rej' linux-2.6.27.10-vs2.3.x-PS-02.0/mm/page_alloc.c linux-2.6.27.10-vs2.3.x-PS-02.1/mm/page_alloc.c
173 --- linux-2.6.27.10-vs2.3.x-PS-02.0/mm/page_alloc.c     2008-12-19 12:09:14.000000000 +0100
174 +++ linux-2.6.27.10-vs2.3.x-PS-02.1/mm/page_alloc.c     2009-01-25 00:37:42.000000000 +0100
175 @@ -1583,11 +1583,12 @@ nofail_alloc:
176                 if (page)
177                         goto got_pg;
178         } else if ((gfp_mask & __GFP_FS) && !(gfp_mask & __GFP_NORETRY)) {
179 +#ifdef CONFIG_OOM_KILLER
180                 if (!try_set_zone_oom(zonelist, gfp_mask)) {
181                         schedule_timeout_uninterruptible(1);
182                         goto restart;
183                 }
184 -
185 +#endif
186                 /*
187                  * Go through the zonelist yet one more time, keep
188                  * very high watermark here, this is only to catch
189 @@ -1598,18 +1599,24 @@ nofail_alloc:
190                         order, zonelist, high_zoneidx,
191                         ALLOC_WMARK_HIGH|ALLOC_CPUSET);
192                 if (page) {
193 +#ifdef CONFIG_OOM_KILLER
194                         clear_zonelist_oom(zonelist, gfp_mask);
195 +#endif
196                         goto got_pg;
197                 }
198  
199                 /* The OOM killer will not help higher order allocs so fail */
200                 if (order > PAGE_ALLOC_COSTLY_ORDER) {
201 +#ifdef CONFIG_OOM_KILLER
202                         clear_zonelist_oom(zonelist, gfp_mask);
203 +#endif
204                         goto nopage;
205                 }
206  
207                 out_of_memory(zonelist, gfp_mask, order);
208 +#ifdef CONFIG_OOM_KILLER
209                 clear_zonelist_oom(zonelist, gfp_mask);
210 +#endif
211                 goto restart;
212         }
213