From: Harry Yoo Date: Tue, 27 Jan 2026 10:31:50 +0000 (+0900) Subject: mm/slab: factor out slab_args_unmergeable() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d907bf434fcd64c9609aa2983574e7c1f28e5493;p=thirdparty%2Fkernel%2Flinux.git mm/slab: factor out slab_args_unmergeable() slab_mergeable() determines whether a slab cache can be merged, but it should not be used when the cache is not fully created yet. Extract the pre-cache-creation mergeability checks into slab_args_unmergeable(), which evaluates kmem_cache_args, slab flags, and slab_nomerge to determine if a cache will be mergeable before it is created. Signed-off-by: Harry Yoo Link: https://patch.msgid.link/20260127103151.21883-2-harry.yoo@oracle.com Signed-off-by: Vlastimil Babka --- diff --git a/mm/slab_common.c b/mm/slab_common.c index 5c15a4ce5743..b6836f8500b6 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -171,24 +171,32 @@ int slab_unmergeable(struct kmem_cache *s) return 0; } -static struct kmem_cache *find_mergeable(unsigned int size, slab_flags_t flags, - const char *name, struct kmem_cache_args *args) +static bool slab_args_unmergeable(struct kmem_cache_args *args, + slab_flags_t flags) { - struct kmem_cache *s; - unsigned int align; - if (slab_nomerge) - return NULL; + return true; if (args->ctor) - return NULL; + return true; if (IS_ENABLED(CONFIG_HARDENED_USERCOPY) && args->usersize) - return NULL; - - flags = kmem_cache_flags(flags, name); + return true; if (flags & SLAB_NEVER_MERGE) + return true; + + return false; +} + +static struct kmem_cache *find_mergeable(unsigned int size, slab_flags_t flags, + const char *name, struct kmem_cache_args *args) +{ + struct kmem_cache *s; + unsigned int align; + + flags = kmem_cache_flags(flags, name); + if (slab_args_unmergeable(args, flags)) return NULL; size = ALIGN(size, sizeof(void *));