All of lore.kernel.org
 help / color / mirror / Atom feed
* + lib-add-version-into-proc-allocinfo-output.patch added to mm-unstable branch
@ 2024-05-14 20:20 Andrew Morton
  2024-05-18 21:03 ` Vlastimil Babka
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Morton @ 2024-05-14 20:20 UTC (permalink / raw)
  To: mm-commits, vbabka, pasha.tatashin, kent.overstreet, keescook,
	surenb, akpm


The patch titled
     Subject: lib: add version into /proc/allocinfo output
has been added to the -mm mm-unstable branch.  Its filename is
     lib-add-version-into-proc-allocinfo-output.patch

This patch will shortly appear at
     https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/lib-add-version-into-proc-allocinfo-output.patch

This patch will later appear in the mm-unstable branch at
    git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next via the mm-everything
branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there every 2-3 working days

------------------------------------------------------
From: Suren Baghdasaryan <surenb@google.com>
Subject: lib: add version into /proc/allocinfo output
Date: Tue, 14 May 2024 09:31:28 -0700

Add version string and a header at the beginning of /proc/allocinfo to
allow later format changes.  Example output:

> head /proc/allocinfo
allocinfo - version: 1.0
#     <size>  <calls> <tag info>
           0        0 init/main.c:1314 func:do_initcalls
           0        0 init/do_mounts.c:353 func:mount_nodev_root
           0        0 init/do_mounts.c:187 func:mount_root_generic
           0        0 init/do_mounts.c:158 func:do_mount_root
           0        0 init/initramfs.c:493 func:unpack_to_rootfs
           0        0 init/initramfs.c:492 func:unpack_to_rootfs
           0        0 init/initramfs.c:491 func:unpack_to_rootfs
         512        1 arch/x86/events/rapl.c:681 func:init_rapl_pmus
         128        1 arch/x86/events/rapl.c:571 func:rapl_cpu_online

Link: https://lkml.kernel.org/r/20240514163128.3662251-1-surenb@google.com
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Cc: Kent Overstreet <kent.overstreet@linux.dev>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 Documentation/filesystems/proc.rst |    5 +-
 lib/alloc_tag.c                    |   48 ++++++++++++++++++---------
 2 files changed, 36 insertions(+), 17 deletions(-)

--- a/Documentation/filesystems/proc.rst~lib-add-version-into-proc-allocinfo-output
+++ a/Documentation/filesystems/proc.rst
@@ -961,13 +961,14 @@ Provides information about memory alloca
 base. Each allocation in the code is identified by its source file, line
 number, module (if originates from a loadable module) and the function calling
 the allocation. The number of bytes allocated and number of calls at each
-location are reported.
+location are reported. The first line indicates the version of the file, the
+second line is the header listing fields in the file.
 
 Example output.
 
 ::
 
-    > sort -rn /proc/allocinfo
+    > tail -n +3 /proc/allocinfo | sort -rn
    127664128    31168 mm/page_ext.c:270 func:alloc_page_ext
     56373248     4737 mm/slub.c:2259 func:alloc_slab_page
     14880768     3633 mm/readahead.c:247 func:page_cache_ra_unbounded
--- a/lib/alloc_tag.c~lib-add-version-into-proc-allocinfo-output
+++ a/lib/alloc_tag.c
@@ -16,47 +16,61 @@ EXPORT_SYMBOL(_shared_alloc_tag);
 DEFINE_STATIC_KEY_MAYBE(CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT,
 			mem_alloc_profiling_key);
 
+struct allocinfo_private {
+	struct codetag_iterator iter;
+	bool print_header;
+
+};
+
 static void *allocinfo_start(struct seq_file *m, loff_t *pos)
 {
-	struct codetag_iterator *iter;
+	struct allocinfo_private *priv;
 	struct codetag *ct;
 	loff_t node = *pos;
 
-	iter = kzalloc(sizeof(*iter), GFP_KERNEL);
-	m->private = iter;
-	if (!iter)
+	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+	m->private = priv;
+	if (!priv)
 		return NULL;
 
+	priv->print_header = (node == 0);
 	codetag_lock_module_list(alloc_tag_cttype, true);
-	*iter = codetag_get_ct_iter(alloc_tag_cttype);
-	while ((ct = codetag_next_ct(iter)) != NULL && node)
+	priv->iter = codetag_get_ct_iter(alloc_tag_cttype);
+	while ((ct = codetag_next_ct(&priv->iter)) != NULL && node)
 		node--;
 
-	return ct ? iter : NULL;
+	return ct ? priv : NULL;
 }
 
 static void *allocinfo_next(struct seq_file *m, void *arg, loff_t *pos)
 {
-	struct codetag_iterator *iter = (struct codetag_iterator *)arg;
-	struct codetag *ct = codetag_next_ct(iter);
+	struct allocinfo_private *priv = (struct allocinfo_private *)arg;
+	struct codetag *ct = codetag_next_ct(&priv->iter);
 
 	(*pos)++;
 	if (!ct)
 		return NULL;
 
-	return iter;
+	return priv;
 }
 
 static void allocinfo_stop(struct seq_file *m, void *arg)
 {
-	struct codetag_iterator *iter = (struct codetag_iterator *)m->private;
+	struct allocinfo_private *priv = (struct allocinfo_private *)m->private;
 
-	if (iter) {
+	if (priv) {
 		codetag_lock_module_list(alloc_tag_cttype, false);
-		kfree(iter);
+		kfree(priv);
 	}
 }
 
+static void print_allocinfo_header(struct seq_buf *buf)
+{
+	/* Output format version, so we can change it. */
+	seq_buf_printf(buf, "allocinfo - version: 1.0\n");
+	seq_buf_printf(buf, "#     <size>  <calls> <tag info>\n");
+}
+
 static void alloc_tag_to_text(struct seq_buf *out, struct codetag *ct)
 {
 	struct alloc_tag *tag = ct_to_alloc_tag(ct);
@@ -71,13 +85,17 @@ static void alloc_tag_to_text(struct seq
 
 static int allocinfo_show(struct seq_file *m, void *arg)
 {
-	struct codetag_iterator *iter = (struct codetag_iterator *)arg;
+	struct allocinfo_private *priv = (struct allocinfo_private *)arg;
 	char *bufp;
 	size_t n = seq_get_buf(m, &bufp);
 	struct seq_buf buf;
 
 	seq_buf_init(&buf, bufp, n);
-	alloc_tag_to_text(&buf, iter->ct);
+	if (priv->print_header) {
+		print_allocinfo_header(&buf);
+		priv->print_header = false;
+	}
+	alloc_tag_to_text(&buf, priv->iter.ct);
 	seq_commit(m, seq_buf_used(&buf));
 	return 0;
 }
_

Patches currently in -mm which might be from surenb@google.com are

lib-add-version-into-proc-allocinfo-output.patch


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

* Re: + lib-add-version-into-proc-allocinfo-output.patch added to mm-unstable branch
  2024-05-14 20:20 + lib-add-version-into-proc-allocinfo-output.patch added to mm-unstable branch Andrew Morton
@ 2024-05-18 21:03 ` Vlastimil Babka
  2024-05-18 23:20   ` Kees Cook
  2024-05-19  5:56   ` Andrew Morton
  0 siblings, 2 replies; 6+ messages in thread
From: Vlastimil Babka @ 2024-05-18 21:03 UTC (permalink / raw)
  To: Andrew Morton, mm-commits, pasha.tatashin, kent.overstreet,
	keescook, surenb

On 5/14/24 10:20 PM, Andrew Morton wrote:
> The patch titled
>      Subject: lib: add version into /proc/allocinfo output
> has been added to the -mm mm-unstable branch.  Its filename is

Hi, I don't know how mm-unstable/mm-hotfixes-unstable is handled during and
right after the merge window, so maybe it's already the plan, but wanted to
note that for this patch to set the userspace ABI with versioning right
away, it should go in before 5.10 is released, and maybe even in the merge
window itself so the version line is already there at 5.10-rc1.

Thanks,
Vlastimil

Also:
Acked-by: Vlastimil Babka <vbabka@suse.cz>

>      lib-add-version-into-proc-allocinfo-output.patch
> 
> This patch will shortly appear at
>      https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/lib-add-version-into-proc-allocinfo-output.patch
> 
> This patch will later appear in the mm-unstable branch at
>     git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
> 
> Before you just go and hit "reply", please:
>    a) Consider who else should be cc'ed
>    b) Prefer to cc a suitable mailing list as well
>    c) Ideally: find the original patch on the mailing list and do a
>       reply-to-all to that, adding suitable additional cc's
> 
> *** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
> 
> The -mm tree is included into linux-next via the mm-everything
> branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
> and is updated there every 2-3 working days
> 
> ------------------------------------------------------
> From: Suren Baghdasaryan <surenb@google.com>
> Subject: lib: add version into /proc/allocinfo output
> Date: Tue, 14 May 2024 09:31:28 -0700
> 
> Add version string and a header at the beginning of /proc/allocinfo to
> allow later format changes.  Example output:
> 
>> head /proc/allocinfo
> allocinfo - version: 1.0
> #     <size>  <calls> <tag info>
>            0        0 init/main.c:1314 func:do_initcalls
>            0        0 init/do_mounts.c:353 func:mount_nodev_root
>            0        0 init/do_mounts.c:187 func:mount_root_generic
>            0        0 init/do_mounts.c:158 func:do_mount_root
>            0        0 init/initramfs.c:493 func:unpack_to_rootfs
>            0        0 init/initramfs.c:492 func:unpack_to_rootfs
>            0        0 init/initramfs.c:491 func:unpack_to_rootfs
>          512        1 arch/x86/events/rapl.c:681 func:init_rapl_pmus
>          128        1 arch/x86/events/rapl.c:571 func:rapl_cpu_online
> 
> Link: https://lkml.kernel.org/r/20240514163128.3662251-1-surenb@google.com
> Signed-off-by: Suren Baghdasaryan <surenb@google.com>
> Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com>
> Reviewed-by: Kees Cook <keescook@chromium.org>
> Cc: Kent Overstreet <kent.overstreet@linux.dev>
> Cc: Vlastimil Babka <vbabka@suse.cz>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> ---
> 
>  Documentation/filesystems/proc.rst |    5 +-
>  lib/alloc_tag.c                    |   48 ++++++++++++++++++---------
>  2 files changed, 36 insertions(+), 17 deletions(-)
> 
> --- a/Documentation/filesystems/proc.rst~lib-add-version-into-proc-allocinfo-output
> +++ a/Documentation/filesystems/proc.rst
> @@ -961,13 +961,14 @@ Provides information about memory alloca
>  base. Each allocation in the code is identified by its source file, line
>  number, module (if originates from a loadable module) and the function calling
>  the allocation. The number of bytes allocated and number of calls at each
> -location are reported.
> +location are reported. The first line indicates the version of the file, the
> +second line is the header listing fields in the file.
>  
>  Example output.
>  
>  ::
>  
> -    > sort -rn /proc/allocinfo
> +    > tail -n +3 /proc/allocinfo | sort -rn
>     127664128    31168 mm/page_ext.c:270 func:alloc_page_ext
>      56373248     4737 mm/slub.c:2259 func:alloc_slab_page
>      14880768     3633 mm/readahead.c:247 func:page_cache_ra_unbounded
> --- a/lib/alloc_tag.c~lib-add-version-into-proc-allocinfo-output
> +++ a/lib/alloc_tag.c
> @@ -16,47 +16,61 @@ EXPORT_SYMBOL(_shared_alloc_tag);
>  DEFINE_STATIC_KEY_MAYBE(CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT,
>  			mem_alloc_profiling_key);
>  
> +struct allocinfo_private {
> +	struct codetag_iterator iter;
> +	bool print_header;
> +
> +};
> +
>  static void *allocinfo_start(struct seq_file *m, loff_t *pos)
>  {
> -	struct codetag_iterator *iter;
> +	struct allocinfo_private *priv;
>  	struct codetag *ct;
>  	loff_t node = *pos;
>  
> -	iter = kzalloc(sizeof(*iter), GFP_KERNEL);
> -	m->private = iter;
> -	if (!iter)
> +	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
> +	m->private = priv;
> +	if (!priv)
>  		return NULL;
>  
> +	priv->print_header = (node == 0);
>  	codetag_lock_module_list(alloc_tag_cttype, true);
> -	*iter = codetag_get_ct_iter(alloc_tag_cttype);
> -	while ((ct = codetag_next_ct(iter)) != NULL && node)
> +	priv->iter = codetag_get_ct_iter(alloc_tag_cttype);
> +	while ((ct = codetag_next_ct(&priv->iter)) != NULL && node)
>  		node--;
>  
> -	return ct ? iter : NULL;
> +	return ct ? priv : NULL;
>  }
>  
>  static void *allocinfo_next(struct seq_file *m, void *arg, loff_t *pos)
>  {
> -	struct codetag_iterator *iter = (struct codetag_iterator *)arg;
> -	struct codetag *ct = codetag_next_ct(iter);
> +	struct allocinfo_private *priv = (struct allocinfo_private *)arg;
> +	struct codetag *ct = codetag_next_ct(&priv->iter);
>  
>  	(*pos)++;
>  	if (!ct)
>  		return NULL;
>  
> -	return iter;
> +	return priv;
>  }
>  
>  static void allocinfo_stop(struct seq_file *m, void *arg)
>  {
> -	struct codetag_iterator *iter = (struct codetag_iterator *)m->private;
> +	struct allocinfo_private *priv = (struct allocinfo_private *)m->private;
>  
> -	if (iter) {
> +	if (priv) {
>  		codetag_lock_module_list(alloc_tag_cttype, false);
> -		kfree(iter);
> +		kfree(priv);
>  	}
>  }
>  
> +static void print_allocinfo_header(struct seq_buf *buf)
> +{
> +	/* Output format version, so we can change it. */
> +	seq_buf_printf(buf, "allocinfo - version: 1.0\n");
> +	seq_buf_printf(buf, "#     <size>  <calls> <tag info>\n");
> +}
> +
>  static void alloc_tag_to_text(struct seq_buf *out, struct codetag *ct)
>  {
>  	struct alloc_tag *tag = ct_to_alloc_tag(ct);
> @@ -71,13 +85,17 @@ static void alloc_tag_to_text(struct seq
>  
>  static int allocinfo_show(struct seq_file *m, void *arg)
>  {
> -	struct codetag_iterator *iter = (struct codetag_iterator *)arg;
> +	struct allocinfo_private *priv = (struct allocinfo_private *)arg;
>  	char *bufp;
>  	size_t n = seq_get_buf(m, &bufp);
>  	struct seq_buf buf;
>  
>  	seq_buf_init(&buf, bufp, n);
> -	alloc_tag_to_text(&buf, iter->ct);
> +	if (priv->print_header) {
> +		print_allocinfo_header(&buf);
> +		priv->print_header = false;
> +	}
> +	alloc_tag_to_text(&buf, priv->iter.ct);
>  	seq_commit(m, seq_buf_used(&buf));
>  	return 0;
>  }
> _
> 
> Patches currently in -mm which might be from surenb@google.com are
> 
> lib-add-version-into-proc-allocinfo-output.patch
> 


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

* Re: + lib-add-version-into-proc-allocinfo-output.patch added to mm-unstable branch
  2024-05-18 21:03 ` Vlastimil Babka
@ 2024-05-18 23:20   ` Kees Cook
  2024-05-19  5:56   ` Andrew Morton
  1 sibling, 0 replies; 6+ messages in thread
From: Kees Cook @ 2024-05-18 23:20 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: Andrew Morton, mm-commits, pasha.tatashin, kent.overstreet,
	surenb

On Sat, May 18, 2024 at 11:03:52PM +0200, Vlastimil Babka wrote:
> On 5/14/24 10:20 PM, Andrew Morton wrote:
> > The patch titled
> >      Subject: lib: add version into /proc/allocinfo output
> > has been added to the -mm mm-unstable branch.  Its filename is
> 
> Hi, I don't know how mm-unstable/mm-hotfixes-unstable is handled during and
> right after the merge window, so maybe it's already the plan, but wanted to
> note that for this patch to set the userspace ABI with versioning right
> away, it should go in before 5.10 is released, and maybe even in the merge
> window itself so the version line is already there at 5.10-rc1.

6.10, but yes, agreed. :)

I'm really looking forward to seeing the allocation profiling land!

-Kees

-- 
Kees Cook

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

* Re: + lib-add-version-into-proc-allocinfo-output.patch added to mm-unstable branch
  2024-05-18 21:03 ` Vlastimil Babka
  2024-05-18 23:20   ` Kees Cook
@ 2024-05-19  5:56   ` Andrew Morton
  2024-05-19 14:20     ` Suren Baghdasaryan
  2024-05-19 22:09     ` Vlastimil Babka
  1 sibling, 2 replies; 6+ messages in thread
From: Andrew Morton @ 2024-05-19  5:56 UTC (permalink / raw)
  To: Vlastimil Babka
  Cc: mm-commits, pasha.tatashin, kent.overstreet, keescook, surenb

On Sat, 18 May 2024 23:03:52 +0200 Vlastimil Babka <vbabka@suse.cz> wrote:

> On 5/14/24 10:20 PM, Andrew Morton wrote:
> > The patch titled
> >      Subject: lib: add version into /proc/allocinfo output
> > has been added to the -mm mm-unstable branch.  Its filename is
> 
> Hi, I don't know how mm-unstable/mm-hotfixes-unstable is handled during and
> right after the merge window, so maybe it's already the plan, but wanted to
> note that for this patch to set the userspace ABI with versioning right
> away, it should go in before 5.10 is released, and maybe even in the merge
> window itself so the version line is already there at 5.10-rc1.

I assume you mean 6.10.

Yes, I'll either build a little mm-stable for -rc1 or I'll add it to
hotfixes for 6.10-rcX.

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

* Re: + lib-add-version-into-proc-allocinfo-output.patch added to mm-unstable branch
  2024-05-19  5:56   ` Andrew Morton
@ 2024-05-19 14:20     ` Suren Baghdasaryan
  2024-05-19 22:09     ` Vlastimil Babka
  1 sibling, 0 replies; 6+ messages in thread
From: Suren Baghdasaryan @ 2024-05-19 14:20 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Vlastimil Babka, mm-commits, pasha.tatashin, kent.overstreet,
	keescook

On Sat, May 18, 2024 at 10:57 PM Andrew Morton
<akpm@linux-foundation.org> wrote:
>
> On Sat, 18 May 2024 23:03:52 +0200 Vlastimil Babka <vbabka@suse.cz> wrote:
>
> > On 5/14/24 10:20 PM, Andrew Morton wrote:
> > > The patch titled
> > >      Subject: lib: add version into /proc/allocinfo output
> > > has been added to the -mm mm-unstable branch.  Its filename is
> >
> > Hi, I don't know how mm-unstable/mm-hotfixes-unstable is handled during and
> > right after the merge window, so maybe it's already the plan, but wanted to
> > note that for this patch to set the userspace ABI with versioning right
> > away, it should go in before 5.10 is released, and maybe even in the merge
> > window itself so the version line is already there at 5.10-rc1.
>
> I assume you mean 6.10.
>
> Yes, I'll either build a little mm-stable for -rc1 or I'll add it to
> hotfixes for 6.10-rcX.

Perfect! Thank you folks!

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

* Re: + lib-add-version-into-proc-allocinfo-output.patch added to mm-unstable branch
  2024-05-19  5:56   ` Andrew Morton
  2024-05-19 14:20     ` Suren Baghdasaryan
@ 2024-05-19 22:09     ` Vlastimil Babka
  1 sibling, 0 replies; 6+ messages in thread
From: Vlastimil Babka @ 2024-05-19 22:09 UTC (permalink / raw)
  To: Andrew Morton
  Cc: mm-commits, pasha.tatashin, kent.overstreet, keescook, surenb

On 5/19/24 7:56 AM, Andrew Morton wrote:
> On Sat, 18 May 2024 23:03:52 +0200 Vlastimil Babka <vbabka@suse.cz> wrote:
> 
>> On 5/14/24 10:20 PM, Andrew Morton wrote:
>> > The patch titled
>> >      Subject: lib: add version into /proc/allocinfo output
>> > has been added to the -mm mm-unstable branch.  Its filename is
>> 
>> Hi, I don't know how mm-unstable/mm-hotfixes-unstable is handled during and
>> right after the merge window, so maybe it's already the plan, but wanted to
>> note that for this patch to set the userspace ABI with versioning right
>> away, it should go in before 5.10 is released, and maybe even in the merge
>> window itself so the version line is already there at 5.10-rc1.
> 
> I assume you mean 6.10.

Yep, I blame jetlag :)

> Yes, I'll either build a little mm-stable for -rc1 or I'll add it to
> hotfixes for 6.10-rcX.

Great, thanks.

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

end of thread, other threads:[~2024-05-19 22:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-14 20:20 + lib-add-version-into-proc-allocinfo-output.patch added to mm-unstable branch Andrew Morton
2024-05-18 21:03 ` Vlastimil Babka
2024-05-18 23:20   ` Kees Cook
2024-05-19  5:56   ` Andrew Morton
2024-05-19 14:20     ` Suren Baghdasaryan
2024-05-19 22:09     ` Vlastimil Babka

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.