From: Hao Li Date: Wed, 10 Dec 2025 00:26:31 +0000 (+0800) Subject: slub: keep empty main sheaf as spare in __pcs_replace_empty_main() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4b038a9670154e8bb4832d80f0f2b68b1b812171;p=thirdparty%2Fkernel%2Flinux.git slub: keep empty main sheaf as spare in __pcs_replace_empty_main() When __pcs_replace_empty_main() fails to obtain a full sheaf directly from the barn, it may either: - Refill an empty sheaf obtained via barn_get_empty_sheaf(), or - Allocate a brand new full sheaf via alloc_full_sheaf(). After reacquiring the per-CPU lock, if pcs->main is still empty and pcs->spare is NULL, the current code donates the empty main sheaf to the barn via barn_put_empty_sheaf() and installs the full sheaf as pcs->main, leaving pcs->spare unpopulated. Instead, keep the existing empty main sheaf locally as the spare: pcs->spare = pcs->main; pcs->main = full; This populates pcs->spare earlier, which can reduce future barn traffic. Suggested-by: Vlastimil Babka Signed-off-by: Hao Li Reviewed-by: Harry Yoo Signed-off-by: Vlastimil Babka Tested-by: Zhao Liu --- diff --git a/mm/slub.c b/mm/slub.c index afc3e511ff395..e90f3e558ae7d 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -5049,7 +5049,10 @@ __pcs_replace_empty_main(struct kmem_cache *s, struct slub_percpu_sheaves *pcs, */ if (pcs->main->size == 0) { - barn_put_empty_sheaf(barn, pcs->main); + if (!pcs->spare) + pcs->spare = pcs->main; + else + barn_put_empty_sheaf(barn, pcs->main); pcs->main = full; return pcs; }