mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] mm/slab: don't set SLAB_MAY_ACCOUNT for KMALLOC_PARTITION_CACHES
@ 2026-11-11 12:49 Hao Li
  2026-11-11 13:08 ` Vlastimil Babka (SUSE)
  0 siblings, 1 reply; 2+ messages in thread
From: Hao Li @ 2026-11-11 12:49 UTC (permalink / raw)
  To: vbabka, harry, akpm
  Cc: cl, rientjes, roman.gushchin, linux-mm, linux-kernel, Hao Li

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] mm/slab: don't set SLAB_MAY_ACCOUNT for KMALLOC_PARTITION_CACHES
  2026-11-11 12:49 [PATCH] mm/slab: don't set SLAB_MAY_ACCOUNT for KMALLOC_PARTITION_CACHES Hao Li
@ 2026-11-11 13:08 ` Vlastimil Babka (SUSE)
  0 siblings, 0 replies; 2+ messages in thread
From: Vlastimil Babka (SUSE) @ 2026-11-11 13:08 UTC (permalink / raw)
  To: Hao Li, harry, akpm
  Cc: cl, rientjes, roman.gushchin, linux-mm, linux-kernel, Suren Baghdasaryan

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;


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-11 13:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-11 12:49 [PATCH] mm/slab: don't set SLAB_MAY_ACCOUNT for KMALLOC_PARTITION_CACHES Hao Li
2026-11-11 13:08 ` Vlastimil Babka (SUSE)

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®