diff options
author | Michal Hocko <mhocko@suse.cz> | 2011-07-26 19:08:30 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-07-26 19:49:43 -0400 |
commit | 778d3b0ff0654ad7092bf823fd32010066b12365 (patch) | |
tree | cd0073d8c513e1c56fd6950c4ec985f16fd004ad | |
parent | 8521fc50d433507a7cdc96bec280f9e5888a54cc (diff) |
cpusets: randomize node rotor used in cpuset_mem_spread_node()
[ This patch has already been accepted as commit 0ac0c0d0f837 but later
reverted (commit 35926ff5fba8) because it itroduced arch specific
__node_random which was defined only for x86 code so it broke other
archs. This is a followup without any arch specific code. Other than
that there are no functional changes.]
Some workloads that create a large number of small files tend to assign
too many pages to node 0 (multi-node systems). Part of the reason is
that the rotor (in cpuset_mem_spread_node()) used to assign nodes starts
at node 0 for newly created tasks.
This patch changes the rotor to be initialized to a random node number
of the cpuset.
[akpm@linux-foundation.org: fix layout]
[Lee.Schermerhorn@hp.com: Define stub numa_random() for !NUMA configuration]
[mhocko@suse.cz: Make it arch independent]
[akpm@linux-foundation.org: fix CONFIG_NUMA=y, MAX_NUMNODES>1 build]
Signed-off-by: Jack Steiner <steiner@sgi.com>
Signed-off-by: Lee Schermerhorn <lee.schermerhorn@hp.com>
Signed-off-by: Michal Hocko <mhocko@suse.cz>
Reviewed-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Christoph Lameter <cl@linux-foundation.org>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Paul Menage <menage@google.com>
Cc: Jack Steiner <steiner@sgi.com>
Cc: Robin Holt <holt@sgi.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Christoph Lameter <cl@linux-foundation.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Jack Steiner <steiner@sgi.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Lee Schermerhorn <lee.schermerhorn@hp.com>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Paul Menage <menage@google.com>
Cc: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: Robin Holt <holt@sgi.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | include/linux/bitmap.h | 1 | ||||
-rw-r--r-- | include/linux/nodemask.h | 13 | ||||
-rw-r--r-- | kernel/cpuset.c | 8 | ||||
-rw-r--r-- | kernel/fork.c | 4 | ||||
-rw-r--r-- | lib/bitmap.c | 2 | ||||
-rw-r--r-- | mm/mempolicy.c | 16 |
6 files changed, 43 insertions, 1 deletions
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index dcafe0bf0005..3bac44cce142 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h | |||
@@ -144,6 +144,7 @@ extern int bitmap_find_free_region(unsigned long *bitmap, int bits, int order); | |||
144 | extern void bitmap_release_region(unsigned long *bitmap, int pos, int order); | 144 | extern void bitmap_release_region(unsigned long *bitmap, int pos, int order); |
145 | extern int bitmap_allocate_region(unsigned long *bitmap, int pos, int order); | 145 | extern int bitmap_allocate_region(unsigned long *bitmap, int pos, int order); |
146 | extern void bitmap_copy_le(void *dst, const unsigned long *src, int nbits); | 146 | extern void bitmap_copy_le(void *dst, const unsigned long *src, int nbits); |
147 | extern int bitmap_ord_to_pos(const unsigned long *bitmap, int n, int bits); | ||
147 | 148 | ||
148 | #define BITMAP_LAST_WORD_MASK(nbits) \ | 149 | #define BITMAP_LAST_WORD_MASK(nbits) \ |
149 | ( \ | 150 | ( \ |
diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h index dba35e413371..7afc36334d52 100644 --- a/include/linux/nodemask.h +++ b/include/linux/nodemask.h | |||
@@ -66,6 +66,8 @@ | |||
66 | * int num_online_nodes() Number of online Nodes | 66 | * int num_online_nodes() Number of online Nodes |
67 | * int num_possible_nodes() Number of all possible Nodes | 67 | * int num_possible_nodes() Number of all possible Nodes |
68 | * | 68 | * |
69 | * int node_random(mask) Random node with set bit in mask | ||
70 | * | ||
69 | * int node_online(node) Is some node online? | 71 | * int node_online(node) Is some node online? |
70 | * int node_possible(node) Is some node possible? | 72 | * int node_possible(node) Is some node possible? |
71 | * | 73 | * |
@@ -430,6 +432,7 @@ static inline void node_set_offline(int nid) | |||
430 | node_clear_state(nid, N_ONLINE); | 432 | node_clear_state(nid, N_ONLINE); |
431 | nr_online_nodes = num_node_state(N_ONLINE); | 433 | nr_online_nodes = num_node_state(N_ONLINE); |
432 | } | 434 | } |
435 | |||
433 | #else | 436 | #else |
434 | 437 | ||
435 | static inline int node_state(int node, enum node_states state) | 438 | static inline int node_state(int node, enum node_states state) |
@@ -460,6 +463,16 @@ static inline int num_node_state(enum node_states state) | |||
460 | 463 | ||
461 | #define node_set_online(node) node_set_state((node), N_ONLINE) | 464 | #define node_set_online(node) node_set_state((node), N_ONLINE) |
462 | #define node_set_offline(node) node_clear_state((node), N_ONLINE) | 465 | #define node_set_offline(node) node_clear_state((node), N_ONLINE) |
466 | |||
467 | #endif | ||
468 | |||
469 | #if defined(CONFIG_NUMA) && (MAX_NUMNODES > 1) | ||
470 | extern int node_random(const nodemask_t *maskp); | ||
471 | #else | ||
472 | static inline int node_random(const nodemask_t *mask) | ||
473 | { | ||
474 | return 0; | ||
475 | } | ||
463 | #endif | 476 | #endif |
464 | 477 | ||
465 | #define node_online_map node_states[N_ONLINE] | 478 | #define node_online_map node_states[N_ONLINE] |
diff --git a/kernel/cpuset.c b/kernel/cpuset.c index 9c9b7545c810..f8bc977ccbbe 100644 --- a/kernel/cpuset.c +++ b/kernel/cpuset.c | |||
@@ -2460,11 +2460,19 @@ static int cpuset_spread_node(int *rotor) | |||
2460 | 2460 | ||
2461 | int cpuset_mem_spread_node(void) | 2461 | int cpuset_mem_spread_node(void) |
2462 | { | 2462 | { |
2463 | if (current->cpuset_mem_spread_rotor == NUMA_NO_NODE) | ||
2464 | current->cpuset_mem_spread_rotor = | ||
2465 | node_random(¤t->mems_allowed); | ||
2466 | |||
2463 | return cpuset_spread_node(¤t->cpuset_mem_spread_rotor); | 2467 | return cpuset_spread_node(¤t->cpuset_mem_spread_rotor); |
2464 | } | 2468 | } |
2465 | 2469 | ||
2466 | int cpuset_slab_spread_node(void) | 2470 | int cpuset_slab_spread_node(void) |
2467 | { | 2471 | { |
2472 | if (current->cpuset_slab_spread_rotor == NUMA_NO_NODE) | ||
2473 | current->cpuset_slab_spread_rotor = | ||
2474 | node_random(¤t->mems_allowed); | ||
2475 | |||
2468 | return cpuset_spread_node(¤t->cpuset_slab_spread_rotor); | 2476 | return cpuset_spread_node(¤t->cpuset_slab_spread_rotor); |
2469 | } | 2477 | } |
2470 | 2478 | ||
diff --git a/kernel/fork.c b/kernel/fork.c index 17bf7c8d6511..e33177edb3bf 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
@@ -1173,6 +1173,10 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
1173 | } | 1173 | } |
1174 | mpol_fix_fork_child_flag(p); | 1174 | mpol_fix_fork_child_flag(p); |
1175 | #endif | 1175 | #endif |
1176 | #ifdef CONFIG_CPUSETS | ||
1177 | p->cpuset_mem_spread_rotor = NUMA_NO_NODE; | ||
1178 | p->cpuset_slab_spread_rotor = NUMA_NO_NODE; | ||
1179 | #endif | ||
1176 | #ifdef CONFIG_TRACE_IRQFLAGS | 1180 | #ifdef CONFIG_TRACE_IRQFLAGS |
1177 | p->irq_events = 0; | 1181 | p->irq_events = 0; |
1178 | #ifdef __ARCH_WANT_INTERRUPTS_ON_CTXSW | 1182 | #ifdef __ARCH_WANT_INTERRUPTS_ON_CTXSW |
diff --git a/lib/bitmap.c b/lib/bitmap.c index 3f3b68199d74..37ef4b048795 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c | |||
@@ -756,7 +756,7 @@ static int bitmap_pos_to_ord(const unsigned long *buf, int pos, int bits) | |||
756 | * | 756 | * |
757 | * The bit positions 0 through @bits are valid positions in @buf. | 757 | * The bit positions 0 through @bits are valid positions in @buf. |
758 | */ | 758 | */ |
759 | static int bitmap_ord_to_pos(const unsigned long *buf, int ord, int bits) | 759 | int bitmap_ord_to_pos(const unsigned long *buf, int ord, int bits) |
760 | { | 760 | { |
761 | int pos = 0; | 761 | int pos = 0; |
762 | 762 | ||
diff --git a/mm/mempolicy.c b/mm/mempolicy.c index e7fb9d25c54e..8b57173c1dd5 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c | |||
@@ -93,6 +93,7 @@ | |||
93 | 93 | ||
94 | #include <asm/tlbflush.h> | 94 | #include <asm/tlbflush.h> |
95 | #include <asm/uaccess.h> | 95 | #include <asm/uaccess.h> |
96 | #include <linux/random.h> | ||
96 | 97 | ||
97 | #include "internal.h" | 98 | #include "internal.h" |
98 | 99 | ||
@@ -1645,6 +1646,21 @@ static inline unsigned interleave_nid(struct mempolicy *pol, | |||
1645 | return interleave_nodes(pol); | 1646 | return interleave_nodes(pol); |
1646 | } | 1647 | } |
1647 | 1648 | ||
1649 | /* | ||
1650 | * Return the bit number of a random bit set in the nodemask. | ||
1651 | * (returns -1 if nodemask is empty) | ||
1652 | */ | ||
1653 | int node_random(const nodemask_t *maskp) | ||
1654 | { | ||
1655 | int w, bit = -1; | ||
1656 | |||
1657 | w = nodes_weight(*maskp); | ||
1658 | if (w) | ||
1659 | bit = bitmap_ord_to_pos(maskp->bits, | ||
1660 | get_random_int() % w, MAX_NUMNODES); | ||
1661 | return bit; | ||
1662 | } | ||
1663 | |||
1648 | #ifdef CONFIG_HUGETLBFS | 1664 | #ifdef CONFIG_HUGETLBFS |
1649 | /* | 1665 | /* |
1650 | * huge_zonelist(@vma, @addr, @gfp_flags, @mpol) | 1666 | * huge_zonelist(@vma, @addr, @gfp_flags, @mpol) |