[PATCH] slab: add flags in cache_show

Kassey Li posted 1 patch 3 months, 3 weeks ago
mm/slab_common.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
[PATCH] slab: add flags in cache_show
Posted by Kassey Li 3 months, 3 weeks ago
Flags info is useful to check the slab type.

for example, _SLAB_RECLAIM_ACCOUNT:

    0x50100 _SLAB_PANIC _SLAB_RECLAIM_ACCOUNT _SLAB_CMPXCHG_DOUBLE

Signed-off-by: Kassey Li <kassey.li@oss.qualcomm.com>
---
 mm/slab_common.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mm/slab_common.c b/mm/slab_common.c
index 932d13ada36c..f43239211e69 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -1083,7 +1083,7 @@ static void print_slabinfo_header(struct seq_file *m)
 	 * without _too_ many complaints.
 	 */
 	seq_puts(m, "slabinfo - version: 2.1\n");
-	seq_puts(m, "# name            <active_objs> <num_objs> <objsize> <objperslab> <pagesperslab>");
+	seq_puts(m, "# name            <active_objs> <num_objs> <objsize> <objperslab> <pagesperslab> <flags>");
 	seq_puts(m, " : tunables <limit> <batchcount> <sharedfactor>");
 	seq_puts(m, " : slabdata <active_slabs> <num_slabs> <sharedavail>");
 	seq_putc(m, '\n');
@@ -1112,9 +1112,9 @@ static void cache_show(struct kmem_cache *s, struct seq_file *m)
 	memset(&sinfo, 0, sizeof(sinfo));
 	get_slabinfo(s, &sinfo);
 
-	seq_printf(m, "%-17s %6lu %6lu %6u %4u %4d",
+	seq_printf(m, "%-17s %6lu %6lu %6u %4u %4d 0x%-8x",
 		   s->name, sinfo.active_objs, sinfo.num_objs, s->size,
-		   sinfo.objects_per_slab, (1 << sinfo.cache_order));
+		   sinfo.objects_per_slab, (1 << sinfo.cache_order), s->flags);
 
 	seq_printf(m, " : tunables %4u %4u %4u",
 		   sinfo.limit, sinfo.batchcount, sinfo.shared);
-- 
2.34.1
Re: [PATCH] slab: add flags in cache_show
Posted by Vlastimil Babka 3 months, 3 weeks ago
On 10/17/25 08:48, Kassey Li wrote:
> Flags info is useful to check the slab type.
> 
> for example, _SLAB_RECLAIM_ACCOUNT:
> 
>     0x50100 _SLAB_PANIC _SLAB_RECLAIM_ACCOUNT _SLAB_CMPXCHG_DOUBLE
> 
> Signed-off-by: Kassey Li <kassey.li@oss.qualcomm.com>

Many of the flags are represented by files in /sys/kernel/slab/<cache>/
If you miss some, we could add it there. Changing slabinfo output could
break some users and the raw hex value is not a stable representation of the
flags anyway.

> ---
>  mm/slab_common.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/mm/slab_common.c b/mm/slab_common.c
> index 932d13ada36c..f43239211e69 100644
> --- a/mm/slab_common.c
> +++ b/mm/slab_common.c
> @@ -1083,7 +1083,7 @@ static void print_slabinfo_header(struct seq_file *m)
>  	 * without _too_ many complaints.
>  	 */
>  	seq_puts(m, "slabinfo - version: 2.1\n");
> -	seq_puts(m, "# name            <active_objs> <num_objs> <objsize> <objperslab> <pagesperslab>");
> +	seq_puts(m, "# name            <active_objs> <num_objs> <objsize> <objperslab> <pagesperslab> <flags>");
>  	seq_puts(m, " : tunables <limit> <batchcount> <sharedfactor>");
>  	seq_puts(m, " : slabdata <active_slabs> <num_slabs> <sharedavail>");
>  	seq_putc(m, '\n');
> @@ -1112,9 +1112,9 @@ static void cache_show(struct kmem_cache *s, struct seq_file *m)
>  	memset(&sinfo, 0, sizeof(sinfo));
>  	get_slabinfo(s, &sinfo);
>  
> -	seq_printf(m, "%-17s %6lu %6lu %6u %4u %4d",
> +	seq_printf(m, "%-17s %6lu %6lu %6u %4u %4d 0x%-8x",
>  		   s->name, sinfo.active_objs, sinfo.num_objs, s->size,
> -		   sinfo.objects_per_slab, (1 << sinfo.cache_order));
> +		   sinfo.objects_per_slab, (1 << sinfo.cache_order), s->flags);
>  
>  	seq_printf(m, " : tunables %4u %4u %4u",
>  		   sinfo.limit, sinfo.batchcount, sinfo.shared);