diff options
author | Christoph Lameter <cl@linux-foundation.org> | 2009-06-16 18:32:15 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-06-16 22:47:35 -0400 |
commit | 62bc62a873116805774ffd37d7f86aa4faa832b1 (patch) | |
tree | 7f3f5b94b2d484a13ca27b8d3f6f54cfe126d7c0 | |
parent | 974709bdb2a34db378fc84140220f363f558d0d6 (diff) |
page allocator: use a pre-calculated value instead of num_online_nodes() in fast paths
num_online_nodes() is called in a number of places but most often by the
page allocator when deciding whether the zonelist needs to be filtered
based on cpusets or the zonelist cache. This is actually a heavy function
and touches a number of cache lines.
This patch stores the number of online nodes at boot time and updates the
value when nodes get onlined and offlined. The value is then used in a
number of important paths in place of num_online_nodes().
[rientjes@google.com: do not override definition of node_set_online() with macro]
Signed-off-by: Christoph Lameter <cl@linux-foundation.org>
Signed-off-by: Mel Gorman <mel@csn.ul.ie>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Nick Piggin <nickpiggin@yahoo.com.au>
Cc: Dave Hansen <dave@linux.vnet.ibm.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
Signed-off-by: David Rientjes <rientjes@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | include/linux/nodemask.h | 19 | ||||
-rw-r--r-- | mm/hugetlb.c | 4 | ||||
-rw-r--r-- | mm/page_alloc.c | 10 | ||||
-rw-r--r-- | mm/slub.c | 2 | ||||
-rw-r--r-- | net/sunrpc/svc.c | 2 |
5 files changed, 26 insertions, 11 deletions
diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h index 848025cd7087..829b94b156f2 100644 --- a/include/linux/nodemask.h +++ b/include/linux/nodemask.h | |||
@@ -408,6 +408,19 @@ static inline int num_node_state(enum node_states state) | |||
408 | #define next_online_node(nid) next_node((nid), node_states[N_ONLINE]) | 408 | #define next_online_node(nid) next_node((nid), node_states[N_ONLINE]) |
409 | 409 | ||
410 | extern int nr_node_ids; | 410 | extern int nr_node_ids; |
411 | extern int nr_online_nodes; | ||
412 | |||
413 | static inline void node_set_online(int nid) | ||
414 | { | ||
415 | node_set_state(nid, N_ONLINE); | ||
416 | nr_online_nodes = num_node_state(N_ONLINE); | ||
417 | } | ||
418 | |||
419 | static inline void node_set_offline(int nid) | ||
420 | { | ||
421 | node_clear_state(nid, N_ONLINE); | ||
422 | nr_online_nodes = num_node_state(N_ONLINE); | ||
423 | } | ||
411 | #else | 424 | #else |
412 | 425 | ||
413 | static inline int node_state(int node, enum node_states state) | 426 | static inline int node_state(int node, enum node_states state) |
@@ -434,7 +447,10 @@ static inline int num_node_state(enum node_states state) | |||
434 | #define first_online_node 0 | 447 | #define first_online_node 0 |
435 | #define next_online_node(nid) (MAX_NUMNODES) | 448 | #define next_online_node(nid) (MAX_NUMNODES) |
436 | #define nr_node_ids 1 | 449 | #define nr_node_ids 1 |
450 | #define nr_online_nodes 1 | ||
437 | 451 | ||
452 | #define node_set_online(node) node_set_state((node), N_ONLINE) | ||
453 | #define node_set_offline(node) node_clear_state((node), N_ONLINE) | ||
438 | #endif | 454 | #endif |
439 | 455 | ||
440 | #define node_online_map node_states[N_ONLINE] | 456 | #define node_online_map node_states[N_ONLINE] |
@@ -454,9 +470,6 @@ static inline int num_node_state(enum node_states state) | |||
454 | #define node_online(node) node_state((node), N_ONLINE) | 470 | #define node_online(node) node_state((node), N_ONLINE) |
455 | #define node_possible(node) node_state((node), N_POSSIBLE) | 471 | #define node_possible(node) node_state((node), N_POSSIBLE) |
456 | 472 | ||
457 | #define node_set_online(node) node_set_state((node), N_ONLINE) | ||
458 | #define node_set_offline(node) node_clear_state((node), N_ONLINE) | ||
459 | |||
460 | #define for_each_node(node) for_each_node_state(node, N_POSSIBLE) | 473 | #define for_each_node(node) for_each_node_state(node, N_POSSIBLE) |
461 | #define for_each_online_node(node) for_each_node_state(node, N_ONLINE) | 474 | #define for_each_online_node(node) for_each_node_state(node, N_ONLINE) |
462 | 475 | ||
diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 2f8241f300f5..7b9b6015b2ec 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c | |||
@@ -875,7 +875,7 @@ static void return_unused_surplus_pages(struct hstate *h, | |||
875 | * can no longer free unreserved surplus pages. This occurs when | 875 | * can no longer free unreserved surplus pages. This occurs when |
876 | * the nodes with surplus pages have no free pages. | 876 | * the nodes with surplus pages have no free pages. |
877 | */ | 877 | */ |
878 | unsigned long remaining_iterations = num_online_nodes(); | 878 | unsigned long remaining_iterations = nr_online_nodes; |
879 | 879 | ||
880 | /* Uncommit the reservation */ | 880 | /* Uncommit the reservation */ |
881 | h->resv_huge_pages -= unused_resv_pages; | 881 | h->resv_huge_pages -= unused_resv_pages; |
@@ -904,7 +904,7 @@ static void return_unused_surplus_pages(struct hstate *h, | |||
904 | h->surplus_huge_pages--; | 904 | h->surplus_huge_pages--; |
905 | h->surplus_huge_pages_node[nid]--; | 905 | h->surplus_huge_pages_node[nid]--; |
906 | nr_pages--; | 906 | nr_pages--; |
907 | remaining_iterations = num_online_nodes(); | 907 | remaining_iterations = nr_online_nodes; |
908 | } | 908 | } |
909 | } | 909 | } |
910 | } | 910 | } |
diff --git a/mm/page_alloc.c b/mm/page_alloc.c index e60e41474332..0c9f406e3c44 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c | |||
@@ -161,7 +161,9 @@ static unsigned long __meminitdata dma_reserve; | |||
161 | 161 | ||
162 | #if MAX_NUMNODES > 1 | 162 | #if MAX_NUMNODES > 1 |
163 | int nr_node_ids __read_mostly = MAX_NUMNODES; | 163 | int nr_node_ids __read_mostly = MAX_NUMNODES; |
164 | int nr_online_nodes __read_mostly = 1; | ||
164 | EXPORT_SYMBOL(nr_node_ids); | 165 | EXPORT_SYMBOL(nr_node_ids); |
166 | EXPORT_SYMBOL(nr_online_nodes); | ||
165 | #endif | 167 | #endif |
166 | 168 | ||
167 | int page_group_by_mobility_disabled __read_mostly; | 169 | int page_group_by_mobility_disabled __read_mostly; |
@@ -1466,7 +1468,7 @@ this_zone_full: | |||
1466 | if (NUMA_BUILD) | 1468 | if (NUMA_BUILD) |
1467 | zlc_mark_zone_full(zonelist, z); | 1469 | zlc_mark_zone_full(zonelist, z); |
1468 | try_next_zone: | 1470 | try_next_zone: |
1469 | if (NUMA_BUILD && !did_zlc_setup && num_online_nodes() > 1) { | 1471 | if (NUMA_BUILD && !did_zlc_setup && nr_online_nodes > 1) { |
1470 | /* | 1472 | /* |
1471 | * we do zlc_setup after the first zone is tried but only | 1473 | * we do zlc_setup after the first zone is tried but only |
1472 | * if there are multiple nodes make it worthwhile | 1474 | * if there are multiple nodes make it worthwhile |
@@ -2265,7 +2267,7 @@ int numa_zonelist_order_handler(ctl_table *table, int write, | |||
2265 | } | 2267 | } |
2266 | 2268 | ||
2267 | 2269 | ||
2268 | #define MAX_NODE_LOAD (num_online_nodes()) | 2270 | #define MAX_NODE_LOAD (nr_online_nodes) |
2269 | static int node_load[MAX_NUMNODES]; | 2271 | static int node_load[MAX_NUMNODES]; |
2270 | 2272 | ||
2271 | /** | 2273 | /** |
@@ -2474,7 +2476,7 @@ static void build_zonelists(pg_data_t *pgdat) | |||
2474 | 2476 | ||
2475 | /* NUMA-aware ordering of nodes */ | 2477 | /* NUMA-aware ordering of nodes */ |
2476 | local_node = pgdat->node_id; | 2478 | local_node = pgdat->node_id; |
2477 | load = num_online_nodes(); | 2479 | load = nr_online_nodes; |
2478 | prev_node = local_node; | 2480 | prev_node = local_node; |
2479 | nodes_clear(used_mask); | 2481 | nodes_clear(used_mask); |
2480 | 2482 | ||
@@ -2625,7 +2627,7 @@ void build_all_zonelists(void) | |||
2625 | 2627 | ||
2626 | printk("Built %i zonelists in %s order, mobility grouping %s. " | 2628 | printk("Built %i zonelists in %s order, mobility grouping %s. " |
2627 | "Total pages: %ld\n", | 2629 | "Total pages: %ld\n", |
2628 | num_online_nodes(), | 2630 | nr_online_nodes, |
2629 | zonelist_order_name[current_zonelist_order], | 2631 | zonelist_order_name[current_zonelist_order], |
2630 | page_group_by_mobility_disabled ? "off" : "on", | 2632 | page_group_by_mobility_disabled ? "off" : "on", |
2631 | vm_total_pages); | 2633 | vm_total_pages); |
@@ -3737,7 +3737,7 @@ static int list_locations(struct kmem_cache *s, char *buf, | |||
3737 | to_cpumask(l->cpus)); | 3737 | to_cpumask(l->cpus)); |
3738 | } | 3738 | } |
3739 | 3739 | ||
3740 | if (num_online_nodes() > 1 && !nodes_empty(l->nodes) && | 3740 | if (nr_online_nodes > 1 && !nodes_empty(l->nodes) && |
3741 | len < PAGE_SIZE - 60) { | 3741 | len < PAGE_SIZE - 60) { |
3742 | len += sprintf(buf + len, " nodes="); | 3742 | len += sprintf(buf + len, " nodes="); |
3743 | len += nodelist_scnprintf(buf + len, PAGE_SIZE - len - 50, | 3743 | len += nodelist_scnprintf(buf + len, PAGE_SIZE - len - 50, |
diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c index 8847add6ca16..5ed8931dfe98 100644 --- a/net/sunrpc/svc.c +++ b/net/sunrpc/svc.c | |||
@@ -124,7 +124,7 @@ svc_pool_map_choose_mode(void) | |||
124 | { | 124 | { |
125 | unsigned int node; | 125 | unsigned int node; |
126 | 126 | ||
127 | if (num_online_nodes() > 1) { | 127 | if (nr_online_nodes > 1) { |
128 | /* | 128 | /* |
129 | * Actually have multiple NUMA nodes, | 129 | * Actually have multiple NUMA nodes, |
130 | * so split pools on NUMA node boundaries | 130 | * so split pools on NUMA node boundaries |