b782934acec5b693dab27cf0d361c04475954cc3
[linux-2.6.git] / mm / oom_panic.c
1 /* 
2  * Just panic() instead of the default behavior of selecting processes
3  * for death.
4  *
5  * Based on
6  * Modular OOM handlers for 2.6.4 (C) 2003,2004 Tvrtko A. Ursulin
7  * and
8  * linux/mm/oom_kill.c (C) 1998,2000 Rik van Riel.
9  *
10  * Mark Huang <mlhuang@cs.princeton.edu>
11  *
12  * $Id$
13  */
14
15 #include <linux/mm.h>
16 #include <linux/sched.h>
17 #include <linux/swap.h>
18
19 /**
20  * out_of_memory - is the system out of memory?
21  */
22 void out_of_memory(int gfp_mask)
23 {
24         /*
25          * oom_lock protects out_of_memory()'s static variables.
26          * It's a global lock; this is not performance-critical.
27          */
28         static spinlock_t oom_lock = SPIN_LOCK_UNLOCKED;
29         static unsigned long count;
30
31         spin_lock(&oom_lock);
32
33         /*
34          * If we have gotten only a few failures,
35          * we're not really oom. 
36          */
37         if (++count < 10)
38                 goto out_unlock;
39
40         /*
41          * Ok, really out of memory. Panic.
42          */
43
44         printk("oom-killer: gfp_mask=0x%x\n", gfp_mask);
45         show_free_areas();
46
47         panic("Out Of Memory");
48
49 out_unlock:
50         spin_unlock(&oom_lock);
51 }