]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
slab: remove alloc_full_sheaf()
authorVlastimil Babka (SUSE) <vbabka@kernel.org>
Wed, 11 Mar 2026 18:22:33 +0000 (19:22 +0100)
committerVlastimil Babka (SUSE) <vbabka@kernel.org>
Mon, 16 Mar 2026 13:13:46 +0000 (14:13 +0100)
The function allocates and then refills and empty sheaf. It's only
called from __pcs_replace_empty_main(), which can also in some cases
refill an empty sheaf. We can therefore consolidate this code.

Remove alloc_full_sheaf() and refactor __pcs_replace_empty_main() so it
will call alloc_empty_sheaf() when necessary, and then use the
pre-existing refill_sheaf(). The result should be simpler to follow and
less duplicated code.

Also adjust the comment about returning sheaves to barn, the part about
where the empty sheaf we'd be returning comes from is incorrect.

No functional change intended.

Reviewed-by: Qing Wang <wangqing7171@gmail.com>
Reviewed-by: Harry Yoo <harry.yoo@oracle.com>
Reviewed-by: Hao Li <hao.li@linux.dev>
Link: https://patch.msgid.link/20260311-b4-slab-remove-alloc_full_sheaf-v1-1-c4c5bb587ae5@kernel.org
Signed-off-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
mm/slub.c

index 2b2d33cc735cb6a0ad7eacb75fffc0816908a096..a8347b79e46fed0c35c6076bcbf03aa7b6d24cf8 100644 (file)
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -2822,24 +2822,6 @@ static int refill_sheaf(struct kmem_cache *s, struct slab_sheaf *sheaf,
        return 0;
 }
 
-static void sheaf_flush_unused(struct kmem_cache *s, struct slab_sheaf *sheaf);
-
-static struct slab_sheaf *alloc_full_sheaf(struct kmem_cache *s, gfp_t gfp)
-{
-       struct slab_sheaf *sheaf = alloc_empty_sheaf(s, gfp);
-
-       if (!sheaf)
-               return NULL;
-
-       if (refill_sheaf(s, sheaf, gfp | __GFP_NOMEMALLOC | __GFP_NOWARN)) {
-               sheaf_flush_unused(s, sheaf);
-               free_empty_sheaf(s, sheaf);
-               return NULL;
-       }
-
-       return sheaf;
-}
-
 /*
  * Maximum number of objects freed during a single flush of main pcs sheaf.
  * Translates directly to an on-stack array size.
@@ -4611,34 +4593,35 @@ __pcs_replace_empty_main(struct kmem_cache *s, struct slub_percpu_sheaves *pcs,
        if (!allow_spin)
                return NULL;
 
-       if (empty) {
-               if (!refill_sheaf(s, empty, gfp | __GFP_NOMEMALLOC | __GFP_NOWARN)) {
-                       full = empty;
-               } else {
-                       /*
-                        * we must be very low on memory so don't bother
-                        * with the barn
-                        */
-                       sheaf_flush_unused(s, empty);
-                       free_empty_sheaf(s, empty);
-               }
-       } else {
-               full = alloc_full_sheaf(s, gfp);
+       if (!empty) {
+               empty = alloc_empty_sheaf(s, gfp);
+               if (!empty)
+                       return NULL;
        }
 
-       if (!full)
+       if (refill_sheaf(s, empty, gfp | __GFP_NOMEMALLOC | __GFP_NOWARN)) {
+               /*
+                * we must be very low on memory so don't bother
+                * with the barn
+                */
+               sheaf_flush_unused(s, empty);
+               free_empty_sheaf(s, empty);
+
                return NULL;
+       }
+
+       full = empty;
+       empty = NULL;
 
        if (!local_trylock(&s->cpu_sheaves->lock))
                goto barn_put;
        pcs = this_cpu_ptr(s->cpu_sheaves);
 
        /*
-        * If we are returning empty sheaf, we either got it from the
-        * barn or had to allocate one. If we are returning a full
-        * sheaf, it's due to racing or being migrated to a different
-        * cpu. Breaching the barn's sheaf limits should be thus rare
-        * enough so just ignore them to simplify the recovery.
+        * If we put any empty or full sheaf to the barn below, it's due to
+        * racing or being migrated to a different cpu. Breaching the barn's
+        * sheaf limits should be thus rare enough so just ignore them to
+        * simplify the recovery.
         */
 
        if (pcs->main->size == 0) {