From: LiZetao <lizetao.kernel@gmail.com>
To: akpm@linux-foundation.org, surenb@google.com, kent.overstreet@linux.dev
Cc: linux-mm@kvack.org
Subject: [PATCH mm-next] alloc_tag: add total bytes allocation information
Date: Wed, 2 Jul 2025 00:38:06 +0800 [thread overview]
Message-ID: <CALXnTC_TD=wd8o9+dEvDu+yry=T_QBbBnaUZxz2k9k58OkNH-w@mail.gmail.com> (raw)
From bb3537ee638ac80eebcfe9160961e36df8d3ee4c Mon Sep 17 00:00:00 2001
From: Li Zetao <lizetao.kernel@gmail.com>
Date: Tue, 1 Jul 2025 09:30:16 +0000
Subject: [PATCH mm-next] alloc_tag: add total bytes allocation information
Some performance monitoring tools focus on real-time memory
usage anddisplay the total amount of memory applied, which is
convenient for analyzing the memory usage ratio.
Added total information in /proc/allocinfo to feedback the
total amount of memory applied to the user. Example is as
follows:
root:~# cat /proc/allocinfo|tail
98112 168 lib/radix-tree.c:338 func:__radix_tree_preload
12848 22 lib/radix-tree.c:276 func:radix_tree_node_alloc
300760 515 lib/radix-tree.c:253 func:radix_tree_node_alloc
0 0 lib/xarray.c:1214 func:xas_try_split
0 0 lib/xarray.c:1059 func:xas_split_alloc
208488 357 lib/xarray.c:378 func:xas_alloc
0 0 lib/xarray.c:344 func:__xas_nomem
0 0 lib/xarray.c:341 func:__xas_nomem
0 0 lib/xarray.c:309 func:xas_nomem
total: 102208196
Signed-off-by: Li Zetao <lizetao.kernel@gmail.com>
---
lib/alloc_tag.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c
index e9b33848700a..e4e41317a4b7 100644
--- a/lib/alloc_tag.c
+++ b/lib/alloc_tag.c
@@ -43,6 +43,7 @@ int alloc_tag_ref_offs;
struct allocinfo_private {
struct codetag_iterator iter;
bool print_header;
+ long long total;
};
static void *allocinfo_start(struct seq_file *m, loff_t *pos)
@@ -53,6 +54,7 @@ static void *allocinfo_start(struct seq_file *m, loff_t *pos)
priv = (struct allocinfo_private *)m->private;
codetag_lock_module_list(alloc_tag_cttype, true);
if (node == 0) {
+ priv->total = 0;
priv->print_header = true;
priv->iter = codetag_get_ct_iter(alloc_tag_cttype);
codetag_next_ct(&priv->iter);
@@ -66,8 +68,16 @@ static void *allocinfo_next(struct seq_file *m,
void *arg, loff_t *pos)
struct codetag *ct = codetag_next_ct(&priv->iter);
(*pos)++;
- if (!ct)
+ if (!ct) {
+ char *bufp;
+ size_t n = seq_get_buf(m, &bufp);
+ struct seq_buf buf;
+
+ seq_buf_init(&buf, bufp, n);
+ seq_buf_printf(&buf, "total: %llu\n", priv->total);
+ seq_commit(m, seq_buf_used(&buf));
return NULL;
+ }
return priv;
}
@@ -84,11 +94,13 @@ static void print_allocinfo_header(struct seq_buf *buf)
seq_buf_printf(buf, "# <size> <calls> <tag info>\n");
}
-static void alloc_tag_to_text(struct seq_buf *out, struct codetag *ct)
+static void alloc_tag_to_text(struct seq_buf *out, struct
allocinfo_private *priv)
{
+ struct codetag *ct = priv->iter.ct;
struct alloc_tag *tag = ct_to_alloc_tag(ct);
struct alloc_tag_counters counter = alloc_tag_read(tag);
s64 bytes = counter.bytes;
+ priv->total += bytes;
seq_buf_printf(out, "%12lli %8llu ", bytes, counter.calls);
codetag_to_text(out, ct);
@@ -108,7 +120,7 @@ static int allocinfo_show(struct seq_file *m, void *arg)
print_allocinfo_header(&buf);
priv->print_header = false;
}
- alloc_tag_to_text(&buf, priv->iter.ct);
+ alloc_tag_to_text(&buf, priv);
seq_commit(m, seq_buf_used(&buf));
return 0;
}
--
2.34.1
next reply other threads:[~2025-07-01 16:38 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-01 16:38 LiZetao [this message]
2025-07-02 17:14 ` Kent Overstreet
2025-07-02 20:19 ` Steven Rostedt
2025-07-06 6:01 ` Li Zetao
2025-07-06 15:21 ` Kent Overstreet
2025-07-08 2:05 ` Suren Baghdasaryan
2025-07-08 2:16 ` Kent Overstreet
2025-07-08 14:38 ` Suren Baghdasaryan
2025-07-08 15:13 ` Kent Overstreet
2025-07-08 15:22 ` Suren Baghdasaryan
2025-07-08 17:23 ` Kent Overstreet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CALXnTC_TD=wd8o9+dEvDu+yry=T_QBbBnaUZxz2k9k58OkNH-w@mail.gmail.com' \
--to=lizetao.kernel@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=kent.overstreet@linux.dev \
--cc=linux-mm@kvack.org \
--cc=surenb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox