mm/slab: don't set SLAB_MAY_ACCOUNT for KMALLOC_PARTITION_CACHES
Subsystems (2)
Hao Li
reviewerPATCH 1/1 mm/slab: don't set SLAB_MAY_ACCOUNT for KMALLOC_PARTITION_CACHES
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.
---
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(-)
mm/slab_common.c +6 -4
@@ -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 ;
Signature · 1 line
2.55.0
Quoted 5 lines · Hao Li
An allocation with
__GFP_ACCOUNTset (without__GFP_DMAor__GFP_RECLAIMABLE) is redirected toKMALLOC_CGROUPand will never hitKMALLOC_NORMALorKMALLOC_PARTITION_CACHES. Consequently, neither of these caches requires objcg slots inobj_exts.
Quoted 7 lines
While
KMALLOC_NORMALalready skips settingSLAB_MAY_ACCOUNT,KMALLOC_PARTITION_CACHESstill carries it unnecessarily.Extend the check to skip
KMALLOC_PARTITION_CACHESas well, saving unnecessary objcg slots inobj_exts.Signed-off-by Hao Li <[email protected]>
Quoted 3 lines
---
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
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.
Quoted 31 lines
--- mm/slab_common.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)mm/slab_common.c +6
-4@@ -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 ;
Hao Li
reviewerQuoted 9 lines · Vlastimil Babka (SUSE)
Quoted 8 lines · Hao Li
An allocation with
__GFP_ACCOUNTset (without__GFP_DMAor__GFP_RECLAIMABLE) is redirected toKMALLOC_CGROUPand will never hitKMALLOC_NORMALorKMALLOC_PARTITION_CACHES. Consequently, neither of these caches requires objcg slots inobj_exts.While
KMALLOC_NORMALalready skips settingSLAB_MAY_ACCOUNT,KMALLOC_PARTITION_CACHESstill carries it unnecessarily.
Quoted 6 lines
Quoted 4 lines
Extend the check to skip
KMALLOC_PARTITION_CACHESas well, saving unnecessary objcg slots inobj_exts.Signed-off-by Hao Li <[email protected]>Reviewed-by Vlastimil Babka (SUSE) <[email protected]>
Thanks!
Quoted 7 lines
Quoted 4 lines
---
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")
Ah right, I mixed up Fixes with cc stable. Thanks for pointing it out!
Quoted 4 lines
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.
Makes sense. If Android uses partitioned caches, then it looks like we should cc stable.
Quoted 33 lines
Quoted 32 lines
--- mm/slab_common.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)mm/slab_common.c +6
-4@@ -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 ;
Quoted 9 lines · Hao Li
An allocation with
__GFP_ACCOUNTset (without__GFP_DMAor__GFP_RECLAIMABLE) is redirected toKMALLOC_CGROUPand will never hitKMALLOC_NORMALorKMALLOC_PARTITION_CACHES. Consequently, neither of these caches requires objcg slots inobj_exts.While
KMALLOC_NORMALalready skips settingSLAB_MAY_ACCOUNT,KMALLOC_PARTITION_CACHESstill carries it unnecessarily.[...]
Applied to mm/slab.git for-next, thanks!
[1/1] mm/slab: don't set SLAB_MAY_ACCOUNT for KMALLOC_PARTITION_CACHES
commit: ec81fa8f7dbcf89d9b4112544f76f47c8eb5c725
Signature · 2 lines
Cheers, Harry / Hyeonggon
Harry Yoo
maintainerQuoted 9 lines · Harry Yoo (Meta)
Quoted 8 lines · Hao Li
An allocation with
__GFP_ACCOUNTset (without__GFP_DMAor__GFP_RECLAIMABLE) is redirected toKMALLOC_CGROUPand will never hitKMALLOC_NORMALorKMALLOC_PARTITION_CACHES. Consequently, neither of these caches requires objcg slots inobj_exts.While
KMALLOC_NORMALalready skips settingSLAB_MAY_ACCOUNT,KMALLOC_PARTITION_CACHESstill carries it unnecessarily.
Quoted 6 lines
Quoted 1 line
[...]
Applied to
mm/slab.gitfor-next, thanks![1/1] mm/slab: don't set
SLAB_MAY_ACCOUNTforKMALLOC_PARTITION_CACHEScommit: ec81fa8f7dbcf89d9b4112544f76f47c8eb5c725
Just for the record I added Fixes: tag per Vlastimil's suggestion but didn't add Cc: stable (dunno if Android would need it (due to random kmalloc caches), but it can be backported later if needed).
Signature · 2 lines
Cheers, Harry / Hyeonggon