Re: [PATCH v1] mm/slab: Optimize the code logic in find_mergeable()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 9/4/24 9:40 AM, Xavier wrote:
> We can first assess the flags, if it's unmergeable, there's no need
> to calculate the size and align.
> 
> Signed-off-by: Xavier <xavier_qy@xxxxxxx>

OK, applied to slab/for-next. Thanks.

Note this is not a hotpath so no need to micro-optimize, but it makes
the code cleaner - no more calculate_alignment() using flags before we
adjust them by kmem_cache_flags(). This currently doesn't matter as it
cares only about SLAB_HWCACHE_ALIGN which is not affected, but will be
more robust in case of future changes.

> ---
>  mm/slab_common.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/mm/slab_common.c b/mm/slab_common.c
> index 40b582a014b8..aaf5989f7ffe 100644
> --- a/mm/slab_common.c
> +++ b/mm/slab_common.c
> @@ -169,14 +169,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;




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux