Commit f183c478 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] for_each_pgdat macro

Patch from Robert Love.

This patch implements for_each_pgdat(pg_data_t *) which is a helper
macro to cleanup code that does a loop of the form:

        pgdat = pgdat_list;
        while(pgdat) {
	        /* ... */
	        pgdat = pgdat->node_next;
	}

and replace it with:

	for_each_pgdat(pgdat) {
		/* ... */
	}

This code is from Rik's 2.4-rmap patch and is by William Irwin.
parent a854c11b
...@@ -167,10 +167,10 @@ show_mem(void) ...@@ -167,10 +167,10 @@ show_mem(void)
#ifdef CONFIG_DISCONTIGMEM #ifdef CONFIG_DISCONTIGMEM
{ {
pg_data_t *pgdat = pgdat_list; pg_data_t *pgdat;
printk("Free swap: %6dkB\n", nr_swap_pages<<(PAGE_SHIFT-10)); printk("Free swap: %6dkB\n", nr_swap_pages<<(PAGE_SHIFT-10));
do { for_each_pgdat(pgdat) {
printk("Node ID: %d\n", pgdat->node_id); printk("Node ID: %d\n", pgdat->node_id);
for(i = 0; i < pgdat->node_size; i++) { for(i = 0; i < pgdat->node_size; i++) {
if (PageReserved(pgdat->node_mem_map+i)) if (PageReserved(pgdat->node_mem_map+i))
...@@ -184,8 +184,7 @@ show_mem(void) ...@@ -184,8 +184,7 @@ show_mem(void)
printk("\t%d reserved pages\n", reserved); printk("\t%d reserved pages\n", reserved);
printk("\t%d pages shared\n", shared); printk("\t%d pages shared\n", shared);
printk("\t%d pages swap cached\n", cached); printk("\t%d pages swap cached\n", cached);
pgdat = pgdat->node_next; }
} while (pgdat);
printk("Total of %ld pages in page table cache\n", pgtable_cache_size); printk("Total of %ld pages in page table cache\n", pgtable_cache_size);
printk("%d free buffer pages\n", nr_free_buffer_pages()); printk("%d free buffer pages\n", nr_free_buffer_pages());
} }
......
...@@ -136,7 +136,7 @@ typedef struct pglist_data { ...@@ -136,7 +136,7 @@ typedef struct pglist_data {
unsigned long node_start_mapnr; unsigned long node_start_mapnr;
unsigned long node_size; unsigned long node_size;
int node_id; int node_id;
struct pglist_data *node_next; struct pglist_data *pgdat_next;
} pg_data_t; } pg_data_t;
extern int numnodes; extern int numnodes;
...@@ -163,6 +163,20 @@ extern void free_area_init_core(int nid, pg_data_t *pgdat, struct page **gmap, ...@@ -163,6 +163,20 @@ extern void free_area_init_core(int nid, pg_data_t *pgdat, struct page **gmap,
extern pg_data_t contig_page_data; extern pg_data_t contig_page_data;
/**
* for_each_pgdat - helper macro to iterate over all nodes
* @pgdat - pointer to a pg_data_t variable
*
* Meant to help with common loops of the form
* pgdat = pgdat_list;
* while(pgdat) {
* ...
* pgdat = pgdat->pgdat_next;
* }
*/
#define for_each_pgdat(pgdat) \
for (pgdat = pgdat_list; pgdat; pgdat = pgdat->pgdat_next)
#ifndef CONFIG_DISCONTIGMEM #ifndef CONFIG_DISCONTIGMEM
#define NODE_DATA(nid) (&contig_page_data) #define NODE_DATA(nid) (&contig_page_data)
......
...@@ -49,7 +49,7 @@ static unsigned long __init init_bootmem_core (pg_data_t *pgdat, ...@@ -49,7 +49,7 @@ static unsigned long __init init_bootmem_core (pg_data_t *pgdat,
bootmem_data_t *bdata = pgdat->bdata; bootmem_data_t *bdata = pgdat->bdata;
unsigned long mapsize = ((end - start)+7)/8; unsigned long mapsize = ((end - start)+7)/8;
pgdat->node_next = pgdat_list; pgdat->pgdat_next = pgdat_list;
pgdat_list = pgdat; pgdat_list = pgdat;
mapsize = (mapsize + (sizeof(long) - 1UL)) & ~(sizeof(long) - 1UL); mapsize = (mapsize + (sizeof(long) - 1UL)) & ~(sizeof(long) - 1UL);
...@@ -339,12 +339,11 @@ void * __init __alloc_bootmem (unsigned long size, unsigned long align, unsigned ...@@ -339,12 +339,11 @@ void * __init __alloc_bootmem (unsigned long size, unsigned long align, unsigned
pg_data_t *pgdat = pgdat_list; pg_data_t *pgdat = pgdat_list;
void *ptr; void *ptr;
while (pgdat) { for_each_pgdat(pgdat)
if ((ptr = __alloc_bootmem_core(pgdat->bdata, size, if ((ptr = __alloc_bootmem_core(pgdat->bdata, size,
align, goal))) align, goal)))
return(ptr); return(ptr);
pgdat = pgdat->node_next;
}
/* /*
* Whoops, we cannot satisfy the allocation request. * Whoops, we cannot satisfy the allocation request.
*/ */
......
...@@ -98,19 +98,19 @@ struct page * _alloc_pages(unsigned int gfp_mask, unsigned int order) ...@@ -98,19 +98,19 @@ struct page * _alloc_pages(unsigned int gfp_mask, unsigned int order)
if (!next) if (!next)
next = pgdat_list; next = pgdat_list;
temp = next; temp = next;
next = next->node_next; next = next->pgdat_next;
#endif #endif
start = temp; start = temp;
while (temp) { while (temp) {
if ((ret = alloc_pages_pgdat(temp, gfp_mask, order))) if ((ret = alloc_pages_pgdat(temp, gfp_mask, order)))
return(ret); return(ret);
temp = temp->node_next; temp = temp->pgdat_next;
} }
temp = pgdat_list; temp = pgdat_list;
while (temp != start) { while (temp != start) {
if ((ret = alloc_pages_pgdat(temp, gfp_mask, order))) if ((ret = alloc_pages_pgdat(temp, gfp_mask, order)))
return(ret); return(ret);
temp = temp->node_next; temp = temp->pgdat_next;
} }
return(0); return(0);
} }
......
...@@ -480,7 +480,7 @@ unsigned int nr_free_pages(void) ...@@ -480,7 +480,7 @@ unsigned int nr_free_pages(void)
unsigned int i, sum = 0; unsigned int i, sum = 0;
pg_data_t *pgdat; pg_data_t *pgdat;
for (pgdat = pgdat_list; pgdat; pgdat = pgdat->node_next) for (pgdat = pgdat_list; pgdat; pgdat = pgdat->pgdat_next)
for (i = 0; i < MAX_NR_ZONES; ++i) for (i = 0; i < MAX_NR_ZONES; ++i)
sum += pgdat->node_zones[i].free_pages; sum += pgdat->node_zones[i].free_pages;
...@@ -489,10 +489,10 @@ unsigned int nr_free_pages(void) ...@@ -489,10 +489,10 @@ unsigned int nr_free_pages(void)
static unsigned int nr_free_zone_pages(int offset) static unsigned int nr_free_zone_pages(int offset)
{ {
pg_data_t *pgdat = pgdat_list; pg_data_t *pgdat;
unsigned int sum = 0; unsigned int sum = 0;
do { for_each_pgdat(pgdat) {
zonelist_t *zonelist = pgdat->node_zonelists + offset; zonelist_t *zonelist = pgdat->node_zonelists + offset;
zone_t **zonep = zonelist->zones; zone_t **zonep = zonelist->zones;
zone_t *zone; zone_t *zone;
...@@ -503,9 +503,7 @@ static unsigned int nr_free_zone_pages(int offset) ...@@ -503,9 +503,7 @@ static unsigned int nr_free_zone_pages(int offset)
if (size > high) if (size > high)
sum += size - high; sum += size - high;
} }
}
pgdat = pgdat->node_next;
} while (pgdat);
return sum; return sum;
} }
...@@ -529,13 +527,12 @@ unsigned int nr_free_pagecache_pages(void) ...@@ -529,13 +527,12 @@ unsigned int nr_free_pagecache_pages(void)
#if CONFIG_HIGHMEM #if CONFIG_HIGHMEM
unsigned int nr_free_highpages (void) unsigned int nr_free_highpages (void)
{ {
pg_data_t *pgdat = pgdat_list; pg_data_t *pgdat;
unsigned int pages = 0; unsigned int pages = 0;
while (pgdat) { for_each_pgdat(pgdat)
pages += pgdat->node_zones[ZONE_HIGHMEM].free_pages; pages += pgdat->node_zones[ZONE_HIGHMEM].free_pages;
pgdat = pgdat->node_next;
}
return pages; return pages;
} }
#endif #endif
...@@ -613,7 +610,7 @@ void show_free_areas(void) ...@@ -613,7 +610,7 @@ void show_free_areas(void)
K(nr_free_pages()), K(nr_free_pages()),
K(nr_free_highpages())); K(nr_free_highpages()));
for (pgdat = pgdat_list; pgdat; pgdat = pgdat->node_next) for (pgdat = pgdat_list; pgdat; pgdat = pgdat->pgdat_next)
for (type = 0; type < MAX_NR_ZONES; ++type) { for (type = 0; type < MAX_NR_ZONES; ++type) {
zone_t *zone = &pgdat->node_zones[type]; zone_t *zone = &pgdat->node_zones[type];
printk("Zone:%s " printk("Zone:%s "
...@@ -635,7 +632,7 @@ void show_free_areas(void) ...@@ -635,7 +632,7 @@ void show_free_areas(void)
ps.nr_writeback, ps.nr_writeback,
nr_free_pages()); nr_free_pages());
for (pgdat = pgdat_list; pgdat; pgdat = pgdat->node_next) for (pgdat = pgdat_list; pgdat; pgdat = pgdat->pgdat_next)
for (type = 0; type < MAX_NR_ZONES; type++) { for (type = 0; type < MAX_NR_ZONES; type++) {
list_t *elem; list_t *elem;
zone_t *zone = &pgdat->node_zones[type]; zone_t *zone = &pgdat->node_zones[type];
......
...@@ -471,7 +471,7 @@ static void kswapd_balance(void) ...@@ -471,7 +471,7 @@ static void kswapd_balance(void)
pgdat = pgdat_list; pgdat = pgdat_list;
do do
need_more_balance |= kswapd_balance_pgdat(pgdat); need_more_balance |= kswapd_balance_pgdat(pgdat);
while ((pgdat = pgdat->node_next)); while ((pgdat = pgdat->pgdat_next));
} while (need_more_balance); } while (need_more_balance);
} }
...@@ -499,7 +499,7 @@ static int kswapd_can_sleep(void) ...@@ -499,7 +499,7 @@ static int kswapd_can_sleep(void)
if (kswapd_can_sleep_pgdat(pgdat)) if (kswapd_can_sleep_pgdat(pgdat))
continue; continue;
return 0; return 0;
} while ((pgdat = pgdat->node_next)); } while ((pgdat = pgdat->pgdat_next));
return 1; return 1;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment