Re: [PATCH for-next v3 6/9] mm/slab: allow kfree_rcu_sheaf() on PREEMPT_RT

"Paul E. McKenney" <[email protected]>
Newsgroups org.kernel.vger.rcu,dev.linux.lists.linux-rt-devel,org.kernel.vger.bpf,org.kernel.vger.linux-kernel,org.kvack.linux-mm
Message-ID <03da8742-3790-4428-84b8-11911bf44c9e@paulmck-laptop>
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/[email protected]
> >>> Suggested-by: Vlastimil Babka (SUSE) <[email protected]>
> >>> Signed-off-by: Harry Yoo (Oracle) <[email protected]>
> >> 
> >> 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?

For the call_rcu*() counterparts, I am currently considering making the
existing functions check for interrupts disabled, using irq_work_queue()
in that case.  I suppose that I could use raise_softirq() in the
use_softirq=1 case when in_hardirq().  Either way, the check should be
cheap compared to rest of the processing.  The additional rcu_barrier()
work required is of course way down in the noise compared to acquiring
a global mutex.

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

Thoughts?

								Thanx, Paul
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.