]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - mm/oom_kill.c
r8169: make room for more phy init changes
[linux-2.6-omap-h63xx.git] / mm / oom_kill.c
index af981b645a6904affee5320ef77869e10b8db278..a64decb5b13fb3922e05a70559855dde685b57b4 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <linux/oom.h>
 #include <linux/mm.h>
+#include <linux/err.h>
 #include <linux/sched.h>
 #include <linux/swap.h>
 #include <linux/timex.h>
@@ -26,6 +27,8 @@
 #include <linux/notifier.h>
 
 int sysctl_panic_on_oom;
+int sysctl_oom_kill_allocating_task;
+static DEFINE_SPINLOCK(zone_scan_mutex);
 /* #define DEBUG */
 
 /**
@@ -140,46 +143,37 @@ unsigned long badness(struct task_struct *p, unsigned long uptime)
         * because p may have allocated or otherwise mapped memory on
         * this node before. However it will be less likely.
         */
-       if (!cpuset_excl_nodes_overlap(p))
+       if (!cpuset_mems_allowed_intersects(current, p))
                points /= 8;
 
        /*
         * Adjust the score by oomkilladj.
         */
        if (p->oomkilladj) {
-               if (p->oomkilladj > 0)
+               if (p->oomkilladj > 0) {
+                       if (!points)
+                               points = 1;
                        points <<= p->oomkilladj;
-               else
+               else
                        points >>= -(p->oomkilladj);
        }
 
 #ifdef DEBUG
-       printk(KERN_DEBUG "OOMkill: task %d (%s) got %d points\n",
+       printk(KERN_DEBUG "OOMkill: task %d (%s) got %lu points\n",
        p->pid, p->comm, points);
 #endif
        return points;
 }
 
-/*
- * Types of limitations to the nodes from which allocations may occur
- */
-#define CONSTRAINT_NONE 1
-#define CONSTRAINT_MEMORY_POLICY 2
-#define CONSTRAINT_CPUSET 3
-
 /*
  * Determine the type of allocation constraint.
  */
-static inline int constrained_alloc(struct zonelist *zonelist, gfp_t gfp_mask)
+static inline enum oom_constraint constrained_alloc(struct zonelist *zonelist,
+                                                   gfp_t gfp_mask)
 {
 #ifdef CONFIG_NUMA
        struct zone **z;
-       nodemask_t nodes;
-       int node;
-       /* node has memory ? */
-       for_each_online_node(node)
-               if (NODE_DATA(node)->node_present_pages)
-                       node_set(node, nodes);
+       nodemask_t nodes = node_states[N_HIGH_MEMORY];
 
        for (z = zonelist->zones; *z; z++)
                if (cpuset_zone_allowed_softwall(*z, gfp_mask))
@@ -339,12 +333,20 @@ static int oom_kill_task(struct task_struct *p)
        return 0;
 }
 
-static int oom_kill_process(struct task_struct *p, unsigned long points,
-               const char *message)
+static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order,
+                           unsigned long points, const char *message)
 {
        struct task_struct *c;
        struct list_head *tsk;
 
+       if (printk_ratelimit()) {
+               printk(KERN_WARNING "%s invoked oom-killer: "
+                       "gfp_mask=0x%x, order=%d, oomkilladj=%d\n",
+                       current->comm, gfp_mask, order, current->oomkilladj);
+               dump_stack();
+               show_mem();
+       }
+
        /*
         * If the task is already exiting, don't alarm the sysadmin or kill
         * its children or threads, just set TIF_MEMDIE so it can die quickly
@@ -382,6 +384,57 @@ int unregister_oom_notifier(struct notifier_block *nb)
 }
 EXPORT_SYMBOL_GPL(unregister_oom_notifier);
 
+/*
+ * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
+ * if a parallel OOM killing is already taking place that includes a zone in
+ * the zonelist.  Otherwise, locks all zones in the zonelist and returns 1.
+ */
+int try_set_zone_oom(struct zonelist *zonelist)
+{
+       struct zone **z;
+       int ret = 1;
+
+       z = zonelist->zones;
+
+       spin_lock(&zone_scan_mutex);
+       do {
+               if (zone_is_oom_locked(*z)) {
+                       ret = 0;
+                       goto out;
+               }
+       } while (*(++z) != NULL);
+
+       /*
+        * Lock each zone in the zonelist under zone_scan_mutex so a parallel
+        * invocation of try_set_zone_oom() doesn't succeed when it shouldn't.
+        */
+       z = zonelist->zones;
+       do {
+               zone_set_flag(*z, ZONE_OOM_LOCKED);
+       } while (*(++z) != NULL);
+out:
+       spin_unlock(&zone_scan_mutex);
+       return ret;
+}
+
+/*
+ * Clears the ZONE_OOM_LOCKED flag for all zones in the zonelist so that failed
+ * allocation attempts with zonelists containing them may now recall the OOM
+ * killer, if necessary.
+ */
+void clear_zonelist_oom(struct zonelist *zonelist)
+{
+       struct zone **z;
+
+       z = zonelist->zones;
+
+       spin_lock(&zone_scan_mutex);
+       do {
+               zone_clear_flag(*z, ZONE_OOM_LOCKED);
+       } while (*(++z) != NULL);
+       spin_unlock(&zone_scan_mutex);
+}
+
 /**
  * out_of_memory - kill the "best" process when we run out of memory
  *
@@ -395,41 +448,39 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask, int order)
        struct task_struct *p;
        unsigned long points = 0;
        unsigned long freed = 0;
+       enum oom_constraint constraint;
 
        blocking_notifier_call_chain(&oom_notify_list, 0, &freed);
        if (freed > 0)
                /* Got some memory back in the last second. */
                return;
 
-       if (printk_ratelimit()) {
-               printk(KERN_WARNING "%s invoked oom-killer: "
-                       "gfp_mask=0x%x, order=%d, oomkilladj=%d\n",
-                       current->comm, gfp_mask, order, current->oomkilladj);
-               dump_stack();
-               show_mem();
-       }
-
-       cpuset_lock();
-       read_lock(&tasklist_lock);
+       if (sysctl_panic_on_oom == 2)
+               panic("out of memory. Compulsory panic_on_oom is selected.\n");
 
        /*
         * Check if there were limitations on the allocation (only relevant for
         * NUMA) that may require different handling.
         */
-       switch (constrained_alloc(zonelist, gfp_mask)) {
+       constraint = constrained_alloc(zonelist, gfp_mask);
+       read_lock(&tasklist_lock);
+
+       switch (constraint) {
        case CONSTRAINT_MEMORY_POLICY:
-               oom_kill_process(current, points,
+               oom_kill_process(current, gfp_mask, order, points,
                                "No available memory (MPOL_BIND)");
                break;
 
-       case CONSTRAINT_CPUSET:
-               oom_kill_process(current, points,
-                               "No available memory in cpuset");
-               break;
-
        case CONSTRAINT_NONE:
                if (sysctl_panic_on_oom)
                        panic("out of memory. panic_on_oom is selected\n");
+               /* Fall-through */
+       case CONSTRAINT_CPUSET:
+               if (sysctl_oom_kill_allocating_task) {
+                       oom_kill_process(current, gfp_mask, order, points,
+                                       "Out of memory (oom_kill_allocating_task)");
+                       break;
+               }
 retry:
                /*
                 * Rambo mode: Shoot down a process and hope it solves whatever
@@ -443,11 +494,11 @@ retry:
                /* Found nothing?!?! Either we hang forever, or we panic. */
                if (!p) {
                        read_unlock(&tasklist_lock);
-                       cpuset_unlock();
                        panic("Out of memory and no killable processes...\n");
                }
 
-               if (oom_kill_process(p, points, "Out of memory"))
+               if (oom_kill_process(p, points, gfp_mask, order,
+                                    "Out of memory"))
                        goto retry;
 
                break;
@@ -455,7 +506,6 @@ retry:
 
 out:
        read_unlock(&tasklist_lock);
-       cpuset_unlock();
 
        /*
         * Give "p" a good chance of killing itself before we