]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mm/slab: pass alloc_flags to new slab allocation
authorVlastimil Babka (SUSE) <vbabka@kernel.org>
Wed, 10 Jun 2026 15:40:10 +0000 (17:40 +0200)
committerVlastimil Babka (SUSE) <vbabka@kernel.org>
Mon, 15 Jun 2026 11:19:37 +0000 (13:19 +0200)
Add the alloc_flags parameter to allocate_slab() and new_slab()
so it can be used to determine if spinning is allowed, independently
from gfp flags.

refill_objects() passes SLAB_ALLOC_DEFAULT because it can only be
reached from contexts that allow spinning.

Link: https://patch.msgid.link/20260610-slab_alloc_flags-v2-8-7190909db118@kernel.org
Reviewed-by: Hao Li <hao.li@linux.dev>
Reviewed-by: Suren Baghdasaryan <surenb@google.com>
Reviewed-by: Harry Yoo (Oracle) <harry@kernel.org>
Signed-off-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
mm/slub.c

index 3a34907b881b9487f8357b084f9fe3fdd035a76c..a975a2e727c815805c285280cb333dc8cc0d0786 100644 (file)
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -3378,9 +3378,10 @@ static __always_inline void unaccount_slab(struct slab *slab, int order,
 }
 
 /* Allocate and initialize a slab without building its freelist. */
-static struct slab *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
+static struct slab *allocate_slab(struct kmem_cache *s, gfp_t flags,
+                                 unsigned int alloc_flags, int node)
 {
-       bool allow_spin = gfpflags_allow_spinning(flags);
+       bool allow_spin = alloc_flags_allow_spinning(alloc_flags);
        struct slab *slab;
        struct kmem_cache_order_objects oo = s->oo;
        gfp_t alloc_gfp;
@@ -3398,10 +3399,6 @@ static struct slab *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
        if ((alloc_gfp & __GFP_DIRECT_RECLAIM) && oo_order(oo) > oo_order(s->min))
                alloc_gfp = (alloc_gfp | __GFP_NOMEMALLOC) & ~__GFP_RECLAIM;
 
-       /*
-        * __GFP_RECLAIM could be cleared on the first allocation attempt,
-        * so pass allow_spin flag directly.
-        */
        slab = alloc_slab_page(alloc_gfp, node, oo, allow_spin);
        if (unlikely(!slab)) {
                oo = s->min;
@@ -3438,15 +3435,17 @@ static struct slab *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
        return slab;
 }
 
-static struct slab *new_slab(struct kmem_cache *s, gfp_t flags, int node)
+static struct slab *new_slab(struct kmem_cache *s, gfp_t flags,
+                            unsigned int alloc_flags, int node)
 {
        if (unlikely(flags & GFP_SLAB_BUG_MASK))
                flags = kmalloc_fix_flags(flags);
 
        WARN_ON_ONCE(s->ctor && (flags & __GFP_ZERO));
 
-       return allocate_slab(s,
-               flags & (GFP_RECLAIM_MASK | GFP_CONSTRAINT_MASK), node);
+       flags &= GFP_RECLAIM_MASK | GFP_CONSTRAINT_MASK;
+
+       return allocate_slab(s, flags, alloc_flags, node);
 }
 
 static void __free_slab(struct kmem_cache *s, struct slab *slab, bool allow_spin)
@@ -4482,7 +4481,7 @@ new_objects:
        if (object)
                goto success;
 
-       slab = new_slab(s, trynode_flags, node);
+       slab = new_slab(s, trynode_flags, ac->alloc_flags, node);
 
        if (unlikely(!slab)) {
                if (node != NUMA_NO_NODE && !(gfpflags & __GFP_THISNODE)
@@ -7230,7 +7229,7 @@ refill_objects(struct kmem_cache *s, void **p, gfp_t gfp, unsigned int min,
 
 new_slab:
 
-       slab = new_slab(s, gfp, local_node);
+       slab = new_slab(s, gfp, SLAB_ALLOC_DEFAULT, local_node);
        if (!slab)
                goto out;
 
@@ -7578,7 +7577,7 @@ static void early_kmem_cache_node_alloc(int node)
 
        BUG_ON(kmem_cache_node->size < sizeof(struct kmem_cache_node));
 
-       slab = new_slab(kmem_cache_node, GFP_NOWAIT, node);
+       slab = new_slab(kmem_cache_node, GFP_NOWAIT, SLAB_ALLOC_DEFAULT, node);
 
        BUG_ON(!slab);
        if (slab_nid(slab) != node) {