linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: William Lee Irwin III <wli@holomorphy.com>
To: riel@surriel.com
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: for_each_zone cleanup
Date: Thu, 7 Feb 2002 16:37:11 -0800	[thread overview]
Message-ID: <20020208003711.GE11971@holomorphy.com> (raw)

Well, this has been floating around for a while, but here it is.
Others will shortly follow.

Cheers,
Bill

# This is a BitKeeper generated patch for the following project:
# Project Name: Long-term Linux VM development
# This patch format is intended for GNU patch command version 2.5 or higher.
# This patch includes the following deltas:
#	           ChangeSet	1.190   -> 1.191  
#	include/linux/mm_inline.h	1.13    -> 1.14   
#	include/linux/mmzone.h	1.12    -> 1.13   
#	         mm/vmscan.c	1.93    -> 1.94   
#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 02/02/07	wli@tisifone.holomorphy.com	1.191
# Cleanup of for_each_zone() specifically addressing
# (1) call by reference instead of returning a value in __next_zone()
# (2) the use of an unnecessary pg_data_t state variable in for_each_zone()
# -- wli
# --------------------------------------------
#
diff --minimal -Nru a/include/linux/mm_inline.h b/include/linux/mm_inline.h
--- a/include/linux/mm_inline.h	Thu Feb  7 16:30:27 2002
+++ b/include/linux/mm_inline.h	Thu Feb  7 16:30:27 2002
@@ -126,13 +126,12 @@
 static inline int free_limit(struct zone_struct * zone, int limit)
 {
 	int shortage = 0, local;
-	pg_data_t * pgdat;
 
 	if (zone == ALL_ZONES) {
-		for_each_zone(pgdat, zone)
+		for_each_zone(zone)
 			shortage += zone_free_limit(zone, limit);
 	} else if (zone == ANY_ZONE) {
-		for_each_zone(pgdat, zone) {
+		for_each_zone(zone) {
 			local = zone_free_limit(zone, limit);
 			shortage += max(local, 0);
 		}
@@ -222,13 +221,12 @@
 static inline int inactive_limit(struct zone_struct * zone, int limit)
 {
 	int shortage = 0, local;
-	pg_data_t * pgdat;
 
 	if (zone == ALL_ZONES) {
-		for_each_zone(pgdat, zone)
+		for_each_zone(zone)
 			shortage += zone_inactive_limit(zone, limit);
 	} else if (zone == ANY_ZONE) {
-		for_each_zone(pgdat, zone) {
+		for_each_zone(zone) {
 			local = zone_inactive_limit(zone, limit);
 			shortage += max(local, 0);
 		}
diff --minimal -Nru a/include/linux/mmzone.h b/include/linux/mmzone.h
--- a/include/linux/mmzone.h	Thu Feb  7 16:30:27 2002
+++ b/include/linux/mmzone.h	Thu Feb  7 16:30:27 2002
@@ -162,28 +162,31 @@
 extern pg_data_t contig_page_data;
 
 /*
- * __next_zone - helper magic for for_each_zone()
+ * next_zone - helper magic for for_each_zone()
  * Thanks to William Lee Irwin III for this piece of ingenuity.
  */
-static inline void __next_zone(pg_data_t **pgdat, zone_t **zone)
+static inline zone_t *next_zone(zone_t *zone)
 {
-	(*zone)++;
-	if(*zone - (*pgdat)->node_zones >= MAX_NR_ZONES) {
-		*pgdat = (*pgdat)->node_next;
-		if(*pgdat)
-			*zone = (*pgdat)->node_zones;
-		else
-			*zone = NULL;
-	}
+	pg_data_t *pgdat = zone->zone_pgdat;
+
+	if (zone - pgdat->node_zones < MAX_NR_ZONES - 1)
+		zone++;
+
+	else if (pgdat->node_next) {
+		pgdat = pgdat->node_next;
+		zone = pgdat->node_zones;
+	} else
+		zone = NULL;
+
+	return zone;
 }
 
 /**
  * for_each_zone - helper macro to iterate over all memory zones
- * @pgdat - pg_data_t * variable
  * @zone - zone_t * variable
  *
- * The user only needs to declare both variables, for_each_zone
- * fills them in. This basically means for_each_zone() is an
+ * The user only needs to declare the zone variable, for_each_zone
+ * fills it in. This basically means for_each_zone() is an
  * easier to read version of this piece of code:
  *
  * for(pgdat = pgdat_list; pgdat; pgdat = pgdat->node_next)
@@ -193,10 +196,8 @@
  * 	}
  * }
  */
-#define for_each_zone(pgdat, zone)				\
-	for(pgdat = pgdat_list, zone = pgdat->node_zones;	\
-			pgdat && zone;				\
-			__next_zone(&pgdat, &zone))
+#define for_each_zone(zone) \
+	for(zone = pgdat_list->node_zones; zone; zone = next_zone(zone))
 
 
 #ifndef CONFIG_DISCONTIGMEM
diff --minimal -Nru a/mm/vmscan.c b/mm/vmscan.c
--- a/mm/vmscan.c	Thu Feb  7 16:30:27 2002
+++ b/mm/vmscan.c	Thu Feb  7 16:30:27 2002
@@ -421,18 +421,17 @@
 {
 	int maxtry = 1 << DEF_PRIORITY;
 	struct zone_struct * zone;
-	pg_data_t * pgdat;
 	int freed = 0;
 
 	/* Global balancing while we have a global shortage. */
 	while (maxtry-- && free_high(ALL_ZONES) >= 0) {
-		for_each_zone(pgdat, zone)
+		for_each_zone(zone)
 			if (free_plenty(zone) >= 0)
 				freed += page_launder_zone(zone, gfp_mask, 6);
 	}
 	
 	/* Clean up the remaining zones with a serious shortage, if any. */
-	for_each_zone(pgdat, zone)
+	for_each_zone(zone)
 		if (free_min(zone) >= 0)
 			freed += page_launder_zone(zone, gfp_mask, 0);
 
@@ -524,20 +523,19 @@
 int refill_inactive(void)
 {
 	int maxtry = 1 << DEF_PRIORITY;
-	pg_data_t * pgdat;
 	zone_t * zone;
 	int ret = 0;
 
 	/* Global balancing while we have a global shortage. */
 	while (maxtry-- && inactive_low(ALL_ZONES) >= 0) {
-		for_each_zone(pgdat, zone) {
+		for_each_zone(zone) {
 			if (inactive_high(zone) >= 0)
 				ret += refill_inactive_zone(zone, DEF_PRIORITY);
 		}
 	}
 
 	/* Local balancing for zones which really need it. */
-	for_each_zone(pgdat, zone) {
+	for_each_zone(zone) {
 		if (inactive_min(zone) >= 0)
 			ret += refill_inactive_zone(zone, 0);
 	}
@@ -558,9 +556,8 @@
 static inline void background_aging(int priority)
 {
 	struct zone_struct * zone;
-	pg_data_t * pgdat;
 
-	for_each_zone(pgdat, zone)
+	for_each_zone(zone)
 		if (inactive_high(zone) > 0)
 			refill_inactive_zone(zone, priority);
 }
@@ -624,10 +621,9 @@
 static void refill_freelist(void)
 {
 	struct page * page;
-	pg_data_t * pgdat;
 	zone_t * zone;
 
-	for_each_zone(pgdat, zone) {
+	for_each_zone(zone) {
 		if (!zone->size || zone->free_pages >= zone->pages_min)
 			continue;
 
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/

                 reply	other threads:[~2002-02-08  0:37 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020208003711.GE11971@holomorphy.com \
    --to=wli@holomorphy.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=riel@surriel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox