Re: [PATCH] mm/page_alloc: skip shuffling and reporting for no-lock frees

From: Karl Mehltretter

Date: Wed Oct 21 2026 - 01:56:36 EST


On Tue, Oct 20, 2026 at 01:09:48PM +0100, Sebastian Andrzej Siewior wrote:
> On 2026-10-20 12:02:01 [+0200], Vlastimil Babka (SUSE) wrote:
> > > An instrumented PREEMPT_RT lockdep run forced a random-bit cache refill
> > > while calling free_pages_nolock() under a raw spinlock. The unpatched
> > > allocator reported:
> > >
> > > BUG: Invalid wait context
> > >
> > > The attempted lock was batched_entropy_u64.lock in get_random_u64().
> > > Lockdep showed the raw test lock and zone->lock both held.
> >
> > In slab we solved this by using prandom - commit a1e244a9f177 ("mm/slab: use
> > prandom if !allow_spin")
> > Could be better?
>
> I hated it at first but now that I looked longer at it, it is not that
> bad.
>

For v2 I can pass allow_spin to shuffle_pick_tail(), keep the cached
get_random_u64() path for ordinary frees and use per-CPU prandom for
FPI_NOLOCK.

For page reporting, the issue is NMI rather than raw spinlocks in
general. free_pages_nolock() may be called from NMI, while the reporting
path may queue delayed work. I would keep the FPI_NOLOCK check and add a
comment explaining it.

I will also put is_shuffle_order() first as suggested.

Karl