* [PATCH v1] mm/slab: Optimize the code logic in find_mergeable()
@ 2024-09-04 7:40 Xavier
2024-09-05 12:47 ` Vlastimil Babka
0 siblings, 1 reply; 2+ messages in thread
From: Xavier @ 2024-09-04 7:40 UTC (permalink / raw)
To: cl, penberg, rientjes, iamjoonsoo.kim, akpm, vbabka,
roman.gushchin, 42.hyeyoo
Cc: linux-mm, linux-kernel, Xavier
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@163.com>
---
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;
--
2.45.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v1] mm/slab: Optimize the code logic in find_mergeable()
2024-09-04 7:40 [PATCH v1] mm/slab: Optimize the code logic in find_mergeable() Xavier
@ 2024-09-05 12:47 ` Vlastimil Babka
0 siblings, 0 replies; 2+ messages in thread
From: Vlastimil Babka @ 2024-09-05 12:47 UTC (permalink / raw)
To: Xavier, cl, penberg, rientjes, iamjoonsoo.kim, akpm,
roman.gushchin, 42.hyeyoo
Cc: linux-mm, linux-kernel
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@163.com>
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;
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-09-05 12:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-04 7:40 [PATCH v1] mm/slab: Optimize the code logic in find_mergeable() Xavier
2024-09-05 12:47 ` Vlastimil Babka
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox