From: Boqun Feng <boqun@kernel.org>
To: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: "Paul E . McKenney" <paulmck@kernel.org>,
linux-kernel@vger.kernel.org,
Bradley Morgan <brads@mainlining.org>,
Gary Guo <gary@garyguo.net>,
rcu@vger.kernel.org, lkmm@lists.linux.dev,
Lian Wang <lianux.mm@gmail.com>,
Kunwu Chan <kunwu.chan@gmail.com>
Subject: Re: [PATCH hazptr 4/4] hazptr: Introduce "try acquire" fast path, fallback to overflow list
Date: Sun, 27 Sep 2026 20:16:20 +0200 [thread overview]
Message-ID: <arlddI54CR7gNqCO@MacBook-0RXW5> (raw)
In-Reply-To: <e26f28e9-e83c-4b39-85f5-928a8097019f@efficios.com>
On Sun, Sep 27, 2026 at 01:36:54PM -0400, Mathieu Desnoyers wrote:
> On 2026-09-27 13:24, Boqun Feng wrote:
> > On Sun, Sep 27, 2026 at 01:15:39PM -0400, Mathieu Desnoyers wrote:
> > [...]
> > > > > @@ -196,16 +197,13 @@ void hazptr_scan_cpu_slots_period(void *addr, void *scan_wildcard)
> > > > > for_each_possible_cpu(cpu) {
> > > > > /*
> > > > > * Scan CPU slots.
> > > > > - * Forward progress against recurring wildcards is guaranteed
> > > > > - * by scanning for one wildcard while new elements use the
> > > > > - * other wildcard value (1UL vs 2UL).
> > > > > * Forward progress against recurring single hazard pointer
> > > > > * values is guaranteed by the fact that a hazard pointer
> > > > > * is not reclaimed nor reused until the scan for that hazard
> > > > > * pointer completes, which prevents a steady flow of readers
> > > > > * to acquire that same hazard pointer value.
> > > >
> > > > (Not a comment to this patch, but I think it's worth bringing up)
> > > >
> > > > I want to point out this is not true for the lockdep use case, because
> > > > the we need to protect a hash list deletion there, and we use the
> > > > address of the hash bucket there. It's proven fine in practice because
> > > > the readers are rare (we only call the reader is_dynamic_key() in
> > > > register_lock_class(), that is every time you have a new lock class to
> > > > register).
> > > >
> > > > Maybe what we want to say here is that "if the users guarantee no steady
> > > > flow of the same hazard pointer value, we guarantee forward progress".
> > > > Thoughts?
> > >
> > > AFAIU, your approach to protect lockdep linked lists is to use the
> > > address of the hash bucket to protect the traversal. As this address is
> > > invariant (global array item address), that address should be fine
> > > to fulfill hazptr requirements, but it has downsides: rather than
> > > protecting the specific nodes being retired, the whole hash chain is
> > > protected. This means that, as you point out, many readers retiring
> > > nodes from a given bucket (except the first node) could end up holding a
> > > continuous stream of hazptr for a given hazptr value, preventing
> > > progress of hazptr synchronize.
> > >
> > > It's also coarser: per-bucket rather than per-node.
> > >
> > > Am I missing something here ?
> > >
> >
> > No, you got it right, but as I said, we can use it in lockdep since the
> > readers are relatively rare, so not an issue here.
> >
> > > One honest question: is this pattern something we expect to
> > > see often ? If so, then we may want to introduce a notion of
> >
> > I honestly don't know. But in my opinion, we'd better focus on finding
> > more typical usage of hazptr (i.e. protecting actual object). So ...
> >
> > > hazptr protection "period" flip (similar to some RCU implementations),
> > > where we tag the low bit of the slot pointer (0 vs 1), and alternate
> > > between the two periods in synchronize. This would prevent a steady-flow
> > > of same-value readers from preventing synchronize forward progress.
> > >
> > > Thoughts ?
> > >
> >
> > ... I will say let's add it only if we have more users of this pattern.
> >
>
> I am concerned about this because many uses of RCU in the Linux
> kernel protects linked list traversals. Turning a RCU-protected list
> traversal into a hazptr protected traversal is not as simple as
> acquiring each hazptr hand in hand.
>
I actually don't think converting RCU usage into hazptr would be a good
starting point for finding good hazptr usage. RCU readers are faster,
and a lot of existing RCU users do want the reader side to be as fast as
possible. So even though this is a problem, but I don't think that's an
urgent problem to resolve. Of course, if one can find a faster hazptr
reader implemenation, then it may be a different story.
> Your own use-case for lockdep is indeed a linked list traversal,
> and you need to use a work-around: protect the address of the
> hash bucket head.
>
So the lockdep usage is IMO a very special case, but it does show the
advantages of hazptr.
> I'm just wondering if this work-around will end up being the
> "blessed" way for protecting linked list traversals with hazptr,
> or whether we should consider alternatives ?
>
It depends on how many uses of the linked list traversals really care
about the reader side performance. I'm not sure we can easily find
another one like lockdep. Hence I think we should only add the
optimization when we find more of such a usage. Make sense?
Personally, I also want to see a refcount-like usage for hazptr, that'll
be very exciting for me :D
Regards,
Boqun
> This ties into finding additional usage for hazptr, because linked
> lists are so prevalent in the kernel.
>
> Thanks,
>
> Mathieu
>
> > Regards,
> > Boqun
> >
> > > Thanks,
> > >
> > > Mathieu
> > >
> > > >
> > > > The rest looks good to me.
> > > >
> > > > Regards,
> > > > Boqun
> > > >
> > >
> > >
> > > --
> > > Mathieu Desnoyers
> > > EfficiOS Inc.
> > > https://www.efficios.com
>
>
> --
> Mathieu Desnoyers
> EfficiOS Inc.
> https://www.efficios.com
next prev parent reply other threads:[~2026-09-27 18:16 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-27 15:51 [PATCH hazptr 0/4] Hazard pointer updates Mathieu Desnoyers
2026-09-27 15:51 ` [PATCH hazptr 1/4] hazptr: Fix two-phase hazptr_synchronize race with detach Mathieu Desnoyers
2026-09-27 15:51 ` [PATCH hazptr 2/4] compiler.h: Introduce ptr_eq() to preserve address dependency Mathieu Desnoyers
2026-09-27 15:51 ` [PATCH hazptr 3/4] Documentation: RCU: Refer to ptr_eq() Mathieu Desnoyers
2026-09-27 15:51 ` [PATCH hazptr 4/4] hazptr: Introduce "try acquire" fast path, fallback to overflow list Mathieu Desnoyers
2026-09-27 16:40 ` Boqun Feng
2026-09-27 17:15 ` Mathieu Desnoyers
2026-09-27 17:24 ` Boqun Feng
2026-09-27 17:36 ` Mathieu Desnoyers
2026-09-27 18:16 ` Boqun Feng [this message]
2026-09-27 17:26 ` Boqun Feng
2026-09-27 22:39 ` Gary Guo
2026-09-28 9:12 ` Boqun Feng
2026-09-28 11:32 ` Gary Guo
2026-09-28 14:56 ` Bradley Morgan
2026-09-28 15:32 ` Boqun Feng
2026-09-28 9:27 ` Kunwu Chan
2026-09-27 16:07 ` [PATCH hazptr 0/4] Hazard pointer updates Bradley Morgan
2026-09-27 16:27 ` Mathieu Desnoyers
2026-09-27 16:33 ` Bradley Morgan
2026-09-27 16:45 ` Mathieu Desnoyers
2026-09-27 16:15 ` Boqun Feng
2026-09-27 16:20 ` Mathieu Desnoyers
2026-09-27 16:22 ` Bradley Morgan
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=arlddI54CR7gNqCO@MacBook-0RXW5 \
--to=boqun@kernel.org \
--cc=brads@mainlining.org \
--cc=gary@garyguo.net \
--cc=kunwu.chan@gmail.com \
--cc=lianux.mm@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lkmm@lists.linux.dev \
--cc=mathieu.desnoyers@efficios.com \
--cc=paulmck@kernel.org \
--cc=rcu@vger.kernel.org \
/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®