]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
oom: add per-zone locking
authorDavid Rientjes <rientjes@google.com>
Wed, 17 Oct 2007 06:25:55 +0000 (23:25 -0700)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Wed, 17 Oct 2007 15:42:45 +0000 (08:42 -0700)
OOM killer synchronization should be done with zone granularity so that memory
policy and cpuset allocations may have their corresponding zones locked and
allow parallel kills for other OOM conditions that may exist elsewhere in the
system.  DMA allocations can be targeted at the zone level, which would not be
possible if locking was done in nodes or globally.

Synchronization shall be done with a variation of "trylocks." The goal is to
put the current task to sleep and restart the failed allocation attempt later
if the trylock fails.  Otherwise, the OOM killer is invoked.

Each zone in the zonelist that __alloc_pages() was called with is checked for
the newly-introduced ZONE_OOM_LOCKED flag.  If any zone has this flag present,
the "trylock" to serialize the OOM killer fails and returns zero.  Otherwise,
all the zones have ZONE_OOM_LOCKED set and the try_set_zone_oom() function
returns non-zero.

Cc: Andrea Arcangeli <andrea@suse.de>
Cc: Christoph Lameter <clameter@sgi.com>
Signed-off-by: David Rientjes <rientjes@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/mmzone.h
include/linux/oom.h
mm/oom_kill.c

index bad9486ee0cce5ceaeb982cd47e0ed15fff91046..9011505e740d8405000b1dc14a0b3f8db4701172 100644 (file)
@@ -344,6 +344,7 @@ struct zone {
 typedef enum {
        ZONE_ALL_UNRECLAIMABLE,         /* all pages pinned */
        ZONE_RECLAIM_LOCKED,            /* prevents concurrent reclaim */
+       ZONE_OOM_LOCKED,                /* zone is in OOM killer zonelist */
 } zone_flags_t;
 
 static inline void zone_set_flag(struct zone *zone, zone_flags_t flag)
@@ -363,6 +364,10 @@ static inline int zone_is_reclaim_locked(const struct zone *zone)
 {
        return test_bit(ZONE_RECLAIM_LOCKED, &zone->flags);
 }
+static inline int zone_is_oom_locked(const struct zone *zone)
+{
+       return test_bit(ZONE_OOM_LOCKED, &zone->flags);
+}
 
 /*
  * The "priority" of VM scanning is how much of the queues we will scan in one
index cf6ebf5b422c40c0233ea08f29dedb4c4885c44c..e9081200cdb77ff8bc4b888c4798156de465f6a2 100644 (file)
@@ -20,6 +20,9 @@ enum oom_constraint {
        CONSTRAINT_MEMORY_POLICY,
 };
 
+extern int try_set_zone_oom(struct zonelist *zonelist);
+extern void clear_zonelist_oom(struct zonelist *zonelist);
+
 extern void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask, int order);
 extern int register_oom_notifier(struct notifier_block *nb);
 extern int unregister_oom_notifier(struct notifier_block *nb);
index 1a7a4ef04e2715b2b217f9f5f560acfd6a26c24c..6e999c88c503ce5f3997c0726cb23033d7119705 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/notifier.h>
 
 int sysctl_panic_on_oom;
+static DEFINE_MUTEX(zone_scan_mutex);
 /* #define DEBUG */
 
 /**
@@ -374,6 +375,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;
+
+       mutex_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:
+       mutex_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;
+
+       mutex_lock(&zone_scan_mutex);
+       do {
+               zone_clear_flag(*z, ZONE_OOM_LOCKED);
+       } while (*(++z) != NULL);
+       mutex_unlock(&zone_scan_mutex);
+}
+
 /**
  * out_of_memory - kill the "best" process when we run out of memory
  *