From: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>
To: Hao Li <hao.li@linux.dev>, harry@kernel.org, akpm@linux-foundation.org
Cc: cl@gentwo.org, rientjes@google.com, roman.gushchin@linux.dev,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Suren Baghdasaryan <surenb@google.com>
Subject: Re: [PATCH] mm/slab: don't set SLAB_MAY_ACCOUNT for KMALLOC_PARTITION_CACHES
Date: Wed, 11 Nov 2026 14:08:40 +0100 [thread overview]
Message-ID: <e2d1dc9f-59ff-4dfb-8ca4-35c584d14b35@kernel.org> (raw)
In-Reply-To: <20261111125628.375624-1-hao.li@linux.dev>
On 11/11/26 13:49, Hao Li wrote:
> An allocation with __GFP_ACCOUNT set (without __GFP_DMA or
> __GFP_RECLAIMABLE) is redirected to KMALLOC_CGROUP and will never hit
> KMALLOC_NORMAL or KMALLOC_PARTITION_CACHES. Consequently, neither of
> these caches requires objcg slots in obj_exts.
>
> While KMALLOC_NORMAL already skips setting SLAB_MAY_ACCOUNT,
> KMALLOC_PARTITION_CACHES still carries it unnecessarily.
>
> Extend the check to skip KMALLOC_PARTITION_CACHES as well, saving
> unnecessary objcg slots in obj_exts.
>
> Signed-off-by: Hao Li <hao.li@linux.dev>
Reviewed-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
> ---
> This doesn't seem like a real bug to me, just a small waste of memory, so I
> didn't add a Fixes tag.
Hmm I'd add
Fixes: 7def2e8549e5 ("mm/slab: add cache_ and slab_needs_objcg() helpers")
The question is whether cc stable as well. 7.3 LTS will be used for Android
and IIRC they have memory allocation profiling enabled. Not sure about
kmalloc partitions. Cc'ing Suren.
> ---
> mm/slab_common.c | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/mm/slab_common.c b/mm/slab_common.c
> index 2befd24b4d09..f0ea1fa178e7 100644
> --- a/mm/slab_common.c
> +++ b/mm/slab_common.c
> @@ -1000,16 +1000,18 @@ new_kmalloc_cache(int idx, enum kmalloc_cache_type type)
> #endif
>
> /*
> - * If memcg_kmem is enabled and this is a KMALLOC_NORMAL cache and not
> - * aliased with any other type, make sure it's never merged with any other
> - * cache.
> + * If memcg_kmem is enabled and this is a KMALLOC_NORMAL or
> + * KMALLOC_PARTITION_CACHES cache and not aliased with any other type,
> + * make sure it's never merged with any other cache.
> *
> * In other cases the kmalloc cache may end up being used for a
> * __GFP_ACCOUNT allocation so mark it as such. The exception is a
> * KMALLOC_NO_OBJ_EXT cache.
> */
> if (!mem_cgroup_kmem_disabled()) {
> - if (type == KMALLOC_NORMAL && KMALLOC_RECLAIM != KMALLOC_NORMAL)
> + if (type >= KMALLOC_PARTITION_START &&
> + type <= KMALLOC_PARTITION_END &&
> + KMALLOC_RECLAIM != KMALLOC_NORMAL)
> flags |= SLAB_NO_MERGE;
> else if (!(flags & SLAB_NO_OBJ_EXT))
> flags |= SLAB_MAY_ACCOUNT;
prev parent reply other threads:[~2026-11-11 13:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 12:49 Hao Li
2026-11-11 13:08 ` Vlastimil Babka (SUSE) [this message]
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=e2d1dc9f-59ff-4dfb-8ca4-35c584d14b35@kernel.org \
--to=vbabka@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=cl@gentwo.org \
--cc=hao.li@linux.dev \
--cc=harry@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rientjes@google.com \
--cc=roman.gushchin@linux.dev \
--cc=surenb@google.com \
/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
all inboxes | Powered by JetHome®