Re: [PATCH 1/3] mm/page_alloc: effectively disable pcp with CONFIG_SMP=n
From: Johannes Weiner
Date: Mon Mar 02 2026 - 12:13:03 EST
On Fri, Feb 27, 2026 at 06:07:58PM +0100, Vlastimil Babka wrote:
> The page allocator has been using a locking scheme for its percpu page
> caches (pcp) based on spin_trylock() with no _irqsave() part. The trick
> is that if we interrupt the locked section, we fail the trylock and just
> fallback to the slowpath taking the zone lock. That's more expensive,
> but rare, so we don't need to pay the irqsave/restore cost all the time
> in the fastpaths.
>
> It's similar to but not exactly local_trylock_t (which is also newer anyway)
> because in some cases we do lock the pcp of a non-local cpu to drain it, in
> a way that's cheaper than using IPI or queue_work_on().
>
> The complication of this scheme has been UP non-debug spinlock
> implementation which assumes spin_trylock() can't fail on UP and has no
> state to track whether it's locked. It just doesn't anticipate this
> usage scenario. So to work around that we disable IRQs only on UP,
> complicating the implementation. Also recently we found years old bug in
> where we didn't disable IRQs in related paths - see 038a102535eb
> ("mm/page_alloc: prevent pcp corruption with SMP=n").
>
> We can avoid this UP complication by realizing that we do not need the
> pcp caching for scalability on UP in the first place. Removing it
> completely with #ifdefs is not worth the trouble either. Just make
> pcp_spin_trylock() return NULL unconditionally on CONFIG_SMP=n. This
> makes the slowpaths unconditional, and we can remove the IRQ
> save/restore handling in pcp_spin_trylock()/unlock() completely.
>
> Suggested-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
> Signed-off-by: Vlastimil Babka (SUSE) <vbabka@xxxxxxxxxx>
Acked-by: Johannes Weiner <hannes@xxxxxxxxxxx>