From: Andrew Morton <akpm@linux-foundation.org>
To: Yury Norov <yury.norov@gmail.com>
Cc: linux-kernel@vger.kernel.org,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
John Stultz <jstultz@google.com>,
Thomas Gleixner <tglx@linutronix.de>,
Stephen Boyd <sboyd@kernel.org>
Subject: Re: [PATCH v3 1/3] bitmap: generalize node_random()
Date: Tue, 17 Jun 2025 15:50:56 -0700 [thread overview]
Message-ID: <20250617155056.5c1d292d8831e7c7a27c8e5f@linux-foundation.org> (raw)
In-Reply-To: <20250617200854.60753-2-yury.norov@gmail.com>
On Tue, 17 Jun 2025 16:08:51 -0400 Yury Norov <yury.norov@gmail.com> wrote:
> From: "Yury Norov [NVIDIA]" <yury.norov@gmail.com>
>
> 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").
>
> ...
>
> --- a/include/linux/nodemask.h
> +++ b/include/linux/nodemask.h
> @@ -492,21 +492,7 @@ 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;
If the mask has no bits set, return -1.
> - 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;
> + return find_random_bit(maskp->bits, MAX_NUMNODES);
>
> ...
>
> +unsigned long find_random_bit(const unsigned long *addr, unsigned long size)
> +{
> + int w = bitmap_weight(addr, size);
> +
> + switch (w) {
> + case 0:
> + return size;
If the mask has no bits set, return the mask's size.
> + case 1:
> + /* Performance trick for single-bit bitmaps */
> + return find_first_bit(addr, size);
> + default:
> + return find_nth_bit(addr, size, get_random_u32_below(w));
> + }
> +}
I'm not seeing how this is correct?
next prev parent reply other threads:[~2025-06-17 22:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-17 20:08 [PATCH v3 0/3] bitmap: introduce find_random_bit() and use in clocksource Yury Norov
2025-06-17 20:08 ` [PATCH v3 1/3] bitmap: generalize node_random() Yury Norov
2025-06-17 22:50 ` Andrew Morton [this message]
2025-06-17 22:59 ` Yury Norov
2025-06-17 20:08 ` [PATCH v3 2/3] cpumask: introduce cpumask_random() Yury Norov
2025-06-17 20:08 ` [PATCH v3 3/3] clocksource: Improve randomness in clocksource_verify_choose_cpus() Yury Norov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250617155056.5c1d292d8831e7c7a27c8e5f@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=jstultz@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=sboyd@kernel.org \
--cc=tglx@linutronix.de \
--cc=yury.norov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®