[PATCH] remove non-DISCONTIG use of pgdat->node_mem_map
authorDave Hansen <haveblue@us.ibm.com>
Thu, 23 Jun 2005 07:07:37 +0000 (00:07 -0700)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Thu, 23 Jun 2005 16:45:00 +0000 (09:45 -0700)
This patch effectively eliminates direct use of pgdat->node_mem_map outside
of the DISCONTIG code.  On a flat memory system, these fields aren't
currently used, neither are they on a sparsemem system.

There was also a node_mem_map(nid) macro on many architectures.  Its use
along with the use of ->node_mem_map itself was not consistent.  It has
been removed in favor of two new, more explicit, arch-independent macros:

pgdat_page_nr(pgdat, pagenr)
nid_page_nr(nid, pagenr)

I called them "pgdat" and "nid" because we overload the term "node" to mean
"NUMA node", "DISCONTIG node" or "pg_data_t" in very confusing ways.  I
believe the newer names are much clearer.

These macros can be overridden in the sparsemem case with a theoretically
slower operation using node_start_pfn and pfn_to_page(), instead.  We could
make this the only behavior if people want, but I don't want to change too
much at once.  One thing at a time.

This patch removes more code than it adds.

Compile tested on alpha, alpha discontig, arm, arm-discontig, i386, i386
generic, NUMAQ, Summit, ppc64, ppc64 discontig, and x86_64.  Full list
here: http://sr71.net/patches/2.6.12/2.6.12-rc1-mhp2/configs/

Boot tested on NUMAQ, x86 SMP and ppc64 power4/5 LPARs.

Signed-off-by: Dave Hansen <haveblue@us.ibm.com>
Signed-off-by: Martin J. Bligh <mbligh@aracnet.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
14 files changed:
arch/alpha/mm/numa.c
arch/i386/mm/pgtable.c
arch/ia64/mm/discontig.c
arch/m32r/mm/init.c
arch/mips/sgi-ip27/ip27-memory.c
arch/parisc/mm/init.c
arch/ppc64/mm/init.c
include/asm-alpha/mmzone.h
include/asm-i386/mmzone.h
include/asm-m32r/mmzone.h
include/asm-parisc/mmzone.h
include/asm-ppc64/mmzone.h
include/asm-x86_64/mmzone.h
include/linux/mmzone.h

index ba81c4422aaf5fcfd4da8d731c23eae8820e988c..c7481d59b6dff4dc922acb6c6afce238f7a8b939 100644 (file)
@@ -327,8 +327,6 @@ void __init mem_init(void)
        extern char _text, _etext, _data, _edata;
        extern char __init_begin, __init_end;
        unsigned long nid, i;
-       struct page * lmem_map;
-
        high_memory = (void *) __va(max_low_pfn << PAGE_SHIFT);
 
        reservedpages = 0;
@@ -338,10 +336,10 @@ void __init mem_init(void)
                 */
                totalram_pages += free_all_bootmem_node(NODE_DATA(nid));
 
-               lmem_map = node_mem_map(nid);
                pfn = NODE_DATA(nid)->node_start_pfn;
                for (i = 0; i < node_spanned_pages(nid); i++, pfn++)
-                       if (page_is_ram(pfn) && PageReserved(lmem_map+i))
+                       if (page_is_ram(pfn) &&
+                           PageReserved(nid_page_nr(nid, i)))
                                reservedpages++;
        }
 
@@ -373,18 +371,18 @@ show_mem(void)
        show_free_areas();
        printk("Free swap:       %6ldkB\n", nr_swap_pages<<(PAGE_SHIFT-10));
        for_each_online_node(nid) {
-               struct page * lmem_map = node_mem_map(nid);
                i = node_spanned_pages(nid);
                while (i-- > 0) {
+                       struct page *page = nid_page_nr(nid, i);
                        total++;
-                       if (PageReserved(lmem_map+i))
+                       if (PageReserved(page))
                                reserved++;
-                       else if (PageSwapCache(lmem_map+i))
+                       else if (PageSwapCache(page))
                                cached++;
-                       else if (!page_count(lmem_map+i))
+                       else if (!page_count(page))
                                free++;
                        else
-                               shared += page_count(lmem_map + i) - 1;
+                               shared += page_count(page) - 1;
                }
        }
        printk("%ld pages of RAM\n",total);
index dd81479ff88a8b61642a34a0449902c4e8a5ecc1..80c84cdf22efb9c66d21e95bb60d467a5124eea8 100644 (file)
@@ -36,7 +36,7 @@ void show_mem(void)
        printk("Free swap:       %6ldkB\n", nr_swap_pages<<(PAGE_SHIFT-10));
        for_each_pgdat(pgdat) {
                for (i = 0; i < pgdat->node_spanned_pages; ++i) {
-                       page = pgdat->node_mem_map + i;
+                       page = pgdat_page_nr(pgdat, i);
                        total++;
                        if (PageHighMem(page))
                                highmem++;
index c00710929390d43c68ccffc92dd899c06e0204f6..f3fd528ead3b6ceb3d9a22e62e75c06b59707c43 100644 (file)
@@ -560,14 +560,15 @@ void show_mem(void)
                int shared = 0, cached = 0, reserved = 0;
                printk("Node ID: %d\n", pgdat->node_id);
                for(i = 0; i < pgdat->node_spanned_pages; i++) {
+                       struct page *page = pgdat_page_nr(pgdat, i);
                        if (!ia64_pfn_valid(pgdat->node_start_pfn+i))
                                continue;
-                       if (PageReserved(pgdat->node_mem_map+i))
+                       if (PageReserved(page))
                                reserved++;
-                       else if (PageSwapCache(pgdat->node_mem_map+i))
+                       else if (PageSwapCache(page))
                                cached++;
-                       else if (page_count(pgdat->node_mem_map+i))
-                               shared += page_count(pgdat->node_mem_map+i)-1;
+                       else if (page_count(page))
+                               shared += page_count(page)-1;
                }
                total_present += present;
                total_reserved += reserved;
index bc423d838fb82d4c70778691e9bd7f3feb600923..d9a40b1fe8ba84e8a8ad4d36920f9a0ecba1c357 100644 (file)
@@ -49,7 +49,7 @@ void show_mem(void)
        printk("Free swap:       %6ldkB\n",nr_swap_pages<<(PAGE_SHIFT-10));
        for_each_pgdat(pgdat) {
                for (i = 0; i < pgdat->node_spanned_pages; ++i) {
-                       page = pgdat->node_mem_map + i;
+                       page = pgdat_page_nr(pgdat, i);
                        total++;
                        if (PageHighMem(page))
                                highmem++;
@@ -152,7 +152,7 @@ int __init reservedpages_count(void)
        reservedpages = 0;
        for_each_online_node(nid)
                for (i = 0 ; i < MAX_LOW_PFN(nid) - START_PFN(nid) ; i++)
-                       if (PageReserved(NODE_DATA(nid)->node_mem_map + i))
+                       if (PageReserved(nid_page_nr(nid, i)))
                                reservedpages++;
 
        return reservedpages;
index 0a44a98d7adc78efd05e1d0e89765872164f32c0..a160d04f7dbe05904f84f60a262ba3b3fbb287d1 100644 (file)
@@ -549,9 +549,8 @@ void __init mem_init(void)
                 */
                numslots = node_getlastslot(node);
                for (slot = 1; slot <= numslots; slot++) {
-                       p = NODE_DATA(node)->node_mem_map +
-                               (slot_getbasepfn(node, slot) -
-                                slot_getbasepfn(node, 0));
+                       p = nid_page_nr(node, slot_getbasepfn(node, slot) -
+                                             slot_getbasepfn(node, 0));
 
                        /*
                         * Free valid memory in current slot.
index cac37589e35cbbf7bbd844a1b24392a080782148..2886ad70db48a5d44eb16fb8aa9aa4262c701d4f 100644 (file)
@@ -506,7 +506,7 @@ void show_mem(void)
                for (j = node_start_pfn(i); j < node_end_pfn(i); j++) {
                        struct page *p;
 
-                       p = node_mem_map(i) + j - node_start_pfn(i);
+                       p = nid_page_nr(i, j) - node_start_pfn(i);
 
                        total++;
                        if (PageReserved(p))
index 6fa1e6490b5747d9ece0de44a9ae4828156a4597..29dbe084c21ff8facd00870a360f5457dd599726 100644 (file)
@@ -98,7 +98,7 @@ void show_mem(void)
        printk("Free swap:       %6ldkB\n", nr_swap_pages<<(PAGE_SHIFT-10));
        for_each_pgdat(pgdat) {
                for (i = 0; i < pgdat->node_spanned_pages; i++) {
-                       page = pgdat->node_mem_map + i;
+                       page = pgdat_page_nr(pgdat, i);
                        total++;
                        if (PageReserved(page))
                                reserved++;
@@ -654,7 +654,7 @@ void __init mem_init(void)
 
        for_each_pgdat(pgdat) {
                for (i = 0; i < pgdat->node_spanned_pages; i++) {
-                       page = pgdat->node_mem_map + i;
+                       page = pgdat_page_nr(pgdat, i);
                        if (PageReserved(page))
                                reservedpages++;
                }
index 726c150dcbe490476a31e49d71208a31d7c82933..a011ef4cf3d3f4ee5ee16c320cc3bbed622e3b7f 100644 (file)
@@ -57,7 +57,6 @@ PLAT_NODE_DATA_LOCALNR(unsigned long p, int n)
  * Given a kernel address, find the home node of the underlying memory.
  */
 #define kvaddr_to_nid(kaddr)   pa_to_nid(__pa(kaddr))
-#define node_mem_map(nid)      (NODE_DATA(nid)->node_mem_map)
 #define node_start_pfn(nid)    (NODE_DATA(nid)->node_start_pfn)
 
 #define local_mapnr(kvaddr) \
@@ -108,7 +107,7 @@ PLAT_NODE_DATA_LOCALNR(unsigned long p, int n)
 #define pfn_to_page(pfn)                                               \
 ({                                                                     \
        unsigned long kaddr = (unsigned long)__va((pfn) << PAGE_SHIFT); \
-       (node_mem_map(kvaddr_to_nid(kaddr)) + local_mapnr(kaddr));      \
+       (NODE_DATA(kvaddr_to_nid(kaddr))->node_mem_map + local_mapnr(kaddr));   \
 })
 
 #define page_to_pfn(page)                                              \
index 13830ae67caca65fc5250ce7d425689ad6bde0dd..9cec191f462c2ae0ed1175aec4b25f34d991c7dc 100644 (file)
@@ -79,7 +79,6 @@ static inline int pfn_to_nid(unsigned long pfn)
  */
 #define kvaddr_to_nid(kaddr)   pfn_to_nid(__pa(kaddr) >> PAGE_SHIFT)
 
-#define node_mem_map(nid)      (NODE_DATA(nid)->node_mem_map)
 #define node_start_pfn(nid)    (NODE_DATA(nid)->node_start_pfn)
 #define node_end_pfn(nid)                                              \
 ({                                                                     \
@@ -100,7 +99,7 @@ static inline int pfn_to_nid(unsigned long pfn)
 ({                                                                     \
        unsigned long __pfn = pfn;                                      \
        int __node  = pfn_to_nid(__pfn);                                \
-       &node_mem_map(__node)[node_localnr(__pfn,__node)];              \
+       &NODE_DATA(__node)->node_mem_map[node_localnr(__pfn,__node)];   \
 })
 
 #define page_to_pfn(pg)                                                        \
index ebf0228fec42298380646f13b6d507fda17689ea..d58878ec899ed005ae3863be23f3e8edb4b383ae 100644 (file)
@@ -14,7 +14,6 @@ extern struct pglist_data *node_data[];
 #define NODE_DATA(nid)         (node_data[nid])
 
 #define node_localnr(pfn, nid) ((pfn) - NODE_DATA(nid)->node_start_pfn)
-#define node_mem_map(nid)      (NODE_DATA(nid)->node_mem_map)
 #define node_start_pfn(nid)    (NODE_DATA(nid)->node_start_pfn)
 #define node_end_pfn(nid)                                              \
 ({                                                                     \
@@ -32,7 +31,7 @@ extern struct pglist_data *node_data[];
 ({                                                                     \
        unsigned long __pfn = pfn;                                      \
        int __node  = pfn_to_nid(__pfn);                                \
-       &node_mem_map(__node)[node_localnr(__pfn,__node)];              \
+       &NODE_DATA(__node)->node_mem_map[node_localnr(__pfn,__node)];   \
 })
 
 #define page_to_pfn(pg)                                                        \
index 928bf50c4693e2d5d31849f4f71c19f17187d93b..595d3dce120a66477f512dfddc6ff83159c5654c 100644 (file)
@@ -19,7 +19,6 @@ extern struct node_map_data node_data[];
  */
 #define kvaddr_to_nid(kaddr)   pfn_to_nid(__pa(kaddr) >> PAGE_SHIFT)
 
-#define node_mem_map(nid)      (NODE_DATA(nid)->node_mem_map)
 #define node_start_pfn(nid)    (NODE_DATA(nid)->node_start_pfn)
 #define node_end_pfn(nid)                                              \
 ({                                                                     \
@@ -38,7 +37,7 @@ extern struct node_map_data node_data[];
 ({                                                                     \
        unsigned long __pfn = (pfn);                                    \
        int __node  = pfn_to_nid(__pfn);                                \
-       &node_mem_map(__node)[node_localnr(__pfn,__node)];              \
+       &NODE_DATA(__node)->node_mem_map[node_localnr(__pfn,__node)];   \
 })
 
 #define page_to_pfn(pg)                                                        \
index 0619a41a3c9dd57734f7d8a419d6eddc0ec04f54..cbfc5ecfe87552c1ed21a0c9bf359cfbf841b6cf 100644 (file)
@@ -65,7 +65,6 @@ static inline int pa_to_nid(unsigned long pa)
  */
 #define kvaddr_to_nid(kaddr)   pa_to_nid(__pa(kaddr))
 
-#define node_mem_map(nid)      (NODE_DATA(nid)->node_mem_map)
 #define node_start_pfn(nid)    (NODE_DATA(nid)->node_start_pfn)
 #define node_end_pfn(nid)      (NODE_DATA(nid)->node_end_pfn)
 
@@ -76,7 +75,7 @@ static inline int pa_to_nid(unsigned long pa)
 #define discontigmem_pfn_to_page(pfn) \
 ({ \
        unsigned long __tmp = pfn; \
-       (node_mem_map(pfn_to_nid(__tmp)) + \
+       (NODE_DATA(pfn_to_nid(__tmp))->node_mem_map + \
         node_localnr(__tmp, pfn_to_nid(__tmp))); \
 })
 
index d95b7c240831656ffebeadf4e2cae47ee3646054..ca4fc3fe0dee41dad2706434ad1b1c5ef0b4b52b 100644 (file)
@@ -35,9 +35,6 @@ static inline __attribute__((pure)) int phys_to_nid(unsigned long addr)
 #define kvaddr_to_nid(kaddr)   phys_to_nid(__pa(kaddr))
 #define NODE_DATA(nid)         (node_data[nid])
 
-#define node_mem_map(nid)      (NODE_DATA(nid)->node_mem_map)
-
-#define node_mem_map(nid)      (NODE_DATA(nid)->node_mem_map)
 #define node_start_pfn(nid)    (NODE_DATA(nid)->node_start_pfn)
 #define node_end_pfn(nid)       (NODE_DATA(nid)->node_start_pfn + \
                                 NODE_DATA(nid)->node_spanned_pages)
@@ -50,7 +47,7 @@ static inline __attribute__((pure)) int phys_to_nid(unsigned long addr)
    (2.4 used to). */
 #define pfn_to_page(pfn) ({ \
        int nid = phys_to_nid(((unsigned long)(pfn)) << PAGE_SHIFT);    \
-       ((pfn) - node_start_pfn(nid)) + node_mem_map(nid);              \
+       ((pfn) - node_start_pfn(nid)) + NODE_DATA(nid)->node_mem_map;   \
 })
 
 #define page_to_pfn(page) \
index 4733d35d8223bf847bc6b31ff7e705da8adb45ce..b79633d3a97b5f0653f65df843b3c1fee75b1c32 100644 (file)
@@ -284,6 +284,8 @@ typedef struct pglist_data {
 
 #define node_present_pages(nid)        (NODE_DATA(nid)->node_present_pages)
 #define node_spanned_pages(nid)        (NODE_DATA(nid)->node_spanned_pages)
+#define pgdat_page_nr(pgdat, pagenr)   ((pgdat)->node_mem_map + (pagenr))
+#define nid_page_nr(nid, pagenr)       pgdat_page_nr(NODE_DATA(nid),(pagenr))
 
 extern struct pglist_data *pgdat_list;