more patches
[linux-2.6.git] / linux-2.6-540-oom-kill.patch
1 diff --git a/mm/oom_panic.c b/mm/oom_panic.c
2 new file mode 100644
3 index 0000000..4230ae5
4 --- /dev/null
5 +++ b/mm/oom_panic.c
6 @@ -0,0 +1,51 @@
7 +/* 
8 + * Just panic() instead of the default behavior of selecting processes
9 + * for death.
10 + *
11 + * Based on
12 + * Modular OOM handlers for 2.6.4 (C) 2003,2004 Tvrtko A. Ursulin
13 + * and
14 + * linux/mm/oom_kill.c (C) 1998,2000 Rik van Riel.
15 + *
16 + * Mark Huang <mlhuang@cs.princeton.edu>
17 + *
18 + * $Id: oom_panic.c,v 1.1 2004/10/01 17:54:48 mlhuang Exp $
19 + */
20 +
21 +#include <linux/mm.h>
22 +#include <linux/sched.h>
23 +#include <linux/swap.h>
24 +
25 +/**
26 + * out_of_memory - is the system out of memory?
27 + */
28 +void out_of_memory(int gfp_mask)
29 +{
30 +       /*
31 +        * oom_lock protects out_of_memory()'s static variables.
32 +        * It's a global lock; this is not performance-critical.
33 +        */
34 +       static spinlock_t oom_lock = SPIN_LOCK_UNLOCKED;
35 +       static unsigned long count;
36 +
37 +       spin_lock(&oom_lock);
38 +
39 +       /*
40 +        * If we have gotten only a few failures,
41 +        * we're not really oom. 
42 +        */
43 +       if (++count < 10)
44 +               goto out_unlock;
45 +
46 +       /*
47 +        * Ok, really out of memory. Panic.
48 +        */
49 +
50 +       printk("oom-killer: gfp_mask=0x%x\n", gfp_mask);
51 +       show_free_areas();
52 +
53 +       panic("Out Of Memory");
54 +
55 +out_unlock:
56 +       spin_unlock(&oom_lock);
57 +}
58
59 commit 2e378e38451e7b3929110dc6f13d48587a169afe
60 Author: root <root@rhel6.(none)>
61 Date:   Thu Apr 29 10:08:21 2010 -0400
62
63     linux-2.6-540-oom-kill.patch
64
65 diff --git a/init/Kconfig b/init/Kconfig
66 index 87fe242..cc782ea 100644
67 --- a/init/Kconfig
68 +++ b/init/Kconfig
69 @@ -548,6 +548,23 @@ config CGROUP_DEVICE
70           Provides a cgroup implementing whitelists for devices which
71           a process in the cgroup can mknod or open.
72  
73 +config OOM_PANIC
74 +       bool "OOM Panic"
75 +       default y
76 +       ---help---
77 +         This option enables panic() to be called when a system is out of
78 +         memory. This feature along with /proc/sys/kernel/panic allows a
79 +         different behavior on out-of-memory conditions when the standard
80 +         behavior (killing processes in an attempt to recover) does not
81 +         make sense.
82 +
83 +         If unsure, say N.
84 +
85 +config OOM_KILL
86 +       bool
87 +       depends on !OOM_PANIC
88 +       default y
89 +
90  config CPUSETS
91         bool "Cpuset support"
92         depends on CGROUPS
93 diff --git a/mm/oom_kill.c b/mm/oom_kill.c
94 index e0ba2e1..bb123cf 100644
95 --- a/mm/oom_kill.c
96 +++ b/mm/oom_kill.c
97 @@ -209,6 +209,11 @@ unsigned long badness(struct task_struct *p, unsigned long uptime)
98         return points;
99  }
100  
101 +#if defined(CONFIG_OOM_PANIC) && defined(CONFIG_OOM_KILLER)
102 +#warning Only define OOM_PANIC or OOM_KILLER; not both
103 +#endif
104 +
105 +#ifdef CONFIG_OOM_KILLER
106  /*
107   * Determine the type of allocation constraint.
108   */
109 @@ -479,6 +484,7 @@ retry:
110  out:
111         read_unlock(&tasklist_lock);
112  }
113 +
114  #endif
115  
116  static BLOCKING_NOTIFIER_HEAD(oom_notify_list);
117 @@ -544,6 +550,7 @@ void clear_zonelist_oom(struct zonelist *zonelist, gfp_t gfp_mask)
118         }
119         spin_unlock(&zone_scan_lock);
120  }
121 +EXPORT_SYMBOL_GPL(clear_zonelist_oom);
122  
123  long vs_oom_action(unsigned int);
124  
125 @@ -675,3 +682,47 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask, int order)
126         if (!test_thread_flag(TIF_MEMDIE))
127                 schedule_timeout_uninterruptible(1);
128  }
129 +#endif /* CONFIG_OOM_KILLER */
130 +
131 +#ifdef CONFIG_OOM_PANIC
132 +/**
133 + * out_of_memory - panic if the system out of memory?
134 + */
135 +void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask, int order)
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 +               /*
152 +                * Ok, really out of memory. Panic.
153 +                */
154 +
155 +               printk("oom-killer: gfp_mask=0x%x\n", gfp_mask);
156 +               show_free_areas();
157 +
158 +               panic("Out Of Memory");
159 +       }
160 +       spin_unlock(&oom_lock);
161 +}
162 +
163 +#ifdef CONFIG_CGROUP_MEM_RES_CTLR
164 +void mem_cgroup_out_of_memory(struct mem_cgroup *mem, gfp_t gfp_mask)
165 +{
166 +       cgroup_lock();
167 +       panic("Memory cgroup out Of Memory");
168 +       cgroup_unlock();
169 +}
170 +
171 +#endif
172 +#endif /*  CONFIG_OOM_PANIC */
173 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
174 index 4b70600..4830639 100644
175 --- a/mm/page_alloc.c
176 +++ b/mm/page_alloc.c
177 @@ -1642,11 +1642,13 @@ __alloc_pages_may_oom(gfp_t gfp_mask, unsigned int order,
178  {
179         struct page *page;
180  
181 +#ifdef CONFIG_OOM_KILLER
182         /* Acquire the OOM killer lock for the zones in zonelist */
183         if (!try_set_zone_oom(zonelist, gfp_mask)) {
184                 schedule_timeout_uninterruptible(1);
185                 return NULL;
186         }
187 +#endif
188  
189         /*
190          * Go through the zonelist yet one more time, keep very high watermark
191 @@ -1668,7 +1670,9 @@ __alloc_pages_may_oom(gfp_t gfp_mask, unsigned int order,
192         out_of_memory(zonelist, gfp_mask, order);
193  
194  out:
195 +#ifdef CONFIG_OOM_KILLER
196         clear_zonelist_oom(zonelist, gfp_mask);
197 +#endif
198         return page;
199  }
200