mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hao Li <hao.li@linux.dev>
To: vbabka@kernel.org, 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,
	Hao Li <hao.li@linux.dev>
Subject: [PATCH] mm/slab: don't set SLAB_MAY_ACCOUNT for KMALLOC_PARTITION_CACHES
Date: Wed, 11 Nov 2026 20:49:10 +0800	[thread overview]
Message-ID: <20261111125628.375624-1-hao.li@linux.dev> (raw)

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>
---
This doesn't seem like a real bug to me, just a small waste of memory, so I
didn't add a Fixes tag.
---
 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;
-- 
2.55.0


             reply	other threads:[~2026-11-11 12:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11 12:49 Hao Li [this message]
2026-11-11 13:08 ` Vlastimil Babka (SUSE)

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=20261111125628.375624-1-hao.li@linux.dev \
    --to=hao.li@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=cl@gentwo.org \
    --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=vbabka@kernel.org \
    /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®