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 1/3] bitmap: generalize node_random()
Date: Wed, 4 Jun 2025 17:46:59 -0400 [thread overview]
Message-ID: <aEC-04zhtWh04b_F@yury> (raw)
In-Reply-To: <20250604143442.37635ce63e50a7425a390c2e@linux-foundation.org>
On Wed, Jun 04, 2025 at 02:34:42PM -0700, Andrew Morton wrote:
> On Wed, 4 Jun 2025 17:21:21 -0400 Yury Norov <yury.norov@gmail.com> wrote:
>
> > Generalize node_random and make it available to general bitmaps and
> > cpumasks users.
>
> Seems sensible.
>
> > --- a/lib/find_bit.c
> > +++ b/lib/find_bit.c
> >
> > +unsigned long find_random_bit(const unsigned long *addr, unsigned long size)
> > +{
> > + int w = bitmap_weight(addr, size);
> > +
> > + switch (w) {
> > + case 0:
> > + return size;
> > + case 1:
> > + return find_first_bit(addr, size);
>
> Is the `1' special case useful? The `default' case should still work OK?
find_first_bit() is faster that find_nth_bit(), so this is a
performance optimization. See 3e061d924fe9c7b4 ("lib/nodemask: optimize
node_random for nodemask with single NUMA node").
> > + default:
> > + return find_nth_bit(addr, size, get_random_u32_below(w));
> > + }
> > +}
> > +EXPORT_SYMBOL(find_random_bit);
>
> Some kerneldoc, please?
Indeed, will send v2.
> Of course, the hard-coding of get_random_u32_below() might be
> unsuitable for some future potential callers but we can deal with that
> if it ever occurs.
Can you please elaborate?
Thanks,
Yury
next prev parent reply other threads:[~2025-06-04 21:47 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-04 21:21 [PATCH 0/3] bitmap: introduce find_random_bit() and use in clocksource Yury Norov
2025-06-04 21:21 ` [PATCH 1/3] bitmap: generalize node_random() Yury Norov
2025-06-04 21:34 ` Andrew Morton
2025-06-04 21:46 ` Yury Norov [this message]
2025-06-04 22:37 ` Andrew Morton
2025-06-04 21:21 ` [PATCH 2/3] cpumask: introduce cpumask_random() Yury Norov
2025-06-04 21:21 ` [PATCH 3/3] clocksource: improve randomness in clocksource_verify_choose_cpus() Yury Norov
2025-06-05 18:17 ` John Stultz
-- strict thread matches above, loose matches on Subject: below --
2025-06-08 19:45 [PATCH v2 0/3] bitmap: introduce find_random_bit() and use in clocksource Yury Norov
2025-06-08 19:45 ` [PATCH 1/3] bitmap: generalize node_random() Yury Norov
2025-06-08 21:44 ` kernel test robot
2025-06-09 14:28 ` 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=aEC-04zhtWh04b_F@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).