9220592
From c01043c9aa51a63bd01c60e53494ca4a7e994542 Mon Sep 17 00:00:00 2001
9220592
From: Mel Gorman <mgorman@suse.de>
9220592
Date: Fri, 7 Oct 2011 16:17:23 +0100
9220592
Subject: [PATCH 2/2] mm: Abort reclaim/compaction if compaction can proceed
9220592
9220592
If compaction can proceed, shrink_zones() stops doing any work but
9220592
the callers still shrink_slab(), raises the priority and potentially
9220592
sleeps.  This patch aborts direct reclaim/compaction entirely if
9220592
compaction can proceed.
9220592
9220592
Signed-off-by: Mel Gorman <mgorman@suse.de>
9220592
---
9220592
 mm/vmscan.c |   20 ++++++++++++++++----
9220592
 1 files changed, 16 insertions(+), 4 deletions(-)
9220592
9220592
diff --git a/mm/vmscan.c b/mm/vmscan.c
9220592
index 8c03534..b295a38 100644
9220592
--- a/mm/vmscan.c
9220592
+++ b/mm/vmscan.c
9220592
@@ -2000,14 +2000,19 @@ restart:
9220592
  *
9220592
  * If a zone is deemed to be full of pinned pages then just give it a light
9220592
  * scan then give up on it.
9220592
+ *
9220592
+ * This function returns true if a zone is being reclaimed for a costly
9220592
+ * high-order allocation and compaction is either ready to begin or deferred.
9220592
+ * This indicates to the caller that it should retry the allocation or fail.
9220592
  */
9220592
-static void shrink_zones(int priority, struct zonelist *zonelist,
9220592
+static bool shrink_zones(int priority, struct zonelist *zonelist,
9220592
 					struct scan_control *sc)
9220592
 {
9220592
 	struct zoneref *z;
9220592
 	struct zone *zone;
9220592
 	unsigned long nr_soft_reclaimed;
9220592
 	unsigned long nr_soft_scanned;
9220592
+	bool should_abort_reclaim = false;
9220592
 
9220592
 	for_each_zone_zonelist_nodemask(zone, z, zonelist,
9220592
 					gfp_zone(sc->gfp_mask), sc->nodemask) {
9220592
@@ -2025,12 +2030,15 @@ static void shrink_zones(int priority, struct zonelist *zonelist,
9220592
 			if (COMPACTION_BUILD) {
9220592
 				/*
9220592
 				 * If we already have plenty of memory free
9220592
-				 * for compaction, don't free any more.
9220592
+				 * for compaction in this zone , don't free any
9220592
+				 * more.
9220592
 				 */
9220592
 				if (sc->order > PAGE_ALLOC_COSTLY_ORDER &&
9220592
 					(compaction_suitable(zone, sc->order) ||
9220592
-					 compaction_deferred(zone)))
9220592
+					 compaction_deferred(zone))) {
9220592
+					should_abort_reclaim = true;
9220592
 					continue;
9220592
+				}
9220592
 			}
9220592
 			/*
9220592
 			 * This steals pages from memory cgroups over softlimit
9220592
@@ -2049,6 +2057,8 @@ static void shrink_zones(int priority, struct zonelist *zonelist,
9220592
 
9220592
 		shrink_zone(priority, zone, sc);
9220592
 	}
9220592
+
9220592
+	return should_abort_reclaim;
9220592
 }
9220592
 
9220592
 static bool zone_reclaimable(struct zone *zone)
9220592
@@ -2113,7 +2123,9 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist,
9220592
 		sc->nr_scanned = 0;
9220592
 		if (!priority)
9220592
 			disable_swap_token(sc->mem_cgroup);
9220592
-		shrink_zones(priority, zonelist, sc);
9220592
+		if (shrink_zones(priority, zonelist, sc))
9220592
+			break;
9220592
+
9220592
 		/*
9220592
 		 * Don't shrink slabs when reclaiming memory from
9220592
 		 * over limit cgroups
9220592
-- 
9220592
1.7.6.4
9220592