Re: [PATCH v2] slab: fix kmalloc_nolock() context check for PREEMPT_RT
From: Vlastimil Babka
Date: Wed Jan 14 2026 - 08:14:31 EST
On 1/13/26 19:00, Sebastian Andrzej Siewior wrote:
>
> I would say that despite the _nolock() suffix a local_lock() is still
> acquired. The !PREEMPT_RT does a trylock.
>
> As I noticed this myself today while looking at other patches, was the
> trylock removed on RT by accident, was it there only in an earlier
> version which was never merged and will it ever come back so we can go
> back to !nmi || !hardirq?
IIRC there was no version that would do always a trylock on RT (or maybe
there was some early one but run into trouble quickly?). The problem was
converting the slub code to deal with situations where initially trylock
suceeds in the given context, but then it's dropped and later needed again,
and failing that later trylock would be too complex to unwind. So instead we
do the local_lock_is_locked() check upfront and then trust that all nested
local_lock_cpu_slab()'s can't fail. And unfortunately this doesn't very play
well with RT semantics.
>
>> + */
>> return NULL;
>> retry:
>> if (unlikely(size > KMALLOC_MAX_CACHE_SIZE))
>>
>
> Sebastian