Skip to content

Commit e02147c

Browse files
Xaviertehcaster
authored andcommitted
mm/slab: Optimize the code logic in find_mergeable()
We can first assess the flags, if it's unmergeable, there's no need to calculate the size and align. Signed-off-by: Xavier <[email protected]> Signed-off-by: Vlastimil Babka <[email protected]>
1 parent 59090e4 commit e02147c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

mm/slab_common.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,15 @@ struct kmem_cache *find_mergeable(unsigned int size, unsigned int align,
186186
if (ctor)
187187
return NULL;
188188

189-
size = ALIGN(size, sizeof(void *));
190-
align = calculate_alignment(flags, align, size);
191-
size = ALIGN(size, align);
192189
flags = kmem_cache_flags(flags, name);
193190

194191
if (flags & SLAB_NEVER_MERGE)
195192
return NULL;
196193

194+
size = ALIGN(size, sizeof(void *));
195+
align = calculate_alignment(flags, align, size);
196+
size = ALIGN(size, align);
197+
197198
list_for_each_entry_reverse(s, &slab_caches, list) {
198199
if (slab_unmergeable(s))
199200
continue;

0 commit comments

Comments
 (0)