From: "zhen.ni" <zhen.ni@easystack.cn>
To: Zi Yan <ziy@nvidia.com>
Cc: akpm@linux-foundation.org, vbabka@kernel.org, surenb@google.com,
mhocko@suse.com, jackmanb@google.com, hannes@cmpxchg.org,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/3] mm/page_owner: add print_mode filter
Date: Wed, 29 Apr 2026 19:42:04 +0800 [thread overview]
Message-ID: <38340de6-c729-4b04-a42b-36cbd6585c9c@easystack.cn> (raw)
In-Reply-To: <CBB2A60B-7491-4D93-89B8-941832DD0478@nvidia.com>
在 2026/4/28 21:20, Zi Yan 写道:
> On 27 Apr 2026, at 23:36, zhen.ni wrote:
>
>> 在 2026/4/27 23:43, Zi Yan 写道:
>>> On 19 Apr 2026, at 11:55, Zhen Ni wrote:
>>>
>>>> Add print_mode functionality to reduce page_owner output size by
>>>> printing only the stack handle instead of the full stack trace.
>>>>
>>>> Example output with print_mode enabled:
>>>> Page allocated via order 0, mask 0x42800(GFP_NOWAIT|__GFP_COMP),
>>>> pid 1, tgid 1 (systemd), ts 349667370 ns
>>>> PFN 0xa00a2 type Unmovable Block 1280 type Unmovable
>>>> Flags 0x33fffe0000004124(referenced|lru|active|private|node=3|zone=0|
>>>> lastcpupid=0x1ffff)
>>>> handle: 17432583
>>>> Charged to memcg /
>>>>
>>>> Print mode significantly reduces output size while preserving all
>>>> other page allocation information. The correspondence between handles
>>>> and stack traces can be obtained through the show_stacks_handles interface.
>>>>
>>>> Link: https://lore.kernel.org/linux-mm/20260417154638.22370-3-zhen.ni@easystack.cn/
>>>> Suggested-by: Zi Yan <ziy@nvidia.com>
>>>> Signed-off-by: Zhen Ni <zhen.ni@easystack.cn>
>>>> ---
>>>>
>>>> Changes in v2:
>>>> - Renamed from 'compact mode' to 'print_mode' for better clarity
>>>> - Use enum values (0=full_stack, 1=stack_handle) instead of boolean
>>>> - Update debugfs filename from 'compact' to 'print_mode'
>>>> ---
>>>> mm/page_owner.c | 28 +++++++++++++++++++++++++++-
>>>> 1 file changed, 27 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/mm/page_owner.c b/mm/page_owner.c
>>>> index 5884d883837e..6d87b6948cfa 100644
>>>> --- a/mm/page_owner.c
>>>> +++ b/mm/page_owner.c
>>>> @@ -590,7 +590,13 @@ print_page_owner(char __user *buf, size_t count, unsigned long pfn,
>>>> migratetype_names[pageblock_mt],
>>>> &page->flags);
>>>>
>>>> - ret += stack_depot_snprint(handle, kbuf + ret, count - ret, 0);
>>>> + /* Print mode: full stack or stack handle */
>>>> + if (READ_ONCE(owner_filter.print_mode) == PAGE_OWNER_PRINT_STACK_HANDLE) {
>>>> + ret += scnprintf(kbuf + ret, count - ret,
>>>> + "handle: %d\n", handle);
>>>> + } else {
>>>> + ret += stack_depot_snprint(handle, kbuf + ret, count - ret, 0);
>>>> + }
>>>> if (ret >= count)
>>>> goto err;
>>>>
>>>> @@ -985,6 +991,24 @@ static int page_owner_threshold_set(void *data, u64 val)
>>>> DEFINE_SIMPLE_ATTRIBUTE(page_owner_threshold_fops, &page_owner_threshold_get,
>>>> &page_owner_threshold_set, "%llu");
>>>>
>>>> +static int page_owner_print_mode_get(void *data, u64 *val)
>>>> +{
>>>> + *val = READ_ONCE(owner_filter.print_mode);
>>>> + return 0;
>>>> +}
>>>> +
>>>> +static int page_owner_print_mode_set(void *data, u64 val)
>>>> +{
>>>> + if (val > PAGE_OWNER_PRINT_STACK_HANDLE)
>>>> + return -EINVAL;
>>>> + WRITE_ONCE(owner_filter.print_mode, val);
>>>> + return 0;
>>>> +}
>>>> +
>>>> +DEFINE_SIMPLE_ATTRIBUTE(page_owner_print_mode_fops,
>>>> + &page_owner_print_mode_get,
>>>> + &page_owner_print_mode_set, "%lld");
>>>> +
>>>>
>>>> static int __init pageowner_init(void)
>>>> {
>>>> @@ -998,6 +1022,8 @@ static int __init pageowner_init(void)
>>>> debugfs_create_file("page_owner", 0400, NULL, NULL, &page_owner_fops);
>>>>
>>>> filter_dir = debugfs_create_dir("page_owner_filter", NULL);
>>>> + debugfs_create_file("print_mode", 0600, filter_dir, NULL,
>>>> + &page_owner_print_mode_fops);
>>>>
>>>> dir = debugfs_create_dir("page_owner_stacks", NULL);
>>>> debugfs_create_file("show_stacks", 0400, dir,
>>>> --
>>>> 2.20.1
>>>
>>> I think it is more user-friendly to use “full_stack” and “stack_handle”
>>> instead of 0 and 1. You can refer to [1] to sysfs_match_string() to
>>> do that. I was testing the interface, but needed to look at your code
>>> to know which print_mode I am using. ;)
>>>
>>>
>>> [1] https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git/tree/mm/huge_memory.c?h=mm-everything#n380
>>>
>>>
>>
>> Thanks for the suggestion!
>>
>> I considered using "full_stack" and "stack_handle" strings, but
>> I think the numeric values (0/1) are more concise and easier to type
>> for users.
>
> I disagree. It is hard for user to know what the current print mode
> is and what available modes are. 0 or 1 is usually for boolean input.
>
> Something like:
> [full_stack] stack_handle
> full_stack [stack_handle]
>
> is much easier for user to read and use.
>
The string-based interface is more user-friendly
I'll switch to using string values "full_stack" and "stack_handle"
with sysfs_match_string() in v4, implementing the show function to
display them with [] brackets around the current selection.
>>
>> The v3 documentation will clarify the meaning:
>> - 0 (default): Print full stack traces
>> - 1: Print only stack handles
>>
>> Do you think this is sufficient, or would you still prefer using
>> string values instead?
>>
>>
>>> Best Regards,
>>> Yan, Zi
>>>
>>>
>> Best regards,
>> Zhen
>
>
> Best Regards,
> Yan, Zi
>
>
Best regards,
Zhen
next prev parent reply other threads:[~2026-04-29 11:42 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-19 15:55 [PATCH v2 0/3] mm/page_owner: add filter infrastructure for print_mode and NUMA filtering Zhen Ni
2026-04-19 15:55 ` [PATCH v2 1/3] mm/page_owner: add filter infrastructure Zhen Ni
2026-04-27 15:35 ` Zi Yan
2026-04-28 3:33 ` zhen.ni
2026-04-28 13:13 ` Zi Yan
2026-04-29 1:39 ` SeongJae Park
2026-04-29 11:22 ` zhen.ni
2026-04-29 11:28 ` Zi Yan
2026-04-19 15:55 ` [PATCH v2 2/3] mm/page_owner: add print_mode filter Zhen Ni
2026-04-27 15:43 ` Zi Yan
2026-04-28 3:36 ` zhen.ni
2026-04-28 13:20 ` Zi Yan
2026-04-29 11:42 ` zhen.ni [this message]
2026-04-19 15:55 ` [PATCH v2 3/3] mm/page_owner: add NUMA node filter with nodelist support Zhen Ni
2026-04-24 11:26 ` Andrew Morton
2026-04-24 20:15 ` Andrew Morton
2026-04-24 11:27 ` [PATCH v2 0/3] mm/page_owner: add filter infrastructure for print_mode and NUMA filtering Andrew Morton
2026-04-24 14:09 ` Andrew Morton
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=38340de6-c729-4b04-a42b-36cbd6585c9c@easystack.cn \
--to=zhen.ni@easystack.cn \
--cc=akpm@linux-foundation.org \
--cc=hannes@cmpxchg.org \
--cc=jackmanb@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
--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