aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/linux/bitmap.h1
-rw-r--r--include/linux/nodemask.h13
-rw-r--r--kernel/cpuset.c8
-rw-r--r--kernel/fork.c4
-rw-r--r--lib/bitmap.c2
-rw-r--r--mm/mempolicy.c16
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);
144extern void bitmap_release_region(unsigned long *bitmap, int pos, int order); 144extern void bitmap_release_region(unsigned long *bitmap, int pos, int order);
145extern int bitmap_allocate_region(unsigned long *bitmap, int pos, int order); 145extern int bitmap_allocate_region(unsigned long *bitmap, int pos, int order);
146extern void bitmap_copy_le(void *dst, const unsigned long *src, int nbits); 146extern void bitmap_copy_le(void *dst, const unsigned long *src, int nbits);
147extern 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
435static inline int node_state(int node, enum node_states state) 438static 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)
470extern int node_random(const nodemask_t *maskp);
471#else
472static 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
2461int cpuset_mem_spread_node(void) 2461int 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(&current->mems_allowed);
2466
2463 return cpuset_spread_node(&current->cpuset_mem_spread_rotor); 2467 return cpuset_spread_node(&current->cpuset_mem_spread_rotor);
2464} 2468}
2465 2469
2466int cpuset_slab_spread_node(void) 2470int 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(&current->mems_allowed);
2475
2468 return cpuset_spread_node(&current->cpuset_slab_spread_rotor); 2476 return cpuset_spread_node(&current->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 */
759static int bitmap_ord_to_pos(const unsigned long *buf, int ord, int bits) 759int 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 */
1653int 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)