Skip to content

Commit d907bf4

Browse files
hygonitehcaster
authored andcommitted
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 <harry.yoo@oracle.com> Link: https://patch.msgid.link/20260127103151.21883-2-harry.yoo@oracle.com Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
1 parent aff8518 commit d907bf4

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

mm/slab_common.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,24 +171,32 @@ int slab_unmergeable(struct kmem_cache *s)
171171
return 0;
172172
}
173173

174-
static struct kmem_cache *find_mergeable(unsigned int size, slab_flags_t flags,
175-
const char *name, struct kmem_cache_args *args)
174+
static bool slab_args_unmergeable(struct kmem_cache_args *args,
175+
slab_flags_t flags)
176176
{
177-
struct kmem_cache *s;
178-
unsigned int align;
179-
180177
if (slab_nomerge)
181-
return NULL;
178+
return true;
182179

183180
if (args->ctor)
184-
return NULL;
181+
return true;
185182

186183
if (IS_ENABLED(CONFIG_HARDENED_USERCOPY) && args->usersize)
187-
return NULL;
188-
189-
flags = kmem_cache_flags(flags, name);
184+
return true;
190185

191186
if (flags & SLAB_NEVER_MERGE)
187+
return true;
188+
189+
return false;
190+
}
191+
192+
static struct kmem_cache *find_mergeable(unsigned int size, slab_flags_t flags,
193+
const char *name, struct kmem_cache_args *args)
194+
{
195+
struct kmem_cache *s;
196+
unsigned int align;
197+
198+
flags = kmem_cache_flags(flags, name);
199+
if (slab_args_unmergeable(args, flags))
192200
return NULL;
193201

194202
size = ALIGN(size, sizeof(void *));

0 commit comments

Comments
 (0)