From e02147cb703412fa13dd31908c734d7fb2314f55 Mon Sep 17 00:00:00 2001 From: Xavier Date: Wed, 4 Sep 2024 15:40:37 +0800 Subject: 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 Signed-off-by: Vlastimil Babka --- mm/slab_common.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'mm') diff --git a/mm/slab_common.c b/mm/slab_common.c index ca694f5553b4..85afeb69b3c0 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -186,14 +186,15 @@ struct kmem_cache *find_mergeable(unsigned int size, unsigned int align, if (ctor) return NULL; - size = ALIGN(size, sizeof(void *)); - align = calculate_alignment(flags, align, size); - size = ALIGN(size, align); flags = kmem_cache_flags(flags, name); if (flags & SLAB_NEVER_MERGE) return NULL; + size = ALIGN(size, sizeof(void *)); + align = calculate_alignment(flags, align, size); + size = ALIGN(size, align); + list_for_each_entry_reverse(s, &slab_caches, list) { if (slab_unmergeable(s)) continue; -- cgit