[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20251218014531.3793471-1-mathieu.desnoyers@efficios.com>
Date: Wed, 17 Dec 2025 20:45:27 -0500
From: Mathieu Desnoyers <mathieu.desnoyers@...icios.com>
To: Boqun Feng <boqun.feng@...il.com>,
Joel Fernandes <joel@...lfernandes.org>,
"Paul E. McKenney" <paulmck@...nel.org>
Cc: linux-kernel@...r.kernel.org,
Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
Nicholas Piggin <npiggin@...il.com>,
Michael Ellerman <mpe@...erman.id.au>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Sebastian Andrzej Siewior <bigeasy@...utronix.de>,
Will Deacon <will@...nel.org>,
Peter Zijlstra <peterz@...radead.org>,
Alan Stern <stern@...land.harvard.edu>,
John Stultz <jstultz@...gle.com>,
Neeraj Upadhyay <Neeraj.Upadhyay@....com>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Frederic Weisbecker <frederic@...nel.org>,
Josh Triplett <josh@...htriplett.org>,
Uladzislau Rezki <urezki@...il.com>,
Steven Rostedt <rostedt@...dmis.org>,
Lai Jiangshan <jiangshanlai@...il.com>,
Zqiang <qiang.zhang1211@...il.com>,
Ingo Molnar <mingo@...hat.com>,
Waiman Long <longman@...hat.com>,
Mark Rutland <mark.rutland@....com>,
Thomas Gleixner <tglx@...utronix.de>,
Vlastimil Babka <vbabka@...e.cz>,
maged.michael@...il.com,
Mateusz Guzik <mjguzik@...il.com>,
Jonas Oberhauser <jonas.oberhauser@...weicloud.com>,
rcu@...r.kernel.org,
linux-mm@...ck.org,
lkmm@...ts.linux.dev
Subject: [RFC PATCH v4 0/4] Hazard Pointers
Hi,
Here is a revisited version of my Hazard Pointers series. Boqun, Joel,
if you guys have time to try it out with your use-cases it would be
great!
This new version does the following:
- It has 8 preallocated hazard pointer slots per CPU (one cache line),
- The hazard pointer user allocates a hazard pointer context variable
(typically on the stack), which contains the pointer to the slot *and*
a backup slot,
- When all the per-CPU slots are in use, fallback to the backup slot.
Chain the backup slot into per-CPU lists, each protected by a raw
spinlock.
- The hazard pointer synchronize does a piecewise iteration on the
per-CPU overflow slots lists, releasing the raw spinlock between
each list item. It uses a 64-bit generation counter to check for
concurrent list changes, and restart the traversal on generation
counter mismatch.
- There is a new CONFIG_PREEMPT_HAZPTR config option. When enabled,
the hazard pointer acquire/release adds and then removes the hazard
pointer context from a per-task linked list. On context switch, the
scheduler migrates the per-CPU slots used by the task to the backup
per-context slots, thus making sure the per-CPU slots are not used
by preempted and blocked tasks.
It is based on v6.18.1.
Review is very welcome,
Thanks,
Mathieu
Cc: Nicholas Piggin <npiggin@...il.com>
Cc: Michael Ellerman <mpe@...erman.id.au>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: Sebastian Andrzej Siewior <bigeasy@...utronix.de>
Cc: "Paul E. McKenney" <paulmck@...nel.org>
Cc: Will Deacon <will@...nel.org>
Cc: Peter Zijlstra <peterz@...radead.org>
Cc: Boqun Feng <boqun.feng@...il.com>
Cc: Alan Stern <stern@...land.harvard.edu>
Cc: John Stultz <jstultz@...gle.com>
Cc: Neeraj Upadhyay <Neeraj.Upadhyay@....com>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Andrew Morton <akpm@...ux-foundation.org>
Cc: Boqun Feng <boqun.feng@...il.com>
Cc: Frederic Weisbecker <frederic@...nel.org>
Cc: Joel Fernandes <joel@...lfernandes.org>
Cc: Josh Triplett <josh@...htriplett.org>
Cc: Uladzislau Rezki <urezki@...il.com>
Cc: Steven Rostedt <rostedt@...dmis.org>
Cc: Lai Jiangshan <jiangshanlai@...il.com>
Cc: Zqiang <qiang.zhang1211@...il.com>
Cc: Ingo Molnar <mingo@...hat.com>
Cc: Waiman Long <longman@...hat.com>
Cc: Mark Rutland <mark.rutland@....com>
Cc: Thomas Gleixner <tglx@...utronix.de>
Cc: Vlastimil Babka <vbabka@...e.cz>
Cc: maged.michael@...il.com
Cc: Mateusz Guzik <mjguzik@...il.com>
Cc: Jonas Oberhauser <jonas.oberhauser@...weicloud.com>
Cc: rcu@...r.kernel.org
Cc: linux-mm@...ck.org
Cc: lkmm@...ts.linux.dev
Mathieu Desnoyers (4):
compiler.h: Introduce ptr_eq() to preserve address dependency
Documentation: RCU: Refer to ptr_eq()
hazptr: Implement Hazard Pointers
hazptr: Migrate per-CPU slots to backup slot on context switch
Documentation/RCU/rcu_dereference.rst | 38 +++-
include/linux/compiler.h | 63 +++++++
include/linux/hazptr.h | 241 ++++++++++++++++++++++++++
include/linux/sched.h | 4 +
init/init_task.c | 3 +
init/main.c | 2 +
kernel/Kconfig.preempt | 10 ++
kernel/Makefile | 2 +-
kernel/fork.c | 3 +
kernel/hazptr.c | 150 ++++++++++++++++
kernel/sched/core.c | 2 +
11 files changed, 512 insertions(+), 6 deletions(-)
create mode 100644 include/linux/hazptr.h
create mode 100644 kernel/hazptr.c
--
2.39.5
Powered by blists - more mailing lists