Skip to content

Commit 2f35fee

Browse files
hygonitehcaster
authored andcommitted
mm/slab: only allow SLAB_OBJ_EXT_IN_OBJ for unmergeable caches
While SLAB_OBJ_EXT_IN_OBJ allows to reduce memory overhead to account slab objects, it prevents slab merging because merging can change the metadata layout. As pointed out Vlastimil Babka, disabling merging solely for this memory optimization may not be a net win, because disabling slab merging tends to increase overall memory usage. Restrict SLAB_OBJ_EXT_IN_OBJ to caches that are already unmergeable for other reasons (e.g., those with constructors or SLAB_TYPESAFE_BY_RCU). Suggested-by: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Harry Yoo <harry.yoo@oracle.com> Link: https://patch.msgid.link/20260127103151.21883-3-harry.yoo@oracle.com Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
1 parent a77d6d3 commit 2f35fee

3 files changed

Lines changed: 4 additions & 3 deletions

File tree

mm/slab.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ extern void create_boot_cache(struct kmem_cache *, const char *name,
411411
unsigned int useroffset, unsigned int usersize);
412412

413413
int slab_unmergeable(struct kmem_cache *s);
414+
bool slab_args_unmergeable(struct kmem_cache_args *args, slab_flags_t flags);
414415

415416
slab_flags_t kmem_cache_flags(slab_flags_t flags, const char *name);
416417

mm/slab_common.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,7 @@ int slab_unmergeable(struct kmem_cache *s)
174174
return 0;
175175
}
176176

177-
static bool slab_args_unmergeable(struct kmem_cache_args *args,
178-
slab_flags_t flags)
177+
bool slab_args_unmergeable(struct kmem_cache_args *args, slab_flags_t flags)
179178
{
180179
if (slab_nomerge)
181180
return true;

mm/slub.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8382,7 +8382,8 @@ static int calculate_sizes(struct kmem_cache_args *args, struct kmem_cache *s)
83828382
*/
83838383
aligned_size = ALIGN(size, s->align);
83848384
#if defined(CONFIG_SLAB_OBJ_EXT) && defined(CONFIG_64BIT)
8385-
if (aligned_size - size >= sizeof(struct slabobj_ext))
8385+
if (slab_args_unmergeable(args, s->flags) &&
8386+
(aligned_size - size >= sizeof(struct slabobj_ext)))
83868387
s->flags |= SLAB_OBJ_EXT_IN_OBJ;
83878388
#endif
83888389
size = aligned_size;

0 commit comments

Comments
 (0)