From: Mauricio Faria de Oliveira <mfo@igalia.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Vlastimil Babka <vbabka@suse.cz>
Cc: Oscar Salvador <osalvador@suse.de>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>,
Brendan Jackman <jackmanb@google.com>,
Johannes Weiner <hannes@cmpxchg.org>, Zi Yan <ziy@nvidia.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
kernel-dev@igalia.com
Subject: [PATCH 2/3] mm/page_owner: add option 'print_stack' for 'show_stacks'
Date: Wed, 24 Sep 2025 14:40:22 -0300 [thread overview]
Message-ID: <20250924174023.261125-3-mfo@igalia.com> (raw)
In-Reply-To: <20250924174023.261125-1-mfo@igalia.com>
For monitoring the memory usage per stack trace, it is more efficient to
read _just_ the handle number of the stack traces _without_ stack traces
themselves, and their number of base pages.
The stack traces are required only at the time to associate memory usage
of a handle number with its stack trace (eg, see top-consuming handles).
Before that, it is sufficient to have just the handle number, as it can
be matched with a stack trace later (possible with the previous patch).
This patch adds the option 'print_stack' option (enabled by default) to
print stack traces in 'show_stacks'.
Testing:
- Enable handle numbers:
# echo 1 >/sys/kernel/debug/page_owner_stacks/print_handle
- With stacks (default):
# cat /sys/kernel/debug/page_owner_stacks/show_stacks > f1
- Without stacks (new option):
# echo 0 >/sys/kernel/debug/page_owner_stacks/print_stack
# cat /sys/kernel/debug/page_owner_stacks/show_stacks > f2
- Differences:
# cat f1
get_page_from_freelist+0x14ab/0x16a0
...
do_syscall_64+0xa4/0x290
handle: 15728651
nr_base_pages: 2
get_page_from_freelist+0x14ab/0x16a0
...
do_sys_openat2+0x8a/0xe0
handle: 8388619
nr_base_pages: 16
...
# cat f2
handle: 15728651
nr_base_pages: 2
handle: 8388619
nr_base_pages: 16
...
Signed-off-by: Mauricio Faria de Oliveira <mfo@igalia.com>
---
mm/page_owner.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/mm/page_owner.c b/mm/page_owner.c
index 420426749239..25221676676d 100644
--- a/mm/page_owner.c
+++ b/mm/page_owner.c
@@ -888,6 +888,7 @@ static void *stack_next(struct seq_file *m, void *v, loff_t *ppos)
static unsigned long page_owner_pages_threshold;
static bool page_owner_print_handle;
+static bool page_owner_print_stack = true;
static int stack_print(struct seq_file *m, void *v)
{
@@ -900,15 +901,17 @@ static int stack_print(struct seq_file *m, void *v)
if (!stack->stack_record)
return 0;
- nr_entries = stack_record->size;
- entries = stack_record->entries;
nr_base_pages = refcount_read(&stack_record->count) - 1;
if (nr_base_pages < 1 || nr_base_pages < page_owner_pages_threshold)
return 0;
- for (i = 0; i < nr_entries; i++)
- seq_printf(m, " %pS\n", (void *)entries[i]);
+ if (page_owner_print_stack) {
+ nr_entries = stack_record->size;
+ entries = stack_record->entries;
+ for (i = 0; i < nr_entries; i++)
+ seq_printf(m, " %pS\n", (void *)entries[i]);
+ }
if (page_owner_print_handle)
seq_printf(m, "handle: %d\n", stack_record->handle.handle);
seq_printf(m, "nr_base_pages: %d\n\n", nr_base_pages);
@@ -973,6 +976,8 @@ static int __init pageowner_init(void)
&proc_page_owner_threshold);
debugfs_create_bool("print_handle", 0600, dir,
&page_owner_print_handle);
+ debugfs_create_bool("print_stack", 0600, dir,
+ &page_owner_print_stack);
return 0;
}
--
2.48.1
next prev parent reply other threads:[~2025-09-24 17:40 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-24 17:40 [PATCH 0/3] mm/page_owner: add options 'print_handle' and " Mauricio Faria de Oliveira
2025-09-24 17:40 ` [PATCH 1/3] mm/page_owner: add option 'print_handle' " Mauricio Faria de Oliveira
2025-09-25 20:28 ` Joshua Hahn
2025-09-25 22:25 ` Mauricio Faria de Oliveira
2025-09-24 17:40 ` Mauricio Faria de Oliveira [this message]
2025-09-24 17:40 ` [PATCH 3/3] mm/page_owner: update Documentation with 'print_handle' and 'print_stack' Mauricio Faria de Oliveira
2025-09-25 16:08 ` [PATCH 0/3] mm/page_owner: add options 'print_handle' and 'print_stack' for 'show_stacks' Michal Hocko
2025-09-25 19:38 ` Mauricio Faria de Oliveira
2025-09-26 6:55 ` Michal Hocko
2025-09-26 16:47 ` Mauricio Faria de Oliveira
2025-09-30 14:02 ` Michal Hocko
2025-09-30 14:32 ` Mauricio Faria de Oliveira
2025-10-01 10:58 ` Vlastimil Babka
2025-10-01 17:37 ` Mauricio Faria de Oliveira
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=20250924174023.261125-3-mfo@igalia.com \
--to=mfo@igalia.com \
--cc=akpm@linux-foundation.org \
--cc=hannes@cmpxchg.org \
--cc=jackmanb@google.com \
--cc=kernel-dev@igalia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=osalvador@suse.de \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
--cc=ziy@nvidia.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