Skip to contentSkip to conversation

PATCH [email protected] 1 participant 1 message Feb 6, 2009

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw
Quoted 1 line

From [email protected] Fri Feb 6 02:28:54 2009

Message-Id: <[email protected]>
User-Agent: quilt/0.47-1
Date: Fri, 06 Feb 2009 02:26:06 +0100
From: Johannes Weiner <[email protected]>
To: Andrew Morton <[email protected]>
Cc: "Rafael J. Wysocki" <[email protected]>,
Rik van Riel <[email protected]>,
[email protected],
[email protected]
Subject: [PATCH 1/3] swsusp: clean up shrink_all_zones()
References: <[email protected]>
Content-Disposition: inline; filename=swsusp-clean-up-shrink_all_zones.patch

Move local variables to innermost possible scopes and use local variables to cache calculations/reads done more than once.

No change in functionality (intended).

---
 mm/vmscan.c |   23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)
mm/vmscan.c +11 -12
@@ -2057,31 +2057,31 @@ static unsigned long shrink_all_zones(un
 				      int pass, struct scan_control *sc)
 {
 	struct zone *zone;
-	unsigned long nr_to_scan, ret = 0;
-	enum lru_list l;
+	unsigned long ret = 0;
 
 	for_each_zone(zone) {
+		enum lru_list l;
 
 		if (!populated_zone(zone))
 			continue;
-
 		if (zone_is_all_unreclaimable(zone) && prio != DEF_PRIORITY)
 			continue;
 
 		for_each_evictable_lru(l) {
+			enum zone_stat_item ls = NR_LRU_BASE + l;
+			unsigned long lru_pages = zone_page_state(zone, ls);
+
 			/* For pass = 0, we don't shrink the active list */
-			if (pass == 0 &&
-				(l == LRU_ACTIVE || l == LRU_ACTIVE_FILE))
+			if (pass == 0 && (l == LRU_ACTIVE_ANON ||
+						l == LRU_ACTIVE_FILE))
 				continue;
 
-			zone->lru[l].nr_scan +=
-				(zone_page_state(zone, NR_LRU_BASE + l)
-								>> prio) + 1;
+			zone->lru[l].nr_scan += (lru_pages >> prio) + 1;
 			if (zone->lru[l].nr_scan >= nr_pages || pass > 3) {
+				unsigned long nr_to_scan;
+
 				zone->lru[l].nr_scan = 0;
-				nr_to_scan = min(nr_pages,
-					zone_page_state(zone,
-							NR_LRU_BASE + l));
+				nr_to_scan = min(nr_pages, lru_pages);
 				ret += shrink_list(l, nr_to_scan, zone,
 								sc, prio);
 				if (ret >= nr_pages)
@@ -2089,7 +2089,6 @@ static unsigned long shrink_all_zones(un
 			}
 		}
 	}
-
 	return ret;
 }