mm/slab: add new flag SLAB_NO_MERGE to avoid merging per slab
Subsystems (3)
David Sterba
maintainerPATCH 1/1 mm/slab: add new flag SLAB_NO_MERGE to avoid merging per slab
Add a flag that allows to disable merging per slab. This can be used for more fine grained control over the caches or for debugging builds where separate slabs can verify that no objects leak.
The slab_nomerge boot option is too coarse and would need to be enabled on all testing hosts. There are some other ways how to disable merging, e.g. a slab constructor but this disables poisoning besides that it adds additional overhead. Other flags are internal and may have other semantics.
A concrete example what motivates the flag. During 'btrfs balance' slab top reported huge increase in caches like
1330095 1330095 100% 0.10K 34105 39 136420K Acpi-ParseExt 1734684 1734684 100% 0.14K 61953 28 247812K pid_namespace 8244036 6873075 83% 0.11K 229001 36 916004K khugepaged_mm_slot
which was confusing and that it's because of slab merging was not the first idea. After rebooting with slab_nomerge all the caches were from btrfs_ namespace as expected.
--- include/linux/slab.h | 3 +++ mm/slab_common.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-)
include/linux/slab.h +3 -0
@@ -106,6 +106,9 @@/* Avoid kmemleak tracing */ #define SLAB_NOLEAKTRACE ((slab_flags_t __force)0x00800000U) +/* Don't merge slab */ +#define SLAB_NO_MERGE ((slab_flags_t __force)0x01000000U) +/* Fault injection mark */ #ifdef CONFIG_FAILSLAB # define SLAB_FAILSLAB ((slab_flags_t __force)0x02000000U)
mm/slab_common.c +1 -1
@@ -47,7 +47,7 @@ static DECLARE_WORK(slab_caches_to_rcu_destroy_work,*/ #define SLAB_NEVER_MERGE (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER | \ SLAB_TRACE | SLAB_TYPESAFE_BY_RCU | SLAB_NOLEAKTRACE | \ - SLAB_FAILSLAB | kasan_never_merge()) + SLAB_FAILSLAB | SLAB_NO_MERGE | kasan_never_merge())#define SLAB_MERGE_SAME (SLAB_RECLAIM_ACCOUNT | SLAB_CACHE_DMA | \ SLAB_CACHE_DMA32 | SLAB_ACCOUNT)
Signature · 1 line
2.40.0
Quoted 5 lines · David Sterba
Add a flag that allows to disable merging per slab. This can be used for more fine grained control over the caches or for debugging builds where separate slabs can verify that no objects leak.
Theslab_nomergeboot option is too coarse and would need to be enabled on all testing hosts.
Hello David,
There is no users nor interface to set this flag, I guess you're going to use it by modifying source code, when debugging?
Does introducing new slub_debug option (i.e. slub_debug=N,pid_namespace) work for your use case? (there are some boot-time slub_debug options described in Documentation/mm/slub.rst)
include/linux/slab.h
Quoted 23 lines
There are some other ways how to disable merging,
e.g. a slab constructor but this disables poisoning besides that it adds additional overhead. Other flags are internal and may have other semantics.A concrete example what motivates the flag. During 'btrfs balance' slab top reported huge increase in caches like
1330095 1330095 100% 0.10K 34105 39 136420K Acpi-ParseExt 1734684 1734684 100% 0.14K 61953 28 247812K pid_namespace 8244036 6873075 83% 0.11K 229001 36 916004K khugepaged_mm_slotwhich was confusing and that it's because of slab merging was not the first idea. After rebooting with
slab_nomergeall the caches were frombtrfs_namespace as expected.Signed-off-by David Sterba <[email protected]>--- include/linux/slab.h | 3 +++ mm/slab_common.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-)include/linux/slab.h +0
-0
Thanks,
Signature · 5 lines
Hyeonggon Yoo Doing kernel stuff as a hobby Undergraduate | Chungnam National University Dept. Computer Science & Engineering
Quoted 7 lines · Hyeonggon Yoo
Quoted 5 lines · David Sterba
Add a flag that allows to disable merging per slab. This can be used for more fine grained control over the caches or for debugging builds where separate slabs can verify that no objects leak.
Theslab_nomergeboot option is too coarse and would need to be enabled on all testing hosts.
Quoted 8 lines
Hello David,
There is no users nor interface to set this flag, I guess you're going to use it by modifying source code, when debugging?
Does introducing new
slub_debugoption (i.e. slub_debug=N,pid_namespace) work for your use case? (there are some boot-timeslub_debugoptions described inDocumentation/mm/slub.rst)
Yeah, it supports globbing so it would be e.g. slub_debug=N,btrfs* That would deal with the "too coarse" aspect slab_nomerge. As for "need to be enabled on all testing hosts", is it more convenient to deploy a debug kernel build on them? Might be because you do that for other reasons already? Just want to clarify.
BTW this was proposed as RFC few months ago but not pursued:
https://lore.kernel.org/all/167396280045.539803.7540459812377220500.stgit@firesoul/
I have no big objections, just wouldn't like to see its usage proliferate unconditionally into non-debug builds.
Quoted 26 lines
include/linux/slab.h
Quoted 23 lines
There are some other ways how to disable merging,
e.g. a slab constructor but this disables poisoning besides that it adds additional overhead. Other flags are internal and may have other semantics.A concrete example what motivates the flag. During 'btrfs balance' slab top reported huge increase in caches like
1330095 1330095 100% 0.10K 34105 39 136420K Acpi-ParseExt 1734684 1734684 100% 0.14K 61953 28 247812K pid_namespace 8244036 6873075 83% 0.11K 229001 36 916004K khugepaged_mm_slotwhich was confusing and that it's because of slab merging was not the first idea. After rebooting with
slab_nomergeall the caches were frombtrfs_namespace as expected.Signed-off-by David Sterba <[email protected]>--- include/linux/slab.h | 3 +++ mm/slab_common.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-)include/linux/slab.h +0
-0Thanks,
Quoted 10 lines · Vlastimil Babka
Quoted 3 lines · Hyeonggon Yoo
On Wed, May 24, 2023 at 12:17:48PM +0200, David Sterba wrote:
work for your use case? (there are some boot-timeslub_debugoptions described inDocumentation/mm/slub.rst)Yeah, it supports globbing so it would be e.g. slub_debug=N,btrfs* That would deal with the "too coarse" aspect
slab_nomerge. As for "need to be enabled on all testing hosts", is it more convenient to deploy a debug kernel build on them? Might be because you do that for other reasons already? Just want to clarify.
Yeah, agreed.
Quoted 5 lines
BTW this was proposed as RFC few months ago but not pursued:
https://lore.kernel.org/all/167396280045.539803.7540459812377220500.stgit@firesoul/I have no big objections, just wouldn't like to see its usage proliferate unconditionally into non-debug builds.
It would be fine for me to make it conditionally available, e.g. depending on SLUB_DEBUG.
Quoted 9 lines · Hyeonggon Yoo
Quoted 5 lines · David Sterba
Add a flag that allows to disable merging per slab. This can be used for more fine grained control over the caches or for debugging builds where separate slabs can verify that no objects leak.
Theslab_nomergeboot option is too coarse and would need to be enabled on all testing hosts.There is no users nor interface to set this flag, I guess you're going to use it by modifying source code, when debugging?
An example usage
fs/btrfs/fs.h +6 -0
@@ -12,6 +12,12 @@#include "async-thread.h" #include "block-rsv.h" +#ifdef CONFIG_BTRFS_DEBUG +#define SLAB_DEBUG_NO_MERGE 0 +#else +#define SLAB_DEBUG_NO_MERGE SLAB_NO_MERGE +#endif +#define BTRFS_MAX_EXTENT_SIZE SZ_128M#define BTRFS_OLDEST_GENERATION 0ULL
fs/btrfs/ctree.c +1 -1
@@ -5049,7 +5049,7 @@ int __init btrfs_ctree_init(void) { btrfs_path_cachep =kmem_cache_create ("btrfs_path" ,sizeof (struct btrfs_path ),0 , -SLAB_MEM_SPREAD ,NULL ); +SLAB_MEM_SPREAD |SLAB_DEBUG_NO_MERGE ,NULL );if (!btrfs_path_cachep)return -ENOMEM ;return 0 ;
---
and this will be a permanent change, not added as needed.
Quoted 3 lines
Does introducing new
slub_debugoption (i.e. slub_debug=N,pid_namespace) work for your use case? (there are some boot-timeslub_debugoptions described inDocumentation/mm/slub.rst)
I'd like to keep boot parameters unchanged, the testing setups are different, physical, local VM, hosted. For the same reason the config option CONFIG_SLUB_DEBUG_ON=y is very convenient.