mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Harry Yoo <harry@kernel.org>
To: paulmck@kernel.org, "Vlastimil Babka (SUSE)" <vbabka@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Hao Li <hao.li@linux.dev>, Christoph Lameter <cl@gentwo.org>,
	David Rientjes <rientjes@google.com>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Puranjay Mohan <puranjay@kernel.org>,
	Amery Hung <ameryhung@gmail.com>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Clark Williams <clrkwllms@kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Frederic Weisbecker <frederic@kernel.org>,
	Neeraj Upadhyay <neeraj.upadhyay@kernel.org>,
	Joel Fernandes <joelagnelf@nvidia.com>,
	Josh Triplett <josh@joshtriplett.org>,
	Boqun Feng <boqun@kernel.org>,
	Uladzislau Rezki <urezki@gmail.com>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Lai Jiangshan <jiangshanlai@gmail.com>,
	Zqiang <qiang.zhang@linux.dev>, Pedro Falcato <pfalcato@suse.de>,
	Suren Baghdasaryan <surenb@google.com>,
	Peter Zijlstra <peterz@infradead.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	linux-rt-devel@lists.linux.dev, rcu@vger.kernel.org,
	bpf@vger.kernel.org
Subject: Re: [PATCH for-next v3 6/9] mm/slab: allow kfree_rcu_sheaf() on PREEMPT_RT
Date: Thu, 18 Jun 2026 21:46:04 +0900	[thread overview]
Message-ID: <39758d58-f646-470c-9c35-818ac75427d3@kernel.org> (raw)
In-Reply-To: <03da8742-3790-4428-84b8-11911bf44c9e@paulmck-laptop>


[-- Attachment #1.1: Type: text/plain, Size: 4166 bytes --]



On 6/18/26 5:40 AM, Paul E. McKenney wrote:
> On Wed, Jun 17, 2026 at 07:38:16AM +0200, Vlastimil Babka (SUSE) wrote:
>> On 6/17/26 07:14, Harry Yoo wrote:
>>> On 6/17/26 2:24 AM, Vlastimil Babka (SUSE) wrote:
>>>> On 6/15/26 13:06, Harry Yoo (Oracle) wrote:
>>>>> As suggested by Vlastimil Babka, kfree_rcu_sheaf() can be used
>>>>> on PREEMPT_RT if we always assume spinning is not allowed on PREEMPT_RT.
>>>>> This is because local_trylock and spinlock_t are safe to use with
>>>>> trylock variant as long as the kernel does not spin and the context is
>>>>> not NMI and not hardirq.
>>>>>
>>>>> Now that __kfree_rcu_sheaf() knows how to handle allow_spin = false,
>>>>> relax the limitation and try the sheaves path on PREEMPT_RT as well.
>>>>>
>>>>> Keep the lockdep map on non RT kernels. However, do not use the lockdep
>>>>> map on PREEMPT_RT to avoid suppressing valid lockdep warnings.
>>>>>
>>>>> Link: https://lore.kernel.org/linux-mm/6811cc17-8ee4-48c8-8cbf-6bf4d9f98162@kernel.org
>>>>> Suggested-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
>>>>> Signed-off-by: Harry Yoo (Oracle) <harry@kernel.org>
>>>>
>>>> LGTM, but maybe unnecessary pessimistic wrt call_rcu() on PREEMPT_RT?
>>>> I thought (in the Link: above) we'd only need to downgrade allow_spin to
>>>> false on PREEMPT_RT for handling sheaves movement from/to barn and
>>>> alloc_empty_sheaf(), but call_rcu() would be safe from kfree_rcu() even on
>>>> RT?
>>>
>>> Indeed. Good point, thanks!
>>>
>>> Hmm, but I'm not sure that it's worth the complexity given that
>>> PREEMPT_RT tries very hard to avoid disabling IRQs...
>>>
>>>> Or is the irqs_disabled() condition rare enough so we don't care?
>>>
>>> Given that most users don't call kfree_rcu() under raw spinlock or
>>> IRQs-disabled section on PREEMPT_RT, I think it's okay to keep it as is
>>> (it's not making things worse, at least) and wait for call_rcu_nolock()?
>>
>> Sounds good.
>>
>>> On a side note, I don't have much idea on what needs to call kfree_rcu()
>>> under a raw spinlock, other than set_cpus_allowed_force(), which should
>>> really be using kfree_nolock() instead of kfree_rcu() once we support
>>> kmalloc() -> kfree_nolock():
>>
>> Looks like the case. Well if the fallback path of kfree_nolock() that is
>> irq_work_queue() is indeed safe here.
>>
>>>> 	/*
>>>> 	 * Because this is called with p->pi_lock held, it is not possible
>>>> 	 * to use kfree() here (when PREEMPT_RT=y), therefore punt to using
>>>> 	 * kfree_rcu().
>>>> 	 */
>>>> 	kfree_rcu((union cpumask_rcuhead *)ac.user_mask, rcu);
>>>
>>> Any thoughts, RCU/RT folks? 

Thanks for looking into it, Paul!

Perhaps I'm missing some context here... let me clarify.

> For the call_rcu*() counterparts, I am currently considering making the
> existing functions check for interrupts disabled, using irq_work_queue()
> in that case. 

Ack.

> I suppose that I could use raise_softirq() in the
> use_softirq=1 case when in_hardirq(). 

Ack.

> Either way, the check should be
> cheap compared to rest of the processing.

Agreed.

> The additional rcu_barrier() work required is of course way down in

Assuming "The additional rcu_barrier() work required" means
rcu_barrier() now needs to wait for all CPUs to complete irq_work or
softirq...

> the noise compared to acquiring a global mutex.

Are you referring to a specific mutex, or just in general?

> In your case, kfree_rcu() can be quite a bit lighter weight, though.
> So the extra checks might not be lost in the noise.

Assuming "the extra checks" means checking whether interrupts are
disabled in call_rcu()*...

It will probably be fine since we invoke call_rcu() only when sheaves
become full, not once for each object?

Perhaps slightly off-topic; at some point, though, I think it'd be
better to teach SLUB to use RCU polling API for RCU sheaves.

e.g.) put sheaves into barn->sheaves_pending instead of invoking
call_rcu(), and the SLUB alloc slowpath checks if there are sheaves
past grace period before allocating and refilling sheaves.

-- 
Cheers,
Harry / Hyeonggon

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply	other threads:[~2026-06-18 12:46 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-15 11:05 [PATCH for-next v3 0/9] mm/slab: introduce kfree_rcu_nolock() and improve slub_kunit coverage Harry Yoo (Oracle)
2026-06-15 11:05 ` [PATCH for-next v3 1/9] slub_kunit: fall back to SW perf events when HW PMU is not available Harry Yoo (Oracle)
2026-06-15 11:14   ` sashiko-bot
2026-06-15 12:58   ` Harry Yoo
2026-06-15 20:01   ` Alexei Starovoitov
2026-06-16  5:23     ` Harry Yoo
2026-06-15 11:05 ` [PATCH for-next v3 2/9] mm/slab, slub_kunit: register kprobe to trigger _nolock APIs Harry Yoo (Oracle)
2026-06-15 11:25   ` sashiko-bot
2026-06-15 20:04   ` Alexei Starovoitov
2026-06-16  6:57   ` Vlastimil Babka (SUSE)
2026-06-24 13:41   ` Pedro Falcato
2026-06-29  7:34     ` Harry Yoo
2026-06-29  8:20       ` Harry Yoo
2026-06-15 11:05 ` [PATCH for-next v3 3/9] mm/slab: handle the !allow_spin case in kfree_rcu_sheaf() Harry Yoo (Oracle)
2026-06-15 11:24   ` sashiko-bot
2026-06-16  7:55   ` Vlastimil Babka (SUSE)
2026-06-16  9:20     ` Vlastimil Babka (SUSE)
2026-06-17  5:32     ` Harry Yoo
2026-06-17  5:58       ` Vlastimil Babka (SUSE)
2026-06-24 14:28   ` Pedro Falcato
2026-06-29  8:01     ` Harry Yoo
2026-06-15 11:05 ` [PATCH for-next v3 4/9] mm/slab: use call_rcu() in unknown context if irqs are enabled Harry Yoo (Oracle)
2026-06-15 11:25   ` sashiko-bot
2026-06-16  9:51   ` Vlastimil Babka (SUSE)
2026-06-24 14:30   ` Pedro Falcato
2026-06-29  8:19     ` Harry Yoo
2026-06-15 11:05 ` [PATCH for-next v3 5/9] mm/slab: extend deferred free mechanism to handle rcu sheaves Harry Yoo (Oracle)
2026-06-15 11:24   ` sashiko-bot
2026-06-16 13:03   ` Vlastimil Babka (SUSE)
2026-06-24 14:37   ` Pedro Falcato
2026-06-15 11:06 ` [PATCH for-next v3 6/9] mm/slab: allow kfree_rcu_sheaf() on PREEMPT_RT Harry Yoo (Oracle)
2026-06-15 11:19   ` sashiko-bot
2026-06-16 17:24   ` Vlastimil Babka (SUSE)
2026-06-17  5:14     ` Harry Yoo
2026-06-17  5:38       ` Vlastimil Babka (SUSE)
2026-06-17 20:40         ` Paul E. McKenney
2026-06-18 12:46           ` Harry Yoo [this message]
2026-06-18 16:26             ` Paul E. McKenney
2026-06-15 11:06 ` [PATCH for-next v3 7/9] mm/slab: introduce kfree_rcu_nolock() Harry Yoo (Oracle)
2026-06-15 11:22   ` sashiko-bot
2026-06-16 17:28   ` Vlastimil Babka (SUSE)
2026-06-21  0:29   ` XIAO WU
2026-06-22  5:28     ` Harry Yoo
2026-06-22 14:56       ` XIAO WU
2026-06-25  5:27         ` Harry Yoo
2026-06-15 11:06 ` [PATCH for-next v3 8/9] mm/slab: introduce struct kfree_rcu_head and use in kfree_rcu_nolock() Harry Yoo (Oracle)
2026-06-15 11:22   ` sashiko-bot
2026-06-16 17:36   ` Vlastimil Babka (SUSE)
2026-06-15 11:06 ` [PATCH for-next v3 9/9] slub_kunit: extend the test for kfree_rcu_nolock() Harry Yoo (Oracle)
2026-06-16 17:38   ` Vlastimil Babka (SUSE)
2026-06-15 11:43 ` [PATCH for-next v3 0/9] mm/slab: introduce kfree_rcu_nolock() and improve slub_kunit coverage Harry Yoo
2026-06-15 20:28 ` Alexei Starovoitov
2026-06-16  4:57   ` Harry Yoo

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=39758d58-f646-470c-9c35-818ac75427d3@kernel.org \
    --to=harry@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=ameryhung@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bigeasy@linutronix.de \
    --cc=boqun@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=cl@gentwo.org \
    --cc=clrkwllms@kernel.org \
    --cc=frederic@kernel.org \
    --cc=hao.li@linux.dev \
    --cc=jiangshanlai@gmail.com \
    --cc=joelagnelf@nvidia.com \
    --cc=josh@joshtriplett.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=neeraj.upadhyay@kernel.org \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=pfalcato@suse.de \
    --cc=puranjay@kernel.org \
    --cc=qiang.zhang@linux.dev \
    --cc=rcu@vger.kernel.org \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=rostedt@goodmis.org \
    --cc=surenb@google.com \
    --cc=urezki@gmail.com \
    --cc=vbabka@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®