aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Steiner <steiner@sgi.com>2010-05-26 17:42:51 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-05-27 12:12:44 -0400
commit0ac0c0d0f837c499afd02a802f9cf52d3027fa3b (patch)
treec20a7306d4b727722556af1aa5565855686aee07
parent6adef3ebe570bcde67fd6c16101451ddde5712b5 (diff)
cpusets: randomize node rotor used in cpuset_mem_spread_node()
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] Signed-off-by: Jack Steiner <steiner@sgi.com> Signed-off-by: Lee Schermerhorn <lee.schermerhorn@hp.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> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--arch/x86/mm/numa.c17
-rw-r--r--include/linux/bitmap.h1
-rw-r--r--include/linux/nodemask.h8
-rw-r--r--kernel/fork.c4
-rw-r--r--lib/bitmap.c2
5 files changed, 31 insertions, 1 deletions
diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
index 550df481accd..10c27bb1e95f 100644
--- a/arch/x86/mm/numa.c
+++ b/arch/x86/mm/numa.c
@@ -2,6 +2,7 @@
2#include <linux/topology.h> 2#include <linux/topology.h>
3#include <linux/module.h> 3#include <linux/module.h>
4#include <linux/bootmem.h> 4#include <linux/bootmem.h>
5#include <linux/random.h>
5 6
6#ifdef CONFIG_DEBUG_PER_CPU_MAPS 7#ifdef CONFIG_DEBUG_PER_CPU_MAPS
7# define DBG(x...) printk(KERN_DEBUG x) 8# define DBG(x...) printk(KERN_DEBUG x)
@@ -65,3 +66,19 @@ const struct cpumask *cpumask_of_node(int node)
65} 66}
66EXPORT_SYMBOL(cpumask_of_node); 67EXPORT_SYMBOL(cpumask_of_node);
67#endif 68#endif
69
70/*
71 * Return the bit number of a random bit set in the nodemask.
72 * (returns -1 if nodemask is empty)
73 */
74int __node_random(const nodemask_t *maskp)
75{
76 int w, bit = -1;
77
78 w = nodes_weight(*maskp);
79 if (w)
80 bit = bitmap_ord_to_pos(maskp->bits,
81 get_random_int() % w, MAX_NUMNODES);
82 return bit;
83}
84EXPORT_SYMBOL(__node_random);
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index daf8c480c786..6fb2720882fc 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -141,6 +141,7 @@ extern int bitmap_find_free_region(unsigned long *bitmap, int bits, int order);
141extern void bitmap_release_region(unsigned long *bitmap, int pos, int order); 141extern void bitmap_release_region(unsigned long *bitmap, int pos, int order);
142extern int bitmap_allocate_region(unsigned long *bitmap, int pos, int order); 142extern int bitmap_allocate_region(unsigned long *bitmap, int pos, int order);
143extern void bitmap_copy_le(void *dst, const unsigned long *src, int nbits); 143extern void bitmap_copy_le(void *dst, const unsigned long *src, int nbits);
144extern int bitmap_ord_to_pos(const unsigned long *bitmap, int n, int bits);
144 145
145#define BITMAP_LAST_WORD_MASK(nbits) \ 146#define BITMAP_LAST_WORD_MASK(nbits) \
146( \ 147( \
diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h
index dba35e413371..8a8f1d09c133 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,10 @@ 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
436#define node_random(mask) __node_random(&(mask))
437extern int __node_random(const nodemask_t *maskp);
438
433#else 439#else
434 440
435static inline int node_state(int node, enum node_states state) 441static inline int node_state(int node, enum node_states state)
@@ -460,6 +466,8 @@ static inline int num_node_state(enum node_states state)
460 466
461#define node_set_online(node) node_set_state((node), N_ONLINE) 467#define node_set_online(node) node_set_state((node), N_ONLINE)
462#define node_set_offline(node) node_clear_state((node), N_ONLINE) 468#define node_set_offline(node) node_clear_state((node), N_ONLINE)
469
470static inline int node_random(const nodemask_t mask) { return 0; }
463#endif 471#endif
464 472
465#define node_online_map node_states[N_ONLINE] 473#define node_online_map node_states[N_ONLINE]
diff --git a/kernel/fork.c b/kernel/fork.c
index 4d57d9e3a6e9..2e9cc3139ec6 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1079,6 +1079,10 @@ static struct task_struct *copy_process(unsigned long clone_flags,
1079 } 1079 }
1080 mpol_fix_fork_child_flag(p); 1080 mpol_fix_fork_child_flag(p);
1081#endif 1081#endif
1082#ifdef CONFIG_CPUSETS
1083 p->cpuset_mem_spread_rotor = node_random(p->mems_allowed);
1084 p->cpuset_slab_spread_rotor = node_random(p->mems_allowed);
1085#endif
1082#ifdef CONFIG_TRACE_IRQFLAGS 1086#ifdef CONFIG_TRACE_IRQFLAGS
1083 p->irq_events = 0; 1087 p->irq_events = 0;
1084#ifdef __ARCH_WANT_INTERRUPTS_ON_CTXSW 1088#ifdef __ARCH_WANT_INTERRUPTS_ON_CTXSW
diff --git a/lib/bitmap.c b/lib/bitmap.c
index ffb78c916ccd..d7137e7e06e8 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -672,7 +672,7 @@ static int bitmap_pos_to_ord(const unsigned long *buf, int pos, int bits)
672 * 672 *
673 * The bit positions 0 through @bits are valid positions in @buf. 673 * The bit positions 0 through @bits are valid positions in @buf.
674 */ 674 */
675static int bitmap_ord_to_pos(const unsigned long *buf, int ord, int bits) 675int bitmap_ord_to_pos(const unsigned long *buf, int ord, int bits)
676{ 676{
677 int pos = 0; 677 int pos = 0;
678 678