[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <a8e06076-3f66-441f-9ccb-0b368d95e1a1@paulmck-laptop>
Date: Thu, 26 Jun 2025 19:56:47 -0700
From: "Paul E. McKenney" <paulmck@...nel.org>
To: Boqun Feng <boqun.feng@...il.com>
Cc: Christoph Hellwig <hch@...radead.org>, linux-kernel@...r.kernel.org,
rcu@...r.kernel.org, lkmm@...ts.linux.dev,
Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...nel.org>, Will Deacon <will@...nel.org>,
Waiman Long <longman@...hat.com>,
Davidlohr Bueso <dave@...olabs.net>,
Josh Triplett <josh@...htriplett.org>,
Frederic Weisbecker <frederic@...nel.org>,
Neeraj Upadhyay <neeraj.upadhyay@...nel.org>,
Joel Fernandes <joelagnelf@...dia.com>,
Uladzislau Rezki <urezki@...il.com>,
Steven Rostedt <rostedt@...dmis.org>,
Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
Lai Jiangshan <jiangshanlai@...il.com>,
Zqiang <qiang.zhang@...ux.dev>, Breno Leitao <leitao@...ian.org>,
aeh@...a.com, netdev@...r.kernel.org, edumazet@...gle.com,
jhs@...atatu.com, kernel-team@...a.com,
Erik Lundgren <elundgren@...a.com>
Subject: Re: [PATCH 0/8] Introduce simple hazard pointers for lockdep
On Thu, Jun 26, 2025 at 08:47:25AM -0700, Boqun Feng wrote:
> On Thu, Jun 26, 2025 at 03:16:49AM -0700, Christoph Hellwig wrote:
> > On Wed, Jun 25, 2025 at 07:08:57AM -0700, Boqun Feng wrote:
> > > Sure, I will put one for the future version, here is the gist:
> >
> > Thanks a lot!
> >
> > > The updater's wait can finish immediately if no one is accessing 'a', in
> > > other words it doesn't need to wait for reader 2.
> >
> > So basically it is the RCU concept, but limited to protecting exactly
> > one pointer update per critical section with no ability for the read
> > to e.g. acquire a refcount on the objected pointed to by that pointer?
>
> For the current simple hazard pointer, yes. But simple hazard pointers
> is easily to extend so support reading:
>
> { gp is a global pointer }
>
> Reader Updater
> ====== =======
> g = shazptr_acquire(p):
> WRITE_ONCE(*this_cpu_ptr(slot), gp);
> smp_mb();
>
> if (READ_ONCE(gp) == *this_cpu_ptr(slot)) {
> // still being protected.
> <can read gp here>
> to_free = READ_ONCE(gp);
> WRITE_ONCE(gp, new);
> synchronize_shazptr(to_free):
> smp_mb();
> // wait on the slot of reader
> // CPU being 0.
> READ_ONCE(per_cpu(reader, slot));
> }
>
> shazptr_clear(g):
> WRITE_ONCE(*this_cpu_ptr(slot), NULL); // unblock synchronize_shazptr()
>
>
> Usually the shazptr_acqurie() + "pointer comparison"* is called
> shazptr_try_protect().
>
> I will add a document about this in the next version along with other
> bits of hazard pointers.
>
> [*]: The pointer comparison is more complicated topic, but Mathieu has
> figured out how to do it correctly:
>
> https://lore.kernel.org/lkml/20241008135034.1982519-2-mathieu.desnoyers@efficios.com/
It might be helpful to add that, at a high level, hazard pointers
are a scalable replacement for reference counting. At a similarly
high level, RCU is a scalable replacement for reader-writer locking.
At lower levels, there is considerable overlap in applicability, so that
you can use RCU to replace many reference-counting use cases and hazard
pointers to replace many reader-writer-locking use cases..
Plus, as both Mathieu and Boqun pointed out, both RCU and hazard pointers
can be combined with other synchronization mechanisms, including each
other.
Thanx, Paul
Powered by blists - more mailing lists