mm: slub: move sysfs slab alloc/free interfaces to debugfs
Subsystems (2)
PATCH v7 1/1 mm: slub: move sysfs slab alloc/free interfaces to debugfs
alloc_calls and free_calls implementation in sysfs have two issues, one is PAGE_SIZE limitiation of sysfs and other is it does not adhere to "one value per file" rule.
To overcome this issues, move the alloc_calls and free_calls implemeation to debugfs.
Rename the alloc_calls/free_calls to alloc_traces/free_traces, to be inline with what it does.
---
changes in V7:
- Drop the older alloc_calls and free_calls interface.
changes in v6:
- https://lore.kernel.org/linux-mm/[email protected]/
changes in v5:
- https://lore.kernel.org/linux-mm/[email protected]/
changes in v4:
- https://lore.kernel.org/linux-mm/[email protected]/
changes in v3:
- https://lore.kernel.org/linux-mm/[email protected]/
changes in v2:
- https://lore.kernel.org/linux-mm/[email protected]/
changes in v1:
- https://lore.kernel.org/linux-mm/[email protected]/
include/linux/slub_def.h | 8 ++ mm/slab_common.c | 9 ++ mm/slub.c | 353 ++++++++++++++++++++++++++++++++++------------- 3 files changed, 276 insertions(+), 94 deletions(-)
include/linux/slub_def.h +8 -0
@@ -159,6 +159,14 @@ static inline void sysfs_slab_release(struct kmem_cache *s) }#endif +#if defined(CONFIG_DEBUG_FS ) && defined(CONFIG_SLUB_DEBUG ) +#define SLAB_SUPPORTS_DEBUGFS +void debugfs_slab_release (struct kmem_cache *); +#else +static inline void debugfs_slab_release (struct kmem_cache *s) +{ +} +#endif void object_err (struct kmem_cache *s,struct page *page,u8 *object,char *reason);
mm/slab_common.c +9 -0
@@ -455,6 +455,9 @@ static void slab_caches_to_rcu_destroy_workfn(struct work_struct *work)#else slab_kmem_cache_release (s);#endif +#ifdef SLAB_SUPPORTS_DEBUGFS +debugfs_slab_release (s); +#endif } }
@@ -472,6 +475,9 @@ static int shutdown_cache(struct kmem_cache *s)#ifdef SLAB_SUPPORTS_SYSFS sysfs_slab_unlink (s);#endif +#ifdef SLAB_SUPPORTS_DEBUGFS +debugfs_slab_release (s); +#endif list_add_tail (&s->list, &slab_caches_to_rcu_destroy);schedule_work (&slab_caches_to_rcu_destroy_work); }else {
@@ -482,6 +488,9 @@ static int shutdown_cache(struct kmem_cache *s)#else slab_kmem_cache_release (s);#endif +#ifdef SLAB_SUPPORTS_DEBUGFS +debugfs_slab_release (s); +#endif }return 0 ;
mm/slub.c +259 -94
413 lines not on this page · raw message
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
Quoted 63 lines · Faiyaz Mohammed
alloc_callsandfree_callsimplementation in sysfs have two issues, one isPAGE_SIZElimitiation of sysfs and other is it does not adhere to "one value per file" rule.To overcome this issues, move the
alloc_callsandfree_callsimplemeation to debugfs.Rename the alloc_calls/free_calls to alloc_traces/free_traces, to be inline with what it does.
Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>Signed-off-by Faiyaz Mohammed <[email protected]>---
changes in V7:
- Drop the olderalloc_callsandfree_callsinterface.
changes in v6:
- https://lore.kernel.org/linux-mm/[email protected]/changes in v5:
- https://lore.kernel.org/linux-mm/[email protected]/changes in v4:
- https://lore.kernel.org/linux-mm/[email protected]/changes in v3:
- https://lore.kernel.org/linux-mm/[email protected]/changes in v2:
- https://lore.kernel.org/linux-mm/[email protected]/changes in v1:
- https://lore.kernel.org/linux-mm/[email protected]/include/linux/slub_def.h | 8 ++ mm/slab_common.c | 9 ++ mm/slub.c | 353 ++++++++++++++++++++++++++++++++++------------- 3 files changed, 276 insertions(+), 94 deletions(-)include/linux/slub_def.h +8
-0@@ -159,6 +159,14 @@ static inline void sysfs_slab_release(struct kmem_cache *s) }#endif +#if defined(CONFIG_DEBUG_FS ) && defined(CONFIG_SLUB_DEBUG ) +#define SLAB_SUPPORTS_DEBUGFS +void debugfs_slab_release (struct kmem_cache *); +#else +static inline void debugfs_slab_release (struct kmem_cache *s) +{ +} +#endif void object_err (struct kmem_cache *s,struct page *page,u8 *object,char *reason);mm/slab_common.c +0
-0
mm/slab_common.c static void slab_caches_to_rcu_destroy_workfn(struct work_struct *work) · line 460
Quoted 6 lines
mm/slab_common.c +3
-0@@ -455,6 +455,9 @@ static void slab_caches_to_rcu_destroy_workfn(struct work_struct *work)#else slab_kmem_cache_release (s);#endif +#ifdef SLAB_SUPPORTS_DEBUGFS +debugfs_slab_release (s); +#endif
Why do you need these #ifdef if your slub_dev.h file already provides an "empty" function for this?
mm/slab_common.c static int shutdown_cache(struct kmem_cache *s) · line 480
Quoted 10 lines
mm/slab_common.c +3
-0} }@@ -472,6 +475,9 @@ static int shutdown_cache(struct kmem_cache *s)#ifdef SLAB_SUPPORTS_SYSFS sysfs_slab_unlink (s);#endif +#ifdef SLAB_SUPPORTS_DEBUGFS +debugfs_slab_release (s); +#endif
Same here.
mm/slab_common.c static int shutdown_cache(struct kmem_cache *s) · line 493
Quoted 10 lines
mm/slab_common.c +3
-0list_add_tail (&s->list, &slab_caches_to_rcu_destroy);schedule_work (&slab_caches_to_rcu_destroy_work); }else {@@ -482,6 +488,9 @@ static int shutdown_cache(struct kmem_cache *s)#else slab_kmem_cache_release (s);#endif +#ifdef SLAB_SUPPORTS_DEBUGFS +debugfs_slab_release (s); +#endif
And here.
What is wrong with your .h file that keeps the need for #ifdef in the .c file?
I thought I've asked about this a number of times in the past, what am I missing?
thanks,
greg k-h
Quoted 59 lines · Greg KH
Quoted 58 lines · Faiyaz Mohammed
alloc_callsandfree_callsimplementation in sysfs have two issues, one isPAGE_SIZElimitiation of sysfs and other is it does not adhere to "one value per file" rule.To overcome this issues, move the
alloc_callsandfree_callsimplemeation to debugfs.Rename the alloc_calls/free_calls to alloc_traces/free_traces, to be inline with what it does.
Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>Signed-off-by Faiyaz Mohammed <[email protected]>---
changes in V7:
- Drop the olderalloc_callsandfree_callsinterface.
changes in v6:
- https://lore.kernel.org/linux-mm/[email protected]/changes in v5:
- https://lore.kernel.org/linux-mm/[email protected]/changes in v4:
- https://lore.kernel.org/linux-mm/[email protected]/changes in v3:
- https://lore.kernel.org/linux-mm/[email protected]/changes in v2:
- https://lore.kernel.org/linux-mm/[email protected]/changes in v1:
- https://lore.kernel.org/linux-mm/[email protected]/include/linux/slub_def.h | 8 ++ mm/slab_common.c | 9 ++ mm/slub.c | 353 ++++++++++++++++++++++++++++++++++------------- 3 files changed, 276 insertions(+), 94 deletions(-)include/linux/slub_def.h +8
-0@@ -159,6 +159,14 @@ static inline void sysfs_slab_release(struct kmem_cache *s) }#endif +#if defined(CONFIG_DEBUG_FS ) && defined(CONFIG_SLUB_DEBUG ) +#define SLAB_SUPPORTS_DEBUGFS +void debugfs_slab_release (struct kmem_cache *); +#else +static inline void debugfs_slab_release (struct kmem_cache *s) +{ +} +#endif void object_err (struct kmem_cache *s,struct page *page,u8 *object,char *reason);
Quoted 15 lines
mm/slab_common.c static void slab_caches_to_rcu_destroy_workfn(struct work_struct *work) · line 460
Quoted 11 lines
mm/slab_common.c +3
-0@@ -455,6 +455,9 @@ static void slab_caches_to_rcu_destroy_workfn(struct work_struct *work)#else slab_kmem_cache_release (s);#endif +#ifdef SLAB_SUPPORTS_DEBUGFS +debugfs_slab_release (s); +#endif Why do you need these #ifdef if your
slub_dev.hfile already provides an "empty" function for this?
We are not including slub_def.h directly. mm/slab.h includes the slub_def.h if CONFIG_SLUB enable,
from mm/slab.h
#ifdef CONFIG_SLAB
#include <linux/slab_def.h>
#endif
#ifdef CONFIG_SLUB
#include <linux/slub_def.h>
#endif
so if CONFIG_SLAB is enable then mm/slab.h includes slab_def.h, to avoid undefined reference error added SLAB_SUPPORTS_DEBUGFS like SLAB_SUPPORTS_SYSFS.
Quoted 36 lines
mm/slab_common.c static int shutdown_cache(struct kmem_cache *s) · line 480
Quoted 10 lines
mm/slab_common.c +3
-0} }@@ -472,6 +475,9 @@ static int shutdown_cache(struct kmem_cache *s)#ifdef SLAB_SUPPORTS_SYSFS sysfs_slab_unlink (s);#endif +#ifdef SLAB_SUPPORTS_DEBUGFS +debugfs_slab_release (s); +#endif Same here.
mm/slab_common.c static int shutdown_cache(struct kmem_cache *s) · line 493
Quoted 10 lines
mm/slab_common.c +3
-0list_add_tail (&s->list, &slab_caches_to_rcu_destroy);schedule_work (&slab_caches_to_rcu_destroy_work); }else {@@ -482,6 +488,9 @@ static int shutdown_cache(struct kmem_cache *s)#else slab_kmem_cache_release (s);#endif +#ifdef SLAB_SUPPORTS_DEBUGFS +debugfs_slab_release (s); +#endif And here.
What is wrong with your .h file that keeps the need for #ifdef in the .c file?
I thought I've asked about this a number of times in the past, what am I missing?
thanks,
greg k-h
Quoted 85 lines · Faiyaz Mohammed
Quoted 59 lines · Greg KH
Quoted 58 lines · Faiyaz Mohammed
alloc_callsandfree_callsimplementation in sysfs have two issues, one isPAGE_SIZElimitiation of sysfs and other is it does not adhere to "one value per file" rule.To overcome this issues, move the
alloc_callsandfree_callsimplemeation to debugfs.Rename the alloc_calls/free_calls to alloc_traces/free_traces, to be inline with what it does.
Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>Signed-off-by Faiyaz Mohammed <[email protected]>---
changes in V7:
- Drop the olderalloc_callsandfree_callsinterface.
changes in v6:
- https://lore.kernel.org/linux-mm/[email protected]/changes in v5:
- https://lore.kernel.org/linux-mm/[email protected]/changes in v4:
- https://lore.kernel.org/linux-mm/[email protected]/changes in v3:
- https://lore.kernel.org/linux-mm/[email protected]/changes in v2:
- https://lore.kernel.org/linux-mm/[email protected]/changes in v1:
- https://lore.kernel.org/linux-mm/[email protected]/include/linux/slub_def.h | 8 ++ mm/slab_common.c | 9 ++ mm/slub.c | 353 ++++++++++++++++++++++++++++++++++------------- 3 files changed, 276 insertions(+), 94 deletions(-)include/linux/slub_def.h +8
-0@@ -159,6 +159,14 @@ static inline void sysfs_slab_release(struct kmem_cache *s) }#endif +#if defined(CONFIG_DEBUG_FS ) && defined(CONFIG_SLUB_DEBUG ) +#define SLAB_SUPPORTS_DEBUGFS +void debugfs_slab_release (struct kmem_cache *); +#else +static inline void debugfs_slab_release (struct kmem_cache *s) +{ +} +#endif void object_err (struct kmem_cache *s,struct page *page,u8 *object,char *reason);Quoted 15 lines
mm/slab_common.c static void slab_caches_to_rcu_destroy_workfn(struct work_struct *work) · line 460
Quoted 11 lines
mm/slab_common.c +3
-0@@ -455,6 +455,9 @@ static void slab_caches_to_rcu_destroy_workfn(struct work_struct *work)#else slab_kmem_cache_release (s);#endif +#ifdef SLAB_SUPPORTS_DEBUGFS +debugfs_slab_release (s); +#endif Why do you need these #ifdef if your
slub_dev.hfile already provides an "empty" function for this?We are not including
slub_def.hdirectly.mm/slab.hincludes theslub_def.hifCONFIG_SLUBenable,from
mm/slab.h
#ifdefCONFIG_SLAB
#include <linux/slab_def.h>
#endif
Quoted 7 lines
#ifdef
CONFIG_SLUB
#include <linux/slub_def.h>
#endifso if
CONFIG_SLABis enable thenmm/slab.hincludesslab_def.h, to avoid undefined reference error addedSLAB_SUPPORTS_DEBUGFSlikeSLAB_SUPPORTS_SYSFS.
Ick, ok, messy code, I'll stop complaining now if this really is the only way to do it (still feels wrong to me...)
greg k-h
Quoted 26 lines · Greg KH
Quoted 25 lines · Faiyaz Mohammed
Quoted 13 lines
---
a/mm/slab_common.cmm/slab_common.c static void slab_caches_to_rcu_destroy_workfn(struct work_struct *work) · line 460
Quoted 8 lines
+++
b/mm/slab_common.cmm/slab_common.c +3
-0@@ -455,6 +455,9 @@ static void slab_caches_to_rcu_destroy_workfn(struct work_struct *work)#else slab_kmem_cache_release (s);#endif +#ifdef SLAB_SUPPORTS_DEBUGFS +debugfs_slab_release (s); +#endif Why do you need these #ifdef if your
slub_dev.hfile already provides an "empty" function for this?We are not including
slub_def.hdirectly.mm/slab.hincludes theslub_def.hifCONFIG_SLUBenable,from
mm/slab.h
#ifdefCONFIG_SLAB
#include <linux/slab_def.h>
#endif#ifdef
CONFIG_SLUB
#include <linux/slub_def.h>
#endif
Quoted 6 lines
Quoted 3 lines
so if
CONFIG_SLABis enable thenmm/slab.hincludesslab_def.h, to avoid undefined reference error addedSLAB_SUPPORTS_DEBUGFSlikeSLAB_SUPPORTS_SYSFS.Ick, ok, messy code, I'll stop complaining now if this really is the only way to do it (still feels wrong to me...)
How about simply replicating the empty function in include/linux/slab_def.h
We could do the same with SYSFS, except the SLAB (and SLUB w/o SYSFS) versions of sysfs_slab_release() would not be empty, but just call slab_kmem_cache_release(s);
Then we could get rid of the #ifdef's completely?
Quoted 2 lines
greg k-h
Quoted 31 lines · Vlastimil Babka
Quoted 30 lines · Greg KH
Quoted 28 lines · Faiyaz Mohammed
Quoted 13 lines
---
a/mm/slab_common.cmm/slab_common.c static void slab_caches_to_rcu_destroy_workfn(struct work_struct *work) · line 460
Quoted 8 lines
+++
b/mm/slab_common.cmm/slab_common.c +3
-0@@ -455,6 +455,9 @@ static void slab_caches_to_rcu_destroy_workfn(struct work_struct *work)#else slab_kmem_cache_release (s);#endif +#ifdef SLAB_SUPPORTS_DEBUGFS +debugfs_slab_release (s); +#endif Why do you need these #ifdef if your
slub_dev.hfile already provides an "empty" function for this?We are not including
slub_def.hdirectly.mm/slab.hincludes theslub_def.hifCONFIG_SLUBenable,from
mm/slab.h
#ifdefCONFIG_SLAB
#include <linux/slab_def.h>
#endif#ifdef
CONFIG_SLUB
#include <linux/slub_def.h>
#endifso if
CONFIG_SLABis enable thenmm/slab.hincludesslab_def.h, to avoid undefined reference error addedSLAB_SUPPORTS_DEBUGFSlikeSLAB_SUPPORTS_SYSFS.
Quoted 6 lines
Quoted 2 lines
Ick, ok, messy code, I'll stop complaining now if this really is the only way to do it (still feels wrong to me...)
How about simply replicating the empty function in
include/linux/slab_def.h
Yes, we can add empty function in include/linux/slab_def.h. I will add in next patch version.
Quoted 5 lines
We could do the same with SYSFS, except the SLAB (and SLUB w/o SYSFS) versions of
sysfs_slab_release()would not be empty, but just callslab_kmem_cache_release(s);
Then we could get rid of the #ifdef's completely?
Is it okay, if I raise separate patch for sysfs by adding empty function in slab_def.h?
Thanks and regards,
Mohammed Faiyaz
Quoted 3 lines
Quoted 2 lines
greg k-h
Quoted 6 lines · Faiyaz Mohammed
Quoted 3 lines
How about simply replicating the empty function in
include/linux/slab_def.hYes, we can add empty function in
include/linux/slab_def.h. I will add in next patch version.
Quoted 7 lines
Quoted 5 lines
We could do the same with SYSFS, except the SLAB (and SLUB w/o SYSFS) versions of
sysfs_slab_release()would not be empty, but just callslab_kmem_cache_release(s);
Then we could get rid of the #ifdef's completely?Is it okay, if I raise separate patch for sysfs by adding empty function in
slab_def.h?
Yeah that would be cleaner. Thanks.
Quoted 6 lines
Thanks and regards,
Mohammed FaiyazQuoted 3 lines
Quoted 2 lines
greg k-h
Quoted 4 lines · Faiyaz Mohammed
alloc_callsandfree_callsimplementation in sysfs have two issues, one isPAGE_SIZElimitiation of sysfs and other is it does not adhere to "one value per file" rule.
Quoted 8 lines
To overcome this issues, move the
alloc_callsandfree_callsimplemeation to debugfs.Rename the alloc_calls/free_calls to alloc_traces/free_traces, to be inline with what it does.
Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>
These were IIRC bot reports for some bugs in the previous versions, so keeping the Reported-by: for the whole patch is misleading - these were not reports for the sysfs issues this patch fixes by moving the files to debugfs.
Quoted 19 lines
Signed-off-by Faiyaz Mohammed <[email protected]>---
changes in V7:
- Drop the olderalloc_callsandfree_callsinterface.
changes in v6:
- https://lore.kernel.org/linux-mm/[email protected]/changes in v5:
- https://lore.kernel.org/linux-mm/[email protected]/changes in v4:
- https://lore.kernel.org/linux-mm/[email protected]/changes in v3:
- https://lore.kernel.org/linux-mm/[email protected]/changes in v2:
- https://lore.kernel.org/linux-mm/[email protected]/
Quoted 7 lines
changes in v1:
- https://lore.kernel.org/linux-mm/[email protected]/include/linux/slub_def.h | 8 ++ mm/slab_common.c | 9 ++ mm/slub.c | 353 ++++++++++++++++++++++++++++++++++------------- 3 files changed, 276 insertions(+), 94 deletions(-)
I don't see any of the symlinks under /sys/kernel/debug/slab/, so I think the aliases handling code is wrong, and I can see at least two reasons why it could be:
mm/slub.c __kmem_cache_alias(const char *name, unsigned int size, unsigned int align, · line 4539
Quoted 6 lines
mm/slub.c +2
-0@@ -4525,6 +4535,8 @@ __kmem_cache_alias(const char *name, unsigned int size, unsigned int align, s->refcount--; s =NULL ; } + +debugfs_slab_alias (s, name);
Here you might be calling debugfs_slab_alias() with NULL if the sysfs_slab_alias() above returned true.
Quoted 3 lines
mm/slub.c +0
-0}return s;
...
mm/slub.c static int __init slab_sysfs_init(void) · line 5972
Quoted 13 lines
mm/slub.c +13
-0+static int __init slab_debugfs_init (void ) +{ +struct kmem_cache *s; + + slab_debugfs_root =debugfs_create_dir ("slab" ,NULL ); + + slab_state =FULL ; + +list_for_each_entry (s, &slab_caches, list) +debugfs_slab_add (s); + +while (alias_list) { +struct saved_alias *al = alias_list;
alias_list a single list and both slab_sysfs_init() and slab_debugfs_init() flush it. So only the init call that happens to be called first, does actually find an unflushed list. I think you
need to use a separate list for debugfs (simpler) or a shared list with both sysfs and debugfs processing (probably more complicated).
And finally a question, perhaps also for Greg. With sysfs, we hand out the lifecycle of struct kmem_cache to sysfs, to ensure we are not reading sysfs files of a cache that has been removed.
But with debugfs, what are the guarantees that things won't blow up when a debugfs file is being read while somebody calls kmem_cache_destroy() on the cache?
Quoted 17 lines
mm/slub.c +13
-0+ + alias_list = alias_list->next; + +debugfs_slab_alias (al->s, al->name); + + kfree(al); + } + +return 0 ; + +} +__initcall (slab_debugfs_init); +#endif /* * The /proc/slabinfo ABI */
Quoted 84 lines · Vlastimil Babka
Quoted 4 lines · Faiyaz Mohammed
alloc_callsandfree_callsimplementation in sysfs have two issues, one isPAGE_SIZElimitiation of sysfs and other is it does not adhere to "one value per file" rule.Quoted 8 lines
To overcome this issues, move the
alloc_callsandfree_callsimplemeation to debugfs.Rename the alloc_calls/free_calls to alloc_traces/free_traces, to be inline with what it does.
Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>These were IIRC bot reports for some bugs in the previous versions, so keeping the Reported-by: for the whole patch is misleading - these were not reports for the sysfs issues this patch fixes by moving the files to debugfs.
Quoted 19 lines
Signed-off-by Faiyaz Mohammed <[email protected]>---
changes in V7:
- Drop the olderalloc_callsandfree_callsinterface.
changes in v6:
- https://lore.kernel.org/linux-mm/[email protected]/changes in v5:
- https://lore.kernel.org/linux-mm/[email protected]/changes in v4:
- https://lore.kernel.org/linux-mm/[email protected]/changes in v3:
- https://lore.kernel.org/linux-mm/[email protected]/changes in v2:
- https://lore.kernel.org/linux-mm/[email protected]/Quoted 7 lines
changes in v1:
- https://lore.kernel.org/linux-mm/[email protected]/include/linux/slub_def.h | 8 ++ mm/slab_common.c | 9 ++ mm/slub.c | 353 ++++++++++++++++++++++++++++++++++------------- 3 files changed, 276 insertions(+), 94 deletions(-)I don't see any of the symlinks under
/sys/kernel/debug/slab/, so I think the aliases handling code is wrong, and I can see at least two reasons why it could be:mm/slub.c __kmem_cache_alias(const char *name, unsigned int size, unsigned int align, · line 4539
Quoted 6 lines
mm/slub.c +2
-0@@ -4525,6 +4535,8 @@ __kmem_cache_alias(const char *name, unsigned int size, unsigned int align, s->refcount--; s =NULL ; } + +debugfs_slab_alias (s, name);Here you might be calling
debugfs_slab_alias()with NULL if thesysfs_slab_alias()above returned true.Quoted 3 lines
mm/slub.c +0
-0}return s;...
mm/slub.c static int __init slab_sysfs_init(void) · line 5972
Quoted 13 lines
mm/slub.c +13
-0+static int __init slab_debugfs_init (void ) +{ +struct kmem_cache *s; + + slab_debugfs_root =debugfs_create_dir ("slab" ,NULL ); + + slab_state =FULL ; + +list_for_each_entry (s, &slab_caches, list) +debugfs_slab_add (s); + +while (alias_list) { +struct saved_alias *al = alias_list;
alias_lista single list and bothslab_sysfs_init()andslab_debugfs_init()flush it. So only the init call that happens to be called first, does actually find an unflushed list. I think you
need to use a separate list for debugfs (simpler) or a shared list with both sysfs and debugfs processing (probably more complicated).
Quoted 6 lines
And finally a question, perhaps also for Greg. With sysfs, we hand out the lifecycle of struct
kmem_cacheto sysfs, to ensure we are not reading sysfs files of a cache that has been removed.But with debugfs, what are the guarantees that things won't blow up when a debugfs file is being read while somebody calls
kmem_cache_destroy()on the cache?
It's much harder, but usually the default debugfs_file_create() will handle this for you. See the debugfs_file_create_unsafe() for the "other" variant where you know you can tear things down "safely".
That being said, yes there are still issues in this area, be careful about what tools you expect to be constantly hitting debugfs files.
thanks,
greg k-h
Quoted 12 lines · Greg KH
Quoted 11 lines · Vlastimil Babka
alias_lista single list and bothslab_sysfs_init()andslab_debugfs_init()flush it. So only the init call that happens to be called first, does actually find an unflushed list. I think you
need to use a separate list for debugfs (simpler) or a shared list with both sysfs and debugfs processing (probably more complicated).And finally a question, perhaps also for Greg. With sysfs, we hand out the lifecycle of struct
kmem_cacheto sysfs, to ensure we are not reading sysfs files of a cache that has been removed.
Quoted 6 lines
Quoted 2 lines
But with debugfs, what are the guarantees that things won't blow up when a debugfs file is being read while somebody calls
kmem_cache_destroy()on the cache?It's much harder, but usually the default
debugfs_file_create()will handle this for you. See thedebugfs_file_create_unsafe()for the "other" variant where you know you can tear things down "safely".
Right, so IIUC debugfs will guarantee that while somebody reads the files, the debugfs cleanup will block, as debugfs_file_get() comment explains.
In that case I think we have the cleanup order wrong in this patch:
shutdown_cache() should first do debugfs_slab_release() (which would block) and only then proceed with slab_kmem_cache_release() which destroys the fundamental structures such as kmem_cache_node, which are also accessed by the debugfs file handlers.
Quoted 2 lines
That being said, yes there are still issues in this area, be careful about what tools you expect to be constantly hitting debugfs files.
FWIW, the files are accessible only to root.
Quoted 4 lines
thanks,
greg k-h
Quoted 23 lines · Vlastimil Babka
Quoted 12 lines · Greg KH
Quoted 11 lines · Vlastimil Babka
alias_lista single list and bothslab_sysfs_init()andslab_debugfs_init()flush it. So only the init call that happens to be called first, does actually find an unflushed list. I think you
need to use a separate list for debugfs (simpler) or a shared list with both sysfs and debugfs processing (probably more complicated).And finally a question, perhaps also for Greg. With sysfs, we hand out the lifecycle of struct
kmem_cacheto sysfs, to ensure we are not reading sysfs files of a cache that has been removed.Quoted 6 lines
Quoted 2 lines
But with debugfs, what are the guarantees that things won't blow up when a debugfs file is being read while somebody calls
kmem_cache_destroy()on the cache?It's much harder, but usually the default
debugfs_file_create()will handle this for you. See thedebugfs_file_create_unsafe()for the "other" variant where you know you can tear things down "safely".Right, so IIUC debugfs will guarantee that while somebody reads the files, the debugfs cleanup will block, as
debugfs_file_get()comment explains.
Quoted 7 lines
In that case I think we have the cleanup order wrong in this patch:
shutdown_cache()should first dodebugfs_slab_release()(which would block) and only then proceed withslab_kmem_cache_release()which destroys the fundamental structures such askmem_cache_node, which are also accessed by the debugfs file handlers.
If user is trying to read the data during shutdown_cache(), then I think it's possible user will get empty data, to avoid that we can call debugfs_slab_release() first and then do other stuff in shutdown_cache().
Quoted 10 lines
Quoted 2 lines
That being said, yes there are still issues in this area, be careful about what tools you expect to be constantly hitting debugfs files.
FWIW, the files are accessible only to root.
Quoted 4 lines
thanks,
greg k-h
Quoted 28 lines · Faiyaz Mohammed
Quoted 25 lines · Vlastimil Babka
Quoted 12 lines · Greg KH
Quoted 11 lines · Vlastimil Babka
alias_lista single list and bothslab_sysfs_init()andslab_debugfs_init()flush it. So only the init call that happens to be called first, does actually find an unflushed list. I think you
need to use a separate list for debugfs (simpler) or a shared list with both sysfs and debugfs processing (probably more complicated).And finally a question, perhaps also for Greg. With sysfs, we hand out the lifecycle of struct
kmem_cacheto sysfs, to ensure we are not reading sysfs files of a cache that has been removed.Quoted 6 lines
Quoted 2 lines
But with debugfs, what are the guarantees that things won't blow up when a debugfs file is being read while somebody calls
kmem_cache_destroy()on the cache?It's much harder, but usually the default
debugfs_file_create()will handle this for you. See thedebugfs_file_create_unsafe()for the "other" variant where you know you can tear things down "safely".Right, so IIUC debugfs will guarantee that while somebody reads the files, the debugfs cleanup will block, as
debugfs_file_get()comment explains.In that case I think we have the cleanup order wrong in this patch:
Quoted 7 lines
Quoted 5 lines
shutdown_cache()should first dodebugfs_slab_release()(which would block) and only then proceed withslab_kmem_cache_release()which destroys the fundamental structures such askmem_cache_node, which are also accessed by the debugfs file handlers.If user is trying to read the data during
shutdown_cache(), then I think it's possible user will get empty data, to avoid that we can call
Empty data is fine, when the cache is going away anyway.
Quoted 1 line
debugfs_slab_release()first and then do other stuff inshutdown_cache().
Everything above list_del(&s->list) should be OK, it's equivalent to normal cache operations which the debugfs files must cope with anyway. list_del(&s->list) is OK as the debugfs handlers don't go through the list. It's slab_kmem_cache_release() that matters.
Quoted 11 lines
Quoted 10 lines
Quoted 2 lines
That being said, yes there are still issues in this area, be careful about what tools you expect to be constantly hitting debugfs files.
FWIW, the files are accessible only to root.
Quoted 4 lines
thanks,
greg k-h
Quoted 37 lines · Vlastimil Babka
Quoted 28 lines · Faiyaz Mohammed
Quoted 25 lines · Vlastimil Babka
Quoted 12 lines · Greg KH
Quoted 11 lines · Vlastimil Babka
alias_lista single list and bothslab_sysfs_init()andslab_debugfs_init()flush it. So only the init call that happens to be called first, does actually find an unflushed list. I think you
need to use a separate list for debugfs (simpler) or a shared list with both sysfs and debugfs processing (probably more complicated).And finally a question, perhaps also for Greg. With sysfs, we hand out the lifecycle of struct
kmem_cacheto sysfs, to ensure we are not reading sysfs files of a cache that has been removed.Quoted 6 lines
Quoted 2 lines
But with debugfs, what are the guarantees that things won't blow up when a debugfs file is being read while somebody calls
kmem_cache_destroy()on the cache?It's much harder, but usually the default
debugfs_file_create()will handle this for you. See thedebugfs_file_create_unsafe()for the "other" variant where you know you can tear things down "safely".Right, so IIUC debugfs will guarantee that while somebody reads the files, the debugfs cleanup will block, as
debugfs_file_get()comment explains.In that case I think we have the cleanup order wrong in this patch:
Quoted 7 lines
Quoted 5 lines
shutdown_cache()should first dodebugfs_slab_release()(which would block) and only then proceed withslab_kmem_cache_release()which destroys the fundamental structures such askmem_cache_node, which are also accessed by the debugfs file handlers.If user is trying to read the data during
shutdown_cache(), then I think it's possible user will get empty data, to avoid that we can call
Quoted 9 lines
Empty data is fine, when the cache is going away anyway.
Quoted 1 line
debugfs_slab_release()first and then do other stuff inshutdown_cache().Everything above
list_del(&s->list)should be OK, it's equivalent to normal cache operations which the debugfs files must cope with anyway.list_del(&s->list)is OK as the debugfs handlers don't go through the list. It'sslab_kmem_cache_release()that matters.
okay, I will move debugfs_slab_release() before the slab_kmem_cache_release() in next patch version.
Quoted 12 lines
Quoted 11 lines
Quoted 10 lines
Quoted 2 lines
That being said, yes there are still issues in this area, be careful about what tools you expect to be constantly hitting debugfs files.
FWIW, the files are accessible only to root.
Quoted 4 lines
thanks,
greg k-h
Quoted 11 lines · Vlastimil Babka
Quoted 10 lines · Faiyaz Mohammed
alloc_callsandfree_callsimplementation in sysfs have two issues, one isPAGE_SIZElimitiation of sysfs and other is it does not adhere to "one value per file" rule.To overcome this issues, move the
alloc_callsandfree_callsimplemeation to debugfs.Rename the alloc_calls/free_calls to alloc_traces/free_traces, to be inline with what it does.
Quoted 7 lines
Quoted 2 lines
Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>These were IIRC bot reports for some bugs in the previous versions, so keeping the Reported-by: for the whole patch is misleading - these were not reports for the sysfs issues this patch fixes by moving the files to debugfs.
Yes, I will update in next patch version.
Quoted 22 lines
Quoted 22 lines
Signed-off-by Faiyaz Mohammed <[email protected]>---
changes in V7:
- Drop the olderalloc_callsandfree_callsinterface.
changes in v6:
- https://lore.kernel.org/linux-mm/[email protected]/changes in v5:
- https://lore.kernel.org/linux-mm/[email protected]/changes in v4:
- https://lore.kernel.org/linux-mm/[email protected]/changes in v3:
- https://lore.kernel.org/linux-mm/[email protected]/changes in v2:
- https://lore.kernel.org/linux-mm/[email protected]/changes in v1:
- https://lore.kernel.org/linux-mm/[email protected]/
Quoted 8 lines
Quoted 4 lines
include/linux/slub_def.h | 8 ++ mm/slab_common.c | 9 ++ mm/slub.c | 353 ++++++++++++++++++++++++++++++++++------------- 3 files changed, 276 insertions(+), 94 deletions(-)I don't see any of the symlinks under
/sys/kernel/debug/slab/, so I think the aliases handling code is wrong, and I can see at least two reasons why it could be:
I think I missed one thing, when CONFIG_SLUB_DEBUG_ON enable or slub_debug is pass through command line __kmem_cache_alias() will return null, so no symlinks will be created even if CONFIG_SLAB_MERGE_DEFAULT is enable and to store user data we need to enable CONFIG_SLUB_DEBUG_ON or pass slub_debug through command line.
Quoted 10 lines
mm/slub.c __kmem_cache_alias(const char *name, unsigned int size, unsigned int align, · line 4539
Quoted 6 lines
mm/slub.c +2
-0@@ -4525,6 +4535,8 @@ __kmem_cache_alias(const char *name, unsigned int size, unsigned int align, s->refcount--; s =NULL ; } + +debugfs_slab_alias (s, name);Here you might be calling
debugfs_slab_alias()with NULL if thesysfs_slab_alias()above returned true.
I think we can drop debugfs_slab_alias implementation.
Quoted 17 lines
Quoted 3 lines
mm/slub.c +0
-0}return s;...
Quoted 11 lines
mm/slub.c +11
-0+static int __init slab_debugfs_init (void ) +{ +struct kmem_cache *s; + + slab_debugfs_root =debugfs_create_dir ("slab" ,NULL ); + + slab_state =FULL ; + +list_for_each_entry (s, &slab_caches, list) +debugfs_slab_add (s); +
Quoted 9 lines
mm/slub.c static int __init slab_sysfs_init(void) · line 5972
Quoted 2 lines
mm/slub.c +2
-0+while (alias_list) { +struct saved_alias *al = alias_list;
alias_lista single list and bothslab_sysfs_init()andslab_debugfs_init()flush it. So only the init call that happens to be called first, does actually find an unflushed list. I think you
need to use a separate list for debugfs (simpler) or a shared list with both sysfs and debugfs processing (probably more complicated).
same here, I think we can drop the debugfs alias change.
Quoted 25 lines
And finally a question, perhaps also for Greg. With sysfs, we hand out the lifecycle of struct
kmem_cacheto sysfs, to ensure we are not reading sysfs files of a cache that has been removed.But with debugfs, what are the guarantees that things won't blow up when a debugfs file is being read while somebody calls
kmem_cache_destroy()on the cache?Quoted 17 lines
mm/slub.c +13
-0+ + alias_list = alias_list->next; + +debugfs_slab_alias (al->s, al->name); + + kfree(al); + } + +return 0 ; + +} +__initcall (slab_debugfs_init); +#endif /* * The /proc/slabinfo ABI */
Quoted 9 lines · Faiyaz Mohammed
Quoted 3 lines
I don't see any of the symlinks under
/sys/kernel/debug/slab/, so I think the aliases handling code is wrong, and I can see at least two reasons why it could be:I think I missed one thing, when
CONFIG_SLUB_DEBUG_ONenable orslub_debugis pass through command line__kmem_cache_alias()will return null, so no symlinks will be created even ifCONFIG_SLAB_MERGE_DEFAULTis enable and to store user data we need to enableCONFIG_SLUB_DEBUG_ONor passslub_debugthrough command line.
So you're saying that caches with SLAB_STORE_USER can never be aliases as the merging logic will prevent merging with any debug flag, including STORE_USER. So if we ignore aliases, it means we will not create the debugfs files for caches, where opening the files would just return error, so we don't lose anything by not creating the files in the first place.
In that case, for consistency I would recommend to skip debugfs creation for all caches without SLAB_STORE_USER (even if the caches are not an alias). I think we can make this decision now as it's a whole new debugfs subtree so we don't break any pre-existing code.
Quoted 18 lines · Vlastimil Babka
Quoted 9 lines · Faiyaz Mohammed
Quoted 3 lines
I don't see any of the symlinks under
/sys/kernel/debug/slab/, so I think the aliases handling code is wrong, and I can see at least two reasons why it could be:I think I missed one thing, when
CONFIG_SLUB_DEBUG_ONenable orslub_debugis pass through command line__kmem_cache_alias()will return null, so no symlinks will be created even ifCONFIG_SLAB_MERGE_DEFAULTis enable and to store user data we need to enableCONFIG_SLUB_DEBUG_ONor passslub_debugthrough command line.So you're saying that caches with
SLAB_STORE_USERcan never be aliases as the merging logic will prevent merging with any debug flag, includingSTORE_USER. So if we ignore aliases, it means we will not create the debugfs files for caches, where opening the files would just return error, so we don't lose anything by not creating the files in the first place.
Quoted 5 lines
In that case, for consistency I would recommend to skip debugfs creation for all caches without
SLAB_STORE_USER(even if the caches are not an alias). I think we can make this decision now as it's a whole new debugfs subtree so we don't break any pre-existing code.
Hmmm, I think yes we can skip debugfs creation for all cache withoutSLAB_STORE_USER flag set instead of returning error after opening of
file. I will do the change in next patch version.
Thanks and regards,
Mohammed Faiyaz