[PATCH] mm/slab: don't set SLAB_MAY_ACCOUNT for KMALLOC_PARTITION_CACHES
From: Hao Li
Date: Wed Nov 11 2026 - 08:10:37 EST
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@xxxxxxxxx>
---
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