From: Catalin Marinas <catalin.marinas@arm.com>
To: Koichiro Den <koichiro.den@gmail.com>
Cc: vbabka@suse.cz, cl@linux.com, penberg@kernel.org,
rientjes@google.com, iamjoonsoo.kim@lge.com,
akpm@linux-foundation.org, roman.gushchin@linux.dev,
42.hyeyoo@gmail.com, kees@kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH v2] mm/slab: fix warning caused by duplicate kmem_cache creation in kmem_buckets_create
Date: Tue, 5 Nov 2024 10:51:36 +0000 [thread overview]
Message-ID: <Zyn4uGY7pObMD14u@arm.com> (raw)
In-Reply-To: <20241105022747.2819151-1-koichiro.den@gmail.com>
On Tue, Nov 05, 2024 at 11:27:47AM +0900, Koichiro Den wrote:
> diff --git a/mm/slab_common.c b/mm/slab_common.c
> index 3d26c257ed8b..db6ffe53c23e 100644
> --- a/mm/slab_common.c
> +++ b/mm/slab_common.c
> @@ -380,8 +380,11 @@ kmem_buckets *kmem_buckets_create(const char *name, slab_flags_t flags,
> unsigned int usersize,
> void (*ctor)(void *))
> {
> + unsigned long mask = 0;
> + unsigned int idx;
> kmem_buckets *b;
> - int idx;
> +
> + BUILD_BUG_ON(ARRAY_SIZE(kmalloc_caches[KMALLOC_NORMAL]) > BITS_PER_LONG);
>
> /*
> * When the separate buckets API is not built in, just return
> @@ -403,7 +406,7 @@ kmem_buckets *kmem_buckets_create(const char *name, slab_flags_t flags,
> for (idx = 0; idx < ARRAY_SIZE(kmalloc_caches[KMALLOC_NORMAL]); idx++) {
> char *short_size, *cache_name;
> unsigned int cache_useroffset, cache_usersize;
> - unsigned int size;
> + unsigned int size, aligned_idx;
>
> if (!kmalloc_caches[KMALLOC_NORMAL][idx])
> continue;
> @@ -416,10 +419,6 @@ kmem_buckets *kmem_buckets_create(const char *name, slab_flags_t flags,
> if (WARN_ON(!short_size))
> goto fail;
>
> - cache_name = kasprintf(GFP_KERNEL, "%s-%s", name, short_size + 1);
> - if (WARN_ON(!cache_name))
> - goto fail;
> -
> if (useroffset >= size) {
> cache_useroffset = 0;
> cache_usersize = 0;
> @@ -427,18 +426,29 @@ kmem_buckets *kmem_buckets_create(const char *name, slab_flags_t flags,
> cache_useroffset = useroffset;
> cache_usersize = min(size - cache_useroffset, usersize);
> }
> - (*b)[idx] = kmem_cache_create_usercopy(cache_name, size,
> - 0, flags, cache_useroffset,
> - cache_usersize, ctor);
> - kfree(cache_name);
> - if (WARN_ON(!(*b)[idx]))
> - goto fail;
> +
> + aligned_idx = __kmalloc_index(size, false);
> + if (!(*b)[aligned_idx]) {
> + cache_name = kasprintf(GFP_KERNEL, "%s-%s", name, short_size + 1);
> + if (WARN_ON(!cache_name))
> + goto fail;
> + (*b)[aligned_idx] = kmem_cache_create_usercopy(cache_name, size,
> + 0, flags, cache_useroffset,
> + cache_usersize, ctor);
> + if (WARN_ON(!(*b)[aligned_idx])) {
> + kfree(cache_name);
> + goto fail;
> + }
> + set_bit(aligned_idx, &mask);
> + }
> + if (idx != aligned_idx)
> + (*b)[idx] = (*b)[aligned_idx];
> }
It looks fine. This pretty much matches the logic in new_kmalloc_cache()
(from commit 963e84b0f262).
> return b;
>
> fail:
> - for (idx = 0; idx < ARRAY_SIZE(kmalloc_caches[KMALLOC_NORMAL]); idx++)
> + for_each_set_bit(idx, &mask, ARRAY_SIZE(kmalloc_caches[KMALLOC_NORMAL]))
> kmem_cache_destroy((*b)[idx]);
> kmem_cache_free(kmem_buckets_cache, b);
I gave this a try with swiotlb=noforce as well (which pushed the minimum
alignment to 64). So:
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Tested-by: Catalin Marinas <catalin.marinas@arm.com>
next prev parent reply other threads:[~2024-11-05 10:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-05 2:27 Koichiro Den
2024-11-05 10:51 ` Catalin Marinas [this message]
2024-11-05 16:48 ` Vlastimil Babka
2024-11-06 2:48 ` Koichiro Den
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Zyn4uGY7pObMD14u@arm.com \
--to=catalin.marinas@arm.com \
--cc=42.hyeyoo@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=cl@linux.com \
--cc=iamjoonsoo.kim@lge.com \
--cc=kees@kernel.org \
--cc=koichiro.den@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=penberg@kernel.org \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=stable@vger.kernel.org \
--cc=vbabka@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox