Setting tag linux-2.6-22-50
[linux-2.6.git] / linux-2.6-540-oom-kill.patch
1 diff -Nurp linux-2.6.22.10-vs2.3.0.29-pl05/init/Kconfig linux-2.6.22.10-vs2.3.0.29-pl06/init/Kconfig
2 --- linux-2.6.22.10-vs2.3.0.29-pl05/init/Kconfig        2007-09-29 08:11:49.000000000 -0400
3 +++ linux-2.6.22.10-vs2.3.0.29-pl06/init/Kconfig        2007-11-14 17:09:01.000000000 -0500
4 @@ -281,6 +281,23 @@ config LOG_BUF_SHIFT
5                      13 =>  8 KB
6                      12 =>  4 KB
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
28 diff -Nurp linux-2.6.22.10-vs2.3.0.29-pl05/mm/oom_kill.c linux-2.6.22.10-vs2.3.0.29-pl06/mm/oom_kill.c
29 --- linux-2.6.22.10-vs2.3.0.29-pl05/mm/oom_kill.c       2007-10-29 21:23:59.000000000 -0400
30 +++ linux-2.6.22.10-vs2.3.0.29-pl06/mm/oom_kill.c       2007-11-14 17:09:01.000000000 -0500
31 @@ -169,6 +169,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   * Types of limitations to the nodes from which allocations may occur
42   */
43 @@ -481,3 +486,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 -Nurp linux-2.6.22.10-vs2.3.0.29-pl05/mm/oom_panic.c linux-2.6.22.10-vs2.3.0.29-pl06/mm/oom_panic.c
82 --- linux-2.6.22.10-vs2.3.0.29-pl05/mm/oom_panic.c      1969-12-31 19:00:00.000000000 -0500
83 +++ linux-2.6.22.10-vs2.3.0.29-pl06/mm/oom_panic.c      2007-11-14 17:09:01.000000000 -0500
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 +}