Commit 89fa3024 authored by Christoph Lameter's avatar Christoph Lameter Committed by Linus Torvalds

[PATCH] NUMA: Add zone_to_nid function

There are many places where we need to determine the node of a zone.
Currently we use a difficult to read sequence of pointer dereferencing.
Put that into an inline function and use throughout VM.  Maybe we can find
a way to optimize the lookup in the future.
Signed-off-by: default avatarChristoph Lameter <clameter@sgi.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 4415cc8d
...@@ -422,7 +422,7 @@ void __init set_highmem_pages_init(int bad_ppro) ...@@ -422,7 +422,7 @@ void __init set_highmem_pages_init(int bad_ppro)
zone_end_pfn = zone_start_pfn + zone->spanned_pages; zone_end_pfn = zone_start_pfn + zone->spanned_pages;
printk("Initializing %s for node %d (%08lx:%08lx)\n", printk("Initializing %s for node %d (%08lx:%08lx)\n",
zone->name, zone->zone_pgdat->node_id, zone->name, zone_to_nid(zone),
zone_start_pfn, zone_end_pfn); zone_start_pfn, zone_end_pfn);
for (node_pfn = zone_start_pfn; node_pfn < zone_end_pfn; node_pfn++) { for (node_pfn = zone_start_pfn; node_pfn < zone_end_pfn; node_pfn++) {
......
...@@ -551,7 +551,7 @@ void show_mem(void) ...@@ -551,7 +551,7 @@ void show_mem(void)
printk("Zone list for zone %d on node %d: ", j, i); printk("Zone list for zone %d on node %d: ", j, i);
for (k = 0; zl->zones[k] != NULL; k++) for (k = 0; zl->zones[k] != NULL; k++)
printk("[%d/%s] ", zl->zones[k]->zone_pgdat->node_id, zl->zones[k]->name); printk("[%d/%s] ", zone_to_nid(zl->zones[k]), zl->zones[k]->name);
printk("\n"); printk("\n");
} }
} }
......
...@@ -499,12 +499,17 @@ static inline struct zone *page_zone(struct page *page) ...@@ -499,12 +499,17 @@ static inline struct zone *page_zone(struct page *page)
return zone_table[page_zone_id(page)]; return zone_table[page_zone_id(page)];
} }
static inline unsigned long zone_to_nid(struct zone *zone)
{
return zone->zone_pgdat->node_id;
}
static inline unsigned long page_to_nid(struct page *page) static inline unsigned long page_to_nid(struct page *page)
{ {
if (FLAGS_HAS_NODE) if (FLAGS_HAS_NODE)
return (page->flags >> NODES_PGSHIFT) & NODES_MASK; return (page->flags >> NODES_PGSHIFT) & NODES_MASK;
else else
return page_zone(page)->zone_pgdat->node_id; return zone_to_nid(page_zone(page));
} }
static inline unsigned long page_to_section(struct page *page) static inline unsigned long page_to_section(struct page *page)
{ {
......
...@@ -2245,7 +2245,7 @@ int cpuset_zonelist_valid_mems_allowed(struct zonelist *zl) ...@@ -2245,7 +2245,7 @@ int cpuset_zonelist_valid_mems_allowed(struct zonelist *zl)
int i; int i;
for (i = 0; zl->zones[i]; i++) { for (i = 0; zl->zones[i]; i++) {
int nid = zl->zones[i]->zone_pgdat->node_id; int nid = zone_to_nid(zl->zones[i]);
if (node_isset(nid, current->mems_allowed)) if (node_isset(nid, current->mems_allowed))
return 1; return 1;
...@@ -2318,7 +2318,7 @@ int __cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask) ...@@ -2318,7 +2318,7 @@ int __cpuset_zone_allowed(struct zone *z, gfp_t gfp_mask)
if (in_interrupt() || (gfp_mask & __GFP_THISNODE)) if (in_interrupt() || (gfp_mask & __GFP_THISNODE))
return 1; return 1;
node = z->zone_pgdat->node_id; node = zone_to_nid(z);
might_sleep_if(!(gfp_mask & __GFP_HARDWALL)); might_sleep_if(!(gfp_mask & __GFP_HARDWALL));
if (node_isset(node, current->mems_allowed)) if (node_isset(node, current->mems_allowed))
return 1; return 1;
......
...@@ -72,7 +72,7 @@ static struct page *dequeue_huge_page(struct vm_area_struct *vma, ...@@ -72,7 +72,7 @@ static struct page *dequeue_huge_page(struct vm_area_struct *vma,
struct zone **z; struct zone **z;
for (z = zonelist->zones; *z; z++) { for (z = zonelist->zones; *z; z++) {
nid = (*z)->zone_pgdat->node_id; nid = zone_to_nid(*z);
if (cpuset_zone_allowed(*z, GFP_HIGHUSER) && if (cpuset_zone_allowed(*z, GFP_HIGHUSER) &&
!list_empty(&hugepage_freelists[nid])) !list_empty(&hugepage_freelists[nid]))
break; break;
......
...@@ -487,7 +487,7 @@ static void get_zonemask(struct mempolicy *p, nodemask_t *nodes) ...@@ -487,7 +487,7 @@ static void get_zonemask(struct mempolicy *p, nodemask_t *nodes)
switch (p->policy) { switch (p->policy) {
case MPOL_BIND: case MPOL_BIND:
for (i = 0; p->v.zonelist->zones[i]; i++) for (i = 0; p->v.zonelist->zones[i]; i++)
node_set(p->v.zonelist->zones[i]->zone_pgdat->node_id, node_set(zone_to_nid(p->v.zonelist->zones[i]),
*nodes); *nodes);
break; break;
case MPOL_DEFAULT: case MPOL_DEFAULT:
...@@ -1145,7 +1145,7 @@ unsigned slab_node(struct mempolicy *policy) ...@@ -1145,7 +1145,7 @@ unsigned slab_node(struct mempolicy *policy)
* Follow bind policy behavior and start allocation at the * Follow bind policy behavior and start allocation at the
* first node. * first node.
*/ */
return policy->v.zonelist->zones[0]->zone_pgdat->node_id; return zone_to_nid(policy->v.zonelist->zones[0]);
case MPOL_PREFERRED: case MPOL_PREFERRED:
if (policy->v.preferred_node >= 0) if (policy->v.preferred_node >= 0)
...@@ -1649,7 +1649,7 @@ void mpol_rebind_policy(struct mempolicy *pol, const nodemask_t *newmask) ...@@ -1649,7 +1649,7 @@ void mpol_rebind_policy(struct mempolicy *pol, const nodemask_t *newmask)
nodes_clear(nodes); nodes_clear(nodes);
for (z = pol->v.zonelist->zones; *z; z++) for (z = pol->v.zonelist->zones; *z; z++)
node_set((*z)->zone_pgdat->node_id, nodes); node_set(zone_to_nid(*z), nodes);
nodes_remap(tmp, nodes, *mpolmask, *newmask); nodes_remap(tmp, nodes, *mpolmask, *newmask);
nodes = tmp; nodes = tmp;
......
...@@ -177,8 +177,7 @@ static inline int constrained_alloc(struct zonelist *zonelist, gfp_t gfp_mask) ...@@ -177,8 +177,7 @@ static inline int constrained_alloc(struct zonelist *zonelist, gfp_t gfp_mask)
for (z = zonelist->zones; *z; z++) for (z = zonelist->zones; *z; z++)
if (cpuset_zone_allowed(*z, gfp_mask)) if (cpuset_zone_allowed(*z, gfp_mask))
node_clear((*z)->zone_pgdat->node_id, node_clear(zone_to_nid(*z), nodes);
nodes);
else else
return CONSTRAINT_CPUSET; return CONSTRAINT_CPUSET;
......
...@@ -1217,7 +1217,7 @@ unsigned int nr_free_pagecache_pages(void) ...@@ -1217,7 +1217,7 @@ unsigned int nr_free_pagecache_pages(void)
#ifdef CONFIG_NUMA #ifdef CONFIG_NUMA
static void show_node(struct zone *zone) static void show_node(struct zone *zone)
{ {
printk("Node %d ", zone->zone_pgdat->node_id); printk("Node %ld ", zone_to_nid(zone));
} }
#else #else
#define show_node(zone) do { } while (0) #define show_node(zone) do { } while (0)
......
...@@ -1661,7 +1661,7 @@ int zone_reclaim(struct zone *zone, gfp_t gfp_mask, unsigned int order) ...@@ -1661,7 +1661,7 @@ int zone_reclaim(struct zone *zone, gfp_t gfp_mask, unsigned int order)
* over remote processors and spread off node memory allocations * over remote processors and spread off node memory allocations
* as wide as possible. * as wide as possible.
*/ */
node_id = zone->zone_pgdat->node_id; node_id = zone_to_nid(zone);
mask = node_to_cpumask(node_id); mask = node_to_cpumask(node_id);
if (!cpus_empty(mask) && node_id != numa_node_id()) if (!cpus_empty(mask) && node_id != numa_node_id())
return 0; return 0;
......
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