linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tools/vm/slabinfo: Handle files in debugfs
@ 2022-03-31 14:03 Stéphane Graber
  2022-04-04 13:40 ` Vlastimil Babka
  0 siblings, 1 reply; 2+ messages in thread
From: Stéphane Graber @ 2022-03-31 14:03 UTC (permalink / raw)
  To: linux-kernel
  Cc: Greg Kroah-Hartman, Andrew Morton, Vlastimil Babka,
	Faiyaz Mohammed, Stéphane Graber, stable

Commit 64dd68497be76 relocated and renamed the alloc_calls and
free_calls files from /sys/kernel/slab/NAME/*_calls over to
/sys/kernel/debug/slab/NAME/*_calls but didn't update the slabinfo tool
with the new location.

This change will now have slabinfo look at the new location (and filenames)
with a fallback to the prior files.

Fixes: 64dd68497be76 ("mm: slub: move sysfs slab alloc/free interfaces to debugfs")
Cc: stable@vger.kernel.org
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Tested-by: Stéphane Graber <stgraber@ubuntu.com>
---
 tools/vm/slabinfo.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/tools/vm/slabinfo.c b/tools/vm/slabinfo.c
index 9b68658b6bb8..5b98f3ee58a5 100644
--- a/tools/vm/slabinfo.c
+++ b/tools/vm/slabinfo.c
@@ -233,6 +233,24 @@ static unsigned long read_slab_obj(struct slabinfo *s, const char *name)
 	return l;
 }
 
+static unsigned long read_debug_slab_obj(struct slabinfo *s, const char *name)
+{
+	char x[128];
+	FILE *f;
+	size_t l;
+
+	snprintf(x, 128, "/sys/kernel/debug/slab/%s/%s", s->name, name);
+	f = fopen(x, "r");
+	if (!f) {
+		buffer[0] = 0;
+		l = 0;
+	} else {
+		l = fread(buffer, 1, sizeof(buffer), f);
+		buffer[l] = 0;
+		fclose(f);
+	}
+	return l;
+}
 
 /*
  * Put a size string together
@@ -409,14 +427,18 @@ static void show_tracking(struct slabinfo *s)
 {
 	printf("\n%s: Kernel object allocation\n", s->name);
 	printf("-----------------------------------------------------------------------\n");
-	if (read_slab_obj(s, "alloc_calls"))
+	if (read_debug_slab_obj(s, "alloc_traces"))
+		printf("%s", buffer);
+	else if (read_slab_obj(s, "alloc_calls"))
 		printf("%s", buffer);
 	else
 		printf("No Data\n");
 
 	printf("\n%s: Kernel object freeing\n", s->name);
 	printf("------------------------------------------------------------------------\n");
-	if (read_slab_obj(s, "free_calls"))
+	if (read_debug_slab_obj(s, "free_traces"))
+		printf("%s", buffer);
+	else if (read_slab_obj(s, "free_calls"))
 		printf("%s", buffer);
 	else
 		printf("No Data\n");
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] tools/vm/slabinfo: Handle files in debugfs
  2022-03-31 14:03 [PATCH] tools/vm/slabinfo: Handle files in debugfs Stéphane Graber
@ 2022-04-04 13:40 ` Vlastimil Babka
  0 siblings, 0 replies; 2+ messages in thread
From: Vlastimil Babka @ 2022-04-04 13:40 UTC (permalink / raw)
  To: Stéphane Graber, linux-kernel
  Cc: Greg Kroah-Hartman, Andrew Morton, Faiyaz Mohammed, stable

On 3/31/22 16:03, Stéphane Graber wrote:
> Commit 64dd68497be76 relocated and renamed the alloc_calls and
> free_calls files from /sys/kernel/slab/NAME/*_calls over to
> /sys/kernel/debug/slab/NAME/*_calls but didn't update the slabinfo tool
> with the new location.
> 
> This change will now have slabinfo look at the new location (and filenames)
> with a fallback to the prior files.
> 
> Fixes: 64dd68497be76 ("mm: slub: move sysfs slab alloc/free interfaces to debugfs")
> Cc: stable@vger.kernel.org
> Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
> Tested-by: Stéphane Graber <stgraber@ubuntu.com>
> ---
>  tools/vm/slabinfo.c | 26 ++++++++++++++++++++++++--
>  1 file changed, 24 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/vm/slabinfo.c b/tools/vm/slabinfo.c
> index 9b68658b6bb8..5b98f3ee58a5 100644
> --- a/tools/vm/slabinfo.c
> +++ b/tools/vm/slabinfo.c
> @@ -233,6 +233,24 @@ static unsigned long read_slab_obj(struct slabinfo *s, const char *name)
>  	return l;
>  }
>  
> +static unsigned long read_debug_slab_obj(struct slabinfo *s, const char *name)
> +{
> +	char x[128];
> +	FILE *f;
> +	size_t l;
> +
> +	snprintf(x, 128, "/sys/kernel/debug/slab/%s/%s", s->name, name);
> +	f = fopen(x, "r");
> +	if (!f) {
> +		buffer[0] = 0;
> +		l = 0;
> +	} else {
> +		l = fread(buffer, 1, sizeof(buffer), f);
> +		buffer[l] = 0;
> +		fclose(f);
> +	}
> +	return l;
> +}

slabinfo is not the nicest code already, but still this basically duplicates
read_slab_obj() just to add a prefix to the path, so it could be done in a
unified way?

>  
>  /*
>   * Put a size string together
> @@ -409,14 +427,18 @@ static void show_tracking(struct slabinfo *s)
>  {
>  	printf("\n%s: Kernel object allocation\n", s->name);
>  	printf("-----------------------------------------------------------------------\n");
> -	if (read_slab_obj(s, "alloc_calls"))
> +	if (read_debug_slab_obj(s, "alloc_traces"))
> +		printf("%s", buffer);
> +	else if (read_slab_obj(s, "alloc_calls"))
>  		printf("%s", buffer);
>  	else
>  		printf("No Data\n");
>  
>  	printf("\n%s: Kernel object freeing\n", s->name);
>  	printf("------------------------------------------------------------------------\n");
> -	if (read_slab_obj(s, "free_calls"))
> +	if (read_debug_slab_obj(s, "free_traces"))
> +		printf("%s", buffer);
> +	else if (read_slab_obj(s, "free_calls"))
>  		printf("%s", buffer);
>  	else
>  		printf("No Data\n");


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-04-04 13:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-31 14:03 [PATCH] tools/vm/slabinfo: Handle files in debugfs Stéphane Graber
2022-04-04 13:40 ` Vlastimil Babka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).