diff options
| author | Yury Norov [NVIDIA] <yury.norov@gmail.com> | 2025-06-19 21:26:23 +0300 |
|---|---|---|
| committer | Yury Norov <yury.norov@gmail.com> | 2025-07-09 02:11:57 +0300 |
| commit | c56f97c5c71f17d781461d44acb777cd21521b81 (patch) | |
| tree | ba7b64c3d174d2978426d06e1a3e58eafb61c503 /include/linux | |
| parent | 733923397fd95405a48f165c9b1fbc8c4b0a4681 (diff) | |
| download | linux-c56f97c5c71f17d781461d44acb777cd21521b81.tar.xz | |
bitmap: generalize node_random()
Generalize node_random() and make it available to general bitmaps and
cpumasks users.
Notice, find_first_bit() is generally faster than find_nth_bit(), and we
employ it when there's a single set bit in the bitmap.
See commit 3e061d924fe9c7b4 ("lib/nodemask: optimize node_random for
nodemask with single NUMA node").
CC: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: "Yury Norov [NVIDIA]" <yury.norov@gmail.com>
Diffstat (limited to 'include/linux')
| -rw-r--r-- | include/linux/find.h | 2 | ||||
| -rw-r--r-- | include/linux/nodemask.h | 18 |
2 files changed, 5 insertions, 15 deletions
diff --git a/include/linux/find.h b/include/linux/find.h index 5a2c267ea7f9..98c61838002c 100644 --- a/include/linux/find.h +++ b/include/linux/find.h @@ -44,6 +44,8 @@ unsigned long _find_next_bit_le(const unsigned long *addr, unsigned long size, unsigned long offset); #endif +unsigned long find_random_bit(const unsigned long *addr, unsigned long size); + #ifndef find_next_bit /** * find_next_bit - find the next set bit in a memory region diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h index f08ae71585fa..7ad1f5c7407e 100644 --- a/include/linux/nodemask.h +++ b/include/linux/nodemask.h @@ -492,21 +492,9 @@ static __always_inline int num_node_state(enum node_states state) static __always_inline int node_random(const nodemask_t *maskp) { #if defined(CONFIG_NUMA) && (MAX_NUMNODES > 1) - int w, bit; - - w = nodes_weight(*maskp); - switch (w) { - case 0: - bit = NUMA_NO_NODE; - break; - case 1: - bit = first_node(*maskp); - break; - default: - bit = find_nth_bit(maskp->bits, MAX_NUMNODES, get_random_u32_below(w)); - break; - } - return bit; + int node = find_random_bit(maskp->bits, MAX_NUMNODES); + + return node < MAX_NUMNODES ? node : NUMA_NO_NODE; #else return 0; #endif |
