slub: track number of slabs irrespective of CONFIG_SLUB_DEBUG
Subsystems (5)
PATCH 1/1 slub: track number of slabs irrespective of CONFIG_SLUB_DEBUG
For !CONFIG_SLUB_DEBUG, SLUB does not maintain the number of slabs allocated per node for a kmem_cache. Thus, slabs_node() in __kmem_cache_empty(), __kmem_cache_shrink() and __kmem_cache_destroy() will always return 0 for such config. This is wrong and can cause issues for all users of these functions.
Infact in [1] Jason has reported a system crash while using SLUB without CONFIG_SLUB_DEBUG. The reason was the usage of slabs_node() by __kmem_cache_empty().
The right solution is to make slabs_node() work even for !CONFIG_SLUB_DEBUG. The commit 0f389ec63077 ("slub: No need for per node slab counters if !SLUB_DEBUG") had put the per node slab counter under CONFIG_SLUB_DEBUG because it was only read through sysfs API and the sysfs API was disabled on !CONFIG_SLUB_DEBUG. However the users of the per node slab counter assumed that it will work in the absence of CONFIG_SLUB_DEBUG. So, make the counter work for !CONFIG_SLUB_DEBUG.
Please note that commit f9e13c0a5a33 ("slab, slub: skip unnecessary kasan_cache_shutdown()") exposed this issue but it is present even before.
[1] http://lkml.kernel.org/r/CAHmME9rtoPwxUSnktxzKso14iuVCWT7BE_-_8PAC=pGw1iJnQg@mail.gmail.com
--- mm/slab.h | 2 +- mm/slub.c | 80 +++++++++++++++++++++++++------------------------------ 2 files changed, 38 insertions(+), 44 deletions(-)
mm/slab.h +1 -1
@@ -473,8 +473,8 @@ struct kmem_cache_node {#ifdef CONFIG_SLUB unsigned long nr_partial;struct list_head partial; -#ifdef CONFIG_SLUB_DEBUG atomic_long_t nr_slabs; +#ifdef CONFIG_SLUB_DEBUG atomic_long_t total_objects;struct list_head full;#endif
mm/slub.c +37 -43
95 lines not on this page · raw message
Signature · 1 line
2.18.0.rc1.244.gcf134e6275-goog
Quoted 5 lines · Shakeel Butt
For !CONFIG_SLUB_DEBUG, SLUB does not maintain the number of slabs allocated per node for a
kmem_cache. Thus,slabs_node()in__kmem_cache_empty(),__kmem_cache_shrink()and__kmem_cache_destroy()will always return 0 for such config. This is wrong and can cause issues for all users of these functions.
CONFIG_SLUB_DEBUG is set by default on almost all builds. The only case where CONFIG_SLUB_DEBUG is switched off is when we absolutely need to use the minimum amount of memory (embedded or some such thing).
Quoted 7 lines
The right solution is to make
slabs_node()work even for !CONFIG_SLUB_DEBUG. The commit0f389ec63077("slub: No need for per node slab counters if !SLUB_DEBUG") had put the per node slab counter underCONFIG_SLUB_DEBUGbecause it was only read through sysfs API and the sysfs API was disabled on !CONFIG_SLUB_DEBUG. However the users of the per node slab counter assumed that it will work in the absence ofCONFIG_SLUB_DEBUG. So, make the counter work for !CONFIG_SLUB_DEBUG.
Please do not do this. Find a way to avoid these checks. The objective of a !CONFIG_SLUB_DEBUG configuration is to not compile in debuggin checks etc etc in order to reduce the code/data footprint to the minimum necessary while sacrificing debuggability etc etc.
Maybe make it impossible to disable CONFIG_SLUB_DEBUG if CGROUPs are in use?
Quoted 22 lines · Christopher Lameter
Quoted 5 lines · Shakeel Butt
For !CONFIG_SLUB_DEBUG, SLUB does not maintain the number of slabs allocated per node for a
kmem_cache. Thus,slabs_node()in__kmem_cache_empty(),__kmem_cache_shrink()and__kmem_cache_destroy()will always return 0 for such config. This is wrong and can cause issues for all users of these functions.
CONFIG_SLUB_DEBUGis set by default on almost all builds. The only case whereCONFIG_SLUB_DEBUGis switched off is when we absolutely need to use the minimum amount of memory (embedded or some such thing).Quoted 7 lines
The right solution is to make
slabs_node()work even for !CONFIG_SLUB_DEBUG. The commit0f389ec63077("slub: No need for per node slab counters if !SLUB_DEBUG") had put the per node slab counter underCONFIG_SLUB_DEBUGbecause it was only read through sysfs API and the sysfs API was disabled on !CONFIG_SLUB_DEBUG. However the users of the per node slab counter assumed that it will work in the absence ofCONFIG_SLUB_DEBUG. So, make the counter work for !CONFIG_SLUB_DEBUG.
Quoted 8 lines
Please do not do this. Find a way to avoid these checks. The objective of a !CONFIG_SLUB_DEBUG configuration is to not compile in debuggin checks etc etc in order to reduce the code/data footprint to the minimum necessary while sacrificing debuggability etc etc.
Maybe make it impossible to disable
CONFIG_SLUB_DEBUGif CGROUPs are in use?
Copying from the other thread:
Quoted 8 lines · Jason A. Donenfeld
Quoted 5 lines · Christopher Lameter
NAK. Its easier to simply not allow !CONFIG_SLUB_DEBUG for cgroups based configs because in that case you certainly have enough memory to include the runtime debug code as well as the extended counters.
Quoted 5 lines
FWIW, I ran into issues with a combination of KASAN+CONFIG_SLUB without having
CONFIG_SLUB_DEBUG, because KASAN was using functions that were broken withoutCONFIG_SLUB_DEBUG, so while you're at it with creating dependencies, you might want to also say KASAN+CONFIG_SLUB ==>CONFIG_SLUB_DEBUG.
KASAN is the only user of __kmem_cache_empty(). So, enforcing KASAN+CONFIG_SLUB => CONFIG_SLUB_DEBUG makes sense but not sure about cgroups or memcg. Though is it ok let __kmem_cache_shrink() & __kmem_cache_shutdown() be broken for !CONFIG_SLUB_DEBUG?
For __kmem_cache_shutdown(), I can understand that shutting down a kmem_cache when there are still objects allocated from it, is broken and wrong. For __kmem_cache_shrink(), maybe wrong answer from it is tolerable.
Shakeel
Quoted 9 lines · Cristopher Lameter
Quoted 5 lines · Shakeel Butt
For !CONFIG_SLUB_DEBUG, SLUB does not maintain the number of slabs allocated per node for a
kmem_cache. Thus,slabs_node()in__kmem_cache_empty(),__kmem_cache_shrink()and__kmem_cache_destroy()will always return 0 for such config. This is wrong and can cause issues for all users of these functions.
Quoted 3 lines
CONFIG_SLUB_DEBUGis set by default on almost all builds. The only case whereCONFIG_SLUB_DEBUGis switched off is when we absolutely need to use the minimum amount of memory (embedded or some such thing).
I thought those would be using SLOB rather than SLUB.
Quoted 9 lines
Quoted 8 lines
The right solution is to make
slabs_node()work even for !CONFIG_SLUB_DEBUG. The commit0f389ec63077("slub: No need for per node slab counters if !SLUB_DEBUG") had put the per node slab counter underCONFIG_SLUB_DEBUGbecause it was only read through sysfs API and the sysfs API was disabled on !CONFIG_SLUB_DEBUG. However the users of the per node slab counter assumed that it will work in the absence ofCONFIG_SLUB_DEBUG. So, make the counter work for !CONFIG_SLUB_DEBUG.
Quoted 7 lines
Please do not do this. Find a way to avoid these checks. The objective of a !CONFIG_SLUB_DEBUG configuration is to not compile in debuggin checks etc etc in order to reduce the code/data footprint to the minimum necessary while sacrificing debuggability etc etc.
Maybe make it impossible to disable
CONFIG_SLUB_DEBUGif CGROUPs are in use?
Why don't we simply remove the config option altogether and make it enabled effectively.
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 31 lines · Michal Hocko
Quoted 9 lines · Cristopher Lameter
Quoted 5 lines · Shakeel Butt
For !CONFIG_SLUB_DEBUG, SLUB does not maintain the number of slabs allocated per node for a
kmem_cache. Thus,slabs_node()in__kmem_cache_empty(),__kmem_cache_shrink()and__kmem_cache_destroy()will always return 0 for such config. This is wrong and can cause issues for all users of these functions.Quoted 3 lines
CONFIG_SLUB_DEBUGis set by default on almost all builds. The only case whereCONFIG_SLUB_DEBUGis switched off is when we absolutely need to use the minimum amount of memory (embedded or some such thing).I thought those would be using SLOB rather than SLUB.
Quoted 14 lines
Quoted 8 lines
The right solution is to make
slabs_node()work even for !CONFIG_SLUB_DEBUG. The commit0f389ec63077("slub: No need for per node slab counters if !SLUB_DEBUG") had put the per node slab counter underCONFIG_SLUB_DEBUGbecause it was only read through sysfs API and the sysfs API was disabled on !CONFIG_SLUB_DEBUG. However the users of the per node slab counter assumed that it will work in the absence ofCONFIG_SLUB_DEBUG. So, make the counter work for !CONFIG_SLUB_DEBUG.Please do not do this. Find a way to avoid these checks. The objective of a !CONFIG_SLUB_DEBUG configuration is to not compile in debuggin checks etc etc in order to reduce the code/data footprint to the minimum necessary while sacrificing debuggability etc etc.
Quoted 6 lines
Quoted 2 lines
Maybe make it impossible to disable
CONFIG_SLUB_DEBUGif CGROUPs are in use?Why don't we simply remove the config option altogether and make it enabled effectively.
Christopher, how do you want to proceed? I don't have any strong opinion. I just don't want KASAN users kept broken for SLUB.
thanks,
Shakeel
PATCH 1/1 kasan: depend on CONFIG_SLUB_DEBUG
KASAN depends on having access to some of the accounting that SLUB_DEBUG does; without it, there are immediate crashes [1]. So, the natural thing to do is to make KASAN select SLUB_DEBUG.
[1] http://lkml.kernel.org/r/CAHmME9rtoPwxUSnktxzKso14iuVCWT7BE_-_8PAC=pGw1iJnQg@mail.gmail.com
--- lib/Kconfig.kasan | 1 + 1 file changed, 1 insertion(+)
lib/Kconfig.kasan +1 -0
@@ -6,6 +6,7 @@ if HAVE_ARCH_KASAN config KASAN bool "KASan: runtime memory debugger" depends on SLUB || (SLAB && !DEBUG_SLAB) + select SLUB_DEBUG if SLUB select CONSTRUCTORS select STACKDEPOT help
Signature · 1 line
2.17.1
Re: [PATCH] kasan: depend on CONFIG_SLUB_DEBUG
Quoted 6 lines · Jason A. Donenfeld
KASAN depends on having access to some of the accounting that
SLUB_DEBUGdoes; without it, there are immediate crashes [1]. So, the natural thing to do is to make KASAN selectSLUB_DEBUG.[1] http://lkml.kernel.org/r/CAHmME9rtoPwxUSnktxzKso14iuVCWT7BE_-_8PAC=pGw1iJnQg@mail.gmail.com
Quoted 12 lines
Fixes f9e13c0a5a33 ("slab, slub: skip unnecessary kasan_cache_shutdown()")Cc Shakeel Butt <[email protected]>Cc David Rientjes <[email protected]>Cc Christoph Lameter <[email protected]>Cc Pekka Enberg <[email protected]>Cc Joonsoo Kim <[email protected]>Cc Andrew Morton <[email protected]>Cc Andrey Ryabinin <[email protected]>Cc <[email protected]>Cc <[email protected]>Cc <[email protected]>Signed-off-by Jason A. Donenfeld <[email protected]>
This is the simplest way to do but I strongly suspect that the whole SLUB_DEBUG is not really necessary
Quoted 18 lines
--- lib/Kconfig.kasan | 1 + 1 file changed, 1 insertion(+)lib/Kconfig.kasan +1
-0@@ -6,6 +6,7 @@ if HAVE_ARCH_KASAN config KASAN bool "KASan: runtime memory debugger" depends on SLUB || (SLAB && !DEBUG_SLAB) + select SLUB_DEBUG if SLUB select CONSTRUCTORS select STACKDEPOT helpSignature · 1 line
2.17.1
Signature · 2 lines
Michal Hocko SUSE Labs
Re: [PATCH] kasan: depend on CONFIG_SLUB_DEBUG
In reply to Jason A. DonenfeldQuoted 7 lines · Jason A. Donenfeld
KASAN depends on having access to some of the accounting that
SLUB_DEBUGdoes; without it, there are immediate crashes [1]. So, the natural thing to do is to make KASAN selectSLUB_DEBUG.[1] http://lkml.kernel.org/r/CAHmME9rtoPwxUSnktxzKso14iuVCWT7BE_-_8PAC=pGw1iJnQg@mail.gmail.com
Quoted 12 lines
Fixes f9e13c0a5a33 ("slab, slub: skip unnecessary kasan_cache_shutdown()")Cc Shakeel Butt <[email protected]>Cc David Rientjes <[email protected]>Cc Christoph Lameter <[email protected]>Cc Pekka Enberg <[email protected]>Cc Joonsoo Kim <[email protected]>Cc Andrew Morton <[email protected]>Cc Andrey Ryabinin <[email protected]>Cc <[email protected]>Cc <[email protected]>Cc <[email protected]>Signed-off-by Jason A. Donenfeld <[email protected]>
Quoted 19 lines
--- lib/Kconfig.kasan | 1 + 1 file changed, 1 insertion(+)lib/Kconfig.kasan +1
-1@@ -6,6 +6,7 @@ if HAVE_ARCH_KASAN config KASAN bool "KASan: runtime memory debugger" depends on SLUB || (SLAB && !DEBUG_SLAB) + select SLUB_DEBUG if SLUB select CONSTRUCTORS select STACKDEPOT help --2.17.1