From: Yury Norov <yury.norov@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
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 18:59:22 -0400 [thread overview]
Message-ID: <aFHzSvlj1pqeSy6E@yury> (raw)
In-Reply-To: <20250617155056.5c1d292d8831e7c7a27c8e5f@linux-foundation.org>
On Tue, Jun 17, 2025 at 03:50:56PM -0700, Andrew Morton wrote:
> 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.
...
> 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?
Ahh... Indeed you're right.
Thanks, Andrew, I'll send v4
next prev parent reply other threads:[~2025-06-17 22:59 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
2025-06-17 22:59 ` Yury Norov [this message]
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=aFHzSvlj1pqeSy6E@yury \
--to=yury.norov@gmail.com \
--cc=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 \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.