Re: [PATCH v12 3/4] tools/mm: add page_owner_filter userspace tool
From: Zi Yan
Date: Tue Jul 07 2026 - 12:18:46 EST
On 7 Jul 2026, at 7:54, Zhen Ni wrote:
> Add a userspace filtering tool for page_owner that supports per-fd
> filtering with print_mode and NUMA node filters.
>
> Features:
> - Three print modes: stack (default), handle, stack_handle
> - NUMA node filtering with flexible formats (single: 0, multiple: 0,1,2,
> range: 0-3, mixed: 0,2-3)
> - Per-file-descriptor filter state for independent filtering
>
> Usage examples:
> # Filter by print mode
> ./page_owner_filter -m handle
> ./page_owner_filter -m stack_handle
>
> # Filter by NUMA node
> ./page_owner_filter -n 0
> ./page_owner_filter -n 0-3
>
> # Combined filters
> ./page_owner_filter -m stack -n 0,1,2
> ./page_owner_filter -m handle -n 0,2-3
>
> The tool validates inputs before sending commands to the kernel and
> provides clear error messages when the kernel does not support
> per-fd filtering.
>
> Signed-off-by: Zhen Ni <zhen.ni@xxxxxxxxxxxx>
> Tested-by: Zi Yan <ziy@xxxxxxxxxx>
> ---
> Changes in v12:
> - No changes
>
> Changes in v11:
> - Add signal(SIGPIPE, SIG_IGN) to ignore SIGPIPE and handle EPIPE gracefully
> - Treat EPIPE from fwrite() and fflush() as success (broken pipe case)
>
> Changes in v10:
> - Improve error handling: check fwrite() and fflush() return values
> - Handle EPIPE correctly: treat broken pipe as success
>
> Changes in v9:
> - Fix isdigit() usage: cast to unsigned char to avoid undefined behavior with non-ASCII input
> - Optimize I/O performance: replace fprintf() + fflush() in loop with fwrite() + single fflush() after loop
>
> Changes in v8:
> - Add validation to reject multiple dashes in nid list (e.g., "1-2-3")
> - Fix snprintf return value handling to prevent command overflow
>
> Changes in v7:
> - New patch for userspace tool
>
> v11: https://lore.kernel.org/linux-mm/20260625043101.338794-4-zhen.ni@xxxxxxxxxxxx/
> v10: https://lore.kernel.org/linux-mm/20260618035750.3724613-4-zhen.ni@xxxxxxxxxxxx/
> v9: https://lore.kernel.org/linux-mm/20260525081652.2210206-4-zhen.ni@xxxxxxxxxxxx/
> v8: https://lore.kernel.org/linux-mm/20260520075641.1931080-4-zhen.ni@xxxxxxxxxxxx/
> v7: https://lore.kernel.org/linux-mm/20260515091942.1535677-4-zhen.ni@xxxxxxxxxxxx/
> ---
> tools/mm/Makefile | 4 +-
> tools/mm/page_owner_filter.c | 310 +++++++++++++++++++++++++++++++++++
> 2 files changed, 312 insertions(+), 2 deletions(-)
> create mode 100644 tools/mm/page_owner_filter.c
>
Acked-by: Zi Yan <ziy@xxxxxxxxxx>
Best Regards,
Yan, Zi