linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ankita Garg <ankita@in.ibm.com>
To: linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org,
	linux-pm@lists.linux-foundation.org
Cc: ankita@in.ibm.com, svaidy@linux.vnet.ibm.com, thomas.abraham@linaro.org
Subject: [PATCH 02/10] mm: Helper routines
Date: Fri, 27 May 2011 18:01:30 +0530	[thread overview]
Message-ID: <1306499498-14263-3-git-send-email-ankita@in.ibm.com> (raw)
In-Reply-To: <1306499498-14263-1-git-send-email-ankita@in.ibm.com>

With the introduction of regions, helper routines are needed to walk through
all the regions and zones inside a node. This patch adds these helper
routines.

Signed-off-by: Ankita Garg <ankita@in.ibm.com>
---
 include/linux/mm.h     |   21 ++++++++++++++++-----
 include/linux/mmzone.h |   25 ++++++++++++++++++++++---
 mm/mmzone.c            |   36 +++++++++++++++++++++++++++++++-----
 mm/page_alloc.c        |   10 ++++++++++
 4 files changed, 79 insertions(+), 13 deletions(-)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 6507dde..25299a3 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -675,11 +675,6 @@ static inline int page_to_nid(struct page *page)
 }
 #endif
 
-static inline struct zone *page_zone(struct page *page)
-{
-	return &NODE_DATA(page_to_nid(page))->node_zones[page_zonenum(page)];
-}
-
 #if defined(CONFIG_SPARSEMEM) && !defined(CONFIG_SPARSEMEM_VMEMMAP)
 static inline unsigned long page_to_section(struct page *page)
 {
@@ -687,6 +682,22 @@ static inline unsigned long page_to_section(struct page *page)
 }
 #endif
 
+static inline struct zone *page_zone(struct page *page)
+{
+	pg_data_t *pg = NODE_DATA(page_to_nid(page));
+	int i;
+	unsigned long pfn = page_to_pfn(page);
+
+	for (i = 0; i< pg->nr_mem_regions; i++) {
+		mem_region_t *mem_region= &(pg->mem_regions[i]);
+		unsigned long end_pfn = mem_region->start_pfn + mem_region->spanned_pages - 1;
+		if ((pfn >= mem_region->start_pfn) && (pfn <= end_pfn))
+			return &mem_region->zones[page_zonenum(page)];
+	}
+
+	return NULL;
+}
+
 static inline void set_page_zone(struct page *page, enum zone_type zone)
 {
 	page->flags &= ~(ZONES_MASK << ZONES_PGSHIFT);
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 997a474..3f13dc8 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -711,7 +711,7 @@ unsigned long __init node_memmap_size_bytes(int, unsigned long, unsigned long);
 /*
  * zone_idx() returns 0 for the ZONE_DMA zone, 1 for the ZONE_NORMAL zone, etc.
  */
-#define zone_idx(zone)		((zone) - (zone)->zone_pgdat->node_zones)
+#define zone_idx(zone)		((zone) - (zone)->zone_mem_region->zones)
 
 static inline int populated_zone(struct zone *zone)
 {
@@ -818,6 +818,7 @@ extern struct pglist_data contig_page_data;
 
 extern struct pglist_data *first_online_pgdat(void);
 extern struct pglist_data *next_online_pgdat(struct pglist_data *pgdat);
+extern struct zone* first_zone(void);
 extern struct zone *next_zone(struct zone *zone);
 
 /**
@@ -828,6 +829,24 @@ extern struct zone *next_zone(struct zone *zone);
 	for (pgdat = first_online_pgdat();		\
 	     pgdat;					\
 	     pgdat = next_online_pgdat(pgdat))
+
+extern struct mem_region_list_data *first_mem_region(struct pglist_data *pgdat);
+/**
+ * for_each_mem_region - helper macro to iterate over all the memory regions in a
+ * node
+ * @mem_region - pointer to a mem_region_t variable
+ */
+#define for_each_online_mem_region(mem_region)			\
+	for (mem_region = first_node_mem_region();		\
+		mem_region;					\
+		mem_region = next_mem_region(mem_region))
+
+inline int first_mem_region_in_nid(int nid);
+int next_mem_region_in_nid(int idx, int nid);
+/* Basic iterator support to walk all the memory regions in a node */
+#define for_each_mem_region_in_nid(i, nid) 		\
+	for (i = 0; i != -1; i = next_mem_region_in_nid(i, nid))
+
 /**
  * for_each_zone - helper macro to iterate over all memory zones
  * @zone - pointer to struct zone variable
@@ -836,12 +855,12 @@ extern struct zone *next_zone(struct zone *zone);
  * fills it in.
  */
 #define for_each_zone(zone)			        \
-	for (zone = (first_online_pgdat())->node_zones; \
+	     for (zone = (first_zone());		\
 	     zone;					\
 	     zone = next_zone(zone))
 
 #define for_each_populated_zone(zone)		        \
-	for (zone = (first_online_pgdat())->node_zones; \
+	     for (zone = (first_zone());		\
 	     zone;					\
 	     zone = next_zone(zone))			\
 		if (!populated_zone(zone))		\
diff --git a/mm/mmzone.c b/mm/mmzone.c
index f5b7d17..0e2bec3 100644
--- a/mm/mmzone.c
+++ b/mm/mmzone.c
@@ -24,21 +24,47 @@ struct pglist_data *next_online_pgdat(struct pglist_data *pgdat)
 	return NODE_DATA(nid);
 }
 
+inline struct mem_region_list_data *first_mem_region(struct pglist_data *pgdat)
+{
+	return &pgdat->mem_regions[0];
+}
+
+struct mem_region_list_data *next_mem_region(struct mem_region_list_data *mem_region)
+{
+	int next_region = mem_region->region + 1;
+	pg_data_t *pgdat = NODE_DATA(mem_region->node);
+
+	if (next_region == pgdat->nr_mem_regions)
+		return NULL;
+	return &(pgdat->mem_regions[next_region]);
+}
+
+inline struct zone *first_zone(void)
+{
+	return (first_online_pgdat())->mem_regions[0].zones;
+}
+
 /*
  * next_zone - helper magic for for_each_zone()
  */
 struct zone *next_zone(struct zone *zone)
 {
 	pg_data_t *pgdat = zone->zone_pgdat;
+	mem_region_t *mem_region = zone->zone_mem_region;
 
-	if (zone < pgdat->node_zones + MAX_NR_ZONES - 1)
+	if (zone < mem_region->zones + MAX_NR_ZONES - 1)
 		zone++;
 	else {
-		pgdat = next_online_pgdat(pgdat);
-		if (pgdat)
-			zone = pgdat->node_zones;
+		mem_region = next_mem_region(mem_region);
+		if (!mem_region) {
+			pgdat = next_online_pgdat(pgdat);
+			if (pgdat)
+				zone = pgdat->mem_regions[0].zones;
+			else
+				zone = NULL;
+		}
 		else
-			zone = NULL;
+			zone = mem_region->zones;
 	}
 	return zone;
 }
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 3f8bce2..af2529d 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -2492,6 +2492,16 @@ out:
 
 #define K(x) ((x) << (PAGE_SHIFT-10))
 
+int next_mem_region_in_nid(int idx, int nid)
+{
+	pg_data_t *pgdat = NODE_DATA(nid);
+	int region = idx + 1;
+
+	if (region == pgdat->nr_mem_regions)
+		return -1;
+	return region;
+}
+
 /*
  * Show free area list (used inside shift_scroll-lock stuff)
  * We also calculate the percentage fragmentation. We do this by counting the
-- 
1.7.4


  parent reply	other threads:[~2011-05-27 12:34 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-27 12:31 [PATCH 00/10] mm: Linux VM Infrastructure to support Memory Power Management Ankita Garg
2011-05-27 12:31 ` [PATCH 01/10] mm: Introduce the memory regions data structure Ankita Garg
2011-05-27 15:30   ` Dave Hansen
2011-05-27 18:20     ` Vaidyanathan Srinivasan
2011-05-27 21:31       ` Dave Hansen
2011-05-29  8:16         ` Ankita Garg
2011-05-31 17:34           ` Dave Hansen
2011-06-02  8:54             ` Ankita Garg
2011-05-27 12:31 ` Ankita Garg [this message]
2011-05-27 12:31 ` [PATCH 03/10] mm: Init zones inside memory regions Ankita Garg
2011-05-27 12:31 ` [PATCH 04/10] mm: Refer to zones from " Ankita Garg
2011-05-27 12:31 ` [PATCH 05/10] mm: Create zonelists Ankita Garg
2011-05-27 12:31 ` [PATCH 06/10] mm: Verify zonelists Ankita Garg
2011-05-27 12:31 ` [PATCH 07/10] mm: Modify vmstat Ankita Garg
2011-05-27 12:31 ` [PATCH 08/10] mm: Modify vmscan Ankita Garg
2011-05-27 12:31 ` [PATCH 09/10] mm: Reflect memory region changes in zoneinfo Ankita Garg
2011-05-27 12:31 ` [PATCH 10/10] mm: Create memory regions at boot-up Ankita Garg
2011-05-28 14:39   ` Jean-Christophe PLAGNIOL-VILLARD
2011-05-28  7:56 ` [PATCH 00/10] mm: Linux VM Infrastructure to support Memory Power Management Andrew Morton
2011-05-28 13:16   ` Ankita Garg
2011-06-09 18:52   ` Paul E. McKenney
2011-06-10  0:51     ` Kyungmin Park
2011-06-10 15:11       ` Paul E. McKenney
2011-06-10 15:59         ` Matthew Garrett
2011-06-10 16:55           ` Paul E. McKenney
2011-06-10 17:05             ` Matthew Garrett
2011-06-10 17:19               ` Paul E. McKenney
2011-06-10 17:23                 ` Matthew Garrett
2011-06-10 17:52                   ` Paul E. McKenney
2011-06-10 18:08                     ` Matthew Garrett
2011-06-10 18:47                       ` Paul E. McKenney
2011-06-10 19:23                         ` Matthew Garrett
2011-06-10 19:37                           ` Paul E. McKenney
2011-06-10 20:12                             ` Matthew Garrett
2011-06-11  3:02                             ` Arjan van de Ven
2011-06-11 17:06                               ` Paul E. McKenney
2011-06-11 17:26                                 ` Arjan van de Ven
2011-06-12 23:07                                   ` Paul E. McKenney
2011-06-13 14:28                                     ` Arjan van de Ven
2011-06-13 23:04                                       ` Paul E. McKenney
2011-06-14  8:51                               ` Ankita Garg
2011-06-15 16:53                               ` Ankita Garg
2011-06-18  4:08                                 ` Arjan van de Ven
2011-06-10 17:33                 ` Ankita Garg
2011-06-11 17:08                   ` Paul E. McKenney
2011-07-12  5:31   ` amit kachhap
2011-06-13  4:47 ` KAMEZAWA Hiroyuki
2011-06-16  4:20   ` Ankita Garg
2011-06-16  9:12     ` KAMEZAWA Hiroyuki
2011-06-17 15:28       ` Ankita Garg
2011-06-19 23:53         ` KAMEZAWA Hiroyuki
2011-06-16 16:04     ` Dave Hansen
2011-06-17 10:03       ` Ankita Garg
2011-06-29 13:00 ` Ankita Garg
2011-06-29 17:06   ` Dave Hansen
2011-06-29 17:42     ` Ankita Garg
2011-06-29 17:59       ` Dave Hansen
2011-06-29 18:17         ` Vaidyanathan Srinivasan
2011-06-30  4:37           ` Ankita Garg
2011-06-29 20:11         ` Andi Kleen
2011-06-30  5:11           ` Ankita Garg
2011-06-29 18:07     ` Vaidyanathan Srinivasan
2011-07-06  8:45   ` Pekka Enberg
2011-07-06  9:01     ` Pekka Enberg
2011-07-06 16:50       ` Vaidyanathan Srinivasan
2011-07-06 16:41     ` Vaidyanathan Srinivasan
2011-07-06 20:20     ` david
2011-07-07  4:54       ` Ankita Garg
2011-07-07 18:00       ` Pekka Enberg
2011-07-08  1:32         ` david

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=1306499498-14263-3-git-send-email-ankita@in.ibm.com \
    --to=ankita@in.ibm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-pm@lists.linux-foundation.org \
    --cc=svaidy@linux.vnet.ibm.com \
    --cc=thomas.abraham@linaro.org \
    /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;
as well as URLs for NNTP newsgroup(s).