From: Robert Love <rml@tech9.net>
To: akpm@zip.com.au, torvalds@transmeta.com
Cc: riel@conectiva.com.br, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, wli@holomorphy.com
Subject: [PATCH] for_each_zone
Date: 20 Jul 2002 13:22:23 -0700 [thread overview]
Message-ID: <1027196543.1555.775.camel@sinai> (raw)
Attached patch implements for_each_zone(zont_t *) which is a helper
macro to cleanup code of the form:
for (pgdat = pgdat_list; pgdat; pgdat = pgdat->node_next) {
for (i = 0; i < MAX_NR_ZONES; ++i) {
zone_t * z = pgdat->node_zones + i;
/* ... */
}
}
and replace it with:
for_each_zone(zone) {
/* ... */
}
This patch only replaces one use of the above loop with the new macro.
Pending code, however, currently in the full rmap patch uses
for_each_zone more extensively.
This is from Rik's 2.4-rmap patch and by William Irwin.
This patch requires the previous for_each_pgdat patch, but only to apply
cleanly.
Robert Love
diff -urN linux-2.5.27/include/linux/mmzone.h linux/include/linux/mmzone.h
--- linux-2.5.27/include/linux/mmzone.h Sat Jul 20 12:11:05 2002
+++ linux/include/linux/mmzone.h Sat Jul 20 13:00:48 2002
@@ -163,6 +163,43 @@
extern pg_data_t contig_page_data;
+/*
+ * next_zone - helper magic for for_each_zone()
+ * Thanks to William Lee Irwin III for this piece of ingenuity.
+ */
+static inline zone_t * next_zone(zone_t * zone)
+{
+ 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
+ * @zone - pointer to zone_t variable
+ *
+ * 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)
+ * for (i = 0; i < MAX_NR_ZONES; ++i) {
+ * zone_t * z = pgdat->node_zones + i;
+ * ...
+ * }
+ * }
+ */
+#define for_each_zone(zone) \
+ for (zone = pgdat_list->node_zones; zone; zone = next_zone(zone))
+
#ifndef CONFIG_DISCONTIGMEM
#define NODE_DATA(nid) (&contig_page_data)
diff -urN linux-2.5.27/mm/page_alloc.c linux/mm/page_alloc.c
--- linux-2.5.27/mm/page_alloc.c Sat Jul 20 12:11:07 2002
+++ linux/mm/page_alloc.c Sat Jul 20 13:00:48 2002
@@ -477,12 +477,12 @@
*/
unsigned int nr_free_pages(void)
{
- unsigned int i, sum = 0;
- pg_data_t *pgdat;
+ unsigned int sum;
+ zone_t *zone;
- for (pgdat = pgdat_list; pgdat; pgdat = pgdat->node_next)
- for (i = 0; i < MAX_NR_ZONES; ++i)
- sum += pgdat->node_zones[i].free_pages;
+ sum = 0;
+ for_each_zone(zone)
+ sum += zone->free_pages;
return sum;
}
WARNING: multiple messages have this Message-ID (diff)
From: Robert Love <rml@tech9.net>
To: akpm@zip.com.au, torvalds@transmeta.com
Cc: riel@conectiva.com.br, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, wli@holomorphy.com
Subject: [PATCH] for_each_zone
Date: 20 Jul 2002 13:22:23 -0700 [thread overview]
Message-ID: <1027196543.1555.775.camel@sinai> (raw)
Attached patch implements for_each_zone(zont_t *) which is a helper
macro to cleanup code of the form:
for (pgdat = pgdat_list; pgdat; pgdat = pgdat->node_next) {
for (i = 0; i < MAX_NR_ZONES; ++i) {
zone_t * z = pgdat->node_zones + i;
/* ... */
}
}
and replace it with:
for_each_zone(zone) {
/* ... */
}
This patch only replaces one use of the above loop with the new macro.
Pending code, however, currently in the full rmap patch uses
for_each_zone more extensively.
This is from Rik's 2.4-rmap patch and by William Irwin.
This patch requires the previous for_each_pgdat patch, but only to apply
cleanly.
Robert Love
diff -urN linux-2.5.27/include/linux/mmzone.h linux/include/linux/mmzone.h
--- linux-2.5.27/include/linux/mmzone.h Sat Jul 20 12:11:05 2002
+++ linux/include/linux/mmzone.h Sat Jul 20 13:00:48 2002
@@ -163,6 +163,43 @@
extern pg_data_t contig_page_data;
+/*
+ * next_zone - helper magic for for_each_zone()
+ * Thanks to William Lee Irwin III for this piece of ingenuity.
+ */
+static inline zone_t * next_zone(zone_t * zone)
+{
+ 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
+ * @zone - pointer to zone_t variable
+ *
+ * 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)
+ * for (i = 0; i < MAX_NR_ZONES; ++i) {
+ * zone_t * z = pgdat->node_zones + i;
+ * ...
+ * }
+ * }
+ */
+#define for_each_zone(zone) \
+ for (zone = pgdat_list->node_zones; zone; zone = next_zone(zone))
+
#ifndef CONFIG_DISCONTIGMEM
#define NODE_DATA(nid) (&contig_page_data)
diff -urN linux-2.5.27/mm/page_alloc.c linux/mm/page_alloc.c
--- linux-2.5.27/mm/page_alloc.c Sat Jul 20 12:11:07 2002
+++ linux/mm/page_alloc.c Sat Jul 20 13:00:48 2002
@@ -477,12 +477,12 @@
*/
unsigned int nr_free_pages(void)
{
- unsigned int i, sum = 0;
- pg_data_t *pgdat;
+ unsigned int sum;
+ zone_t *zone;
- for (pgdat = pgdat_list; pgdat; pgdat = pgdat->node_next)
- for (i = 0; i < MAX_NR_ZONES; ++i)
- sum += pgdat->node_zones[i].free_pages;
+ sum = 0;
+ for_each_zone(zone)
+ sum += zone->free_pages;
return sum;
}
--
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/
next reply other threads:[~2002-07-20 20:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-07-20 20:22 Robert Love [this message]
2002-07-20 20:22 ` [PATCH] for_each_zone Robert Love
2002-07-20 22:43 ` [PATCH] for_each_zone, updated Robert Love
2002-07-20 22:43 ` Robert Love
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=1027196543.1555.775.camel@sinai \
--to=rml@tech9.net \
--cc=akpm@zip.com.au \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=riel@conectiva.com.br \
--cc=torvalds@transmeta.com \
--cc=wli@holomorphy.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.