All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/4] mm/page_owner: add filter infrastructure for print_mode and NUMA filtering
@ 2026-04-28  7:11 Zhen Ni
  2026-04-28  7:11 ` [PATCH v3 1/4] mm/page_owner: add filter infrastructure Zhen Ni
                   ` (4 more replies)
  0 siblings, 5 replies; 18+ messages in thread
From: Zhen Ni @ 2026-04-28  7:11 UTC (permalink / raw)
  To: akpm, vbabka
  Cc: surenb, mhocko, jackmanb, hannes, ziy, linux-mm, linux-kernel,
	Zhen Ni

This patch series introduces filtering capabilities to the page_owner
feature to address storage and performance challenges in production
environments.

Changes from v2:
- Remove READ_ONCE/WRITE_ONCE for nodemask_t (fixes compilation errors)
  * nodemask_t is a large structure (128 bytes) that triggers compile-time asserts
  * Direct assignment is safe for this use case
- Add comment explaining input length calculation formula
  * 6 bytes = ",NNNNN" (comma + 5-digit node number)
- Simplify "-1" check using kstrtoint() instead of dual strcmp()
- Move nodemask_t mask read outside PFN iteration loop for performance
  * Avoids 128-byte structure copy on each iteration
- Add documentation for filter features (patch 4/4)

Changes from v1:
- Renamed 'compact' to 'print_mode' with enum type for better clarity
  * PAGE_OWNER_PRINT_FULL_STACK (0): print full stack traces
  * PAGE_OWNER_PRINT_STACK_HANDLE (1): print only stack handles
- Changed NUMA filter from single node to nodelist with bitmask support
  * Uses nodelist_parse() to support "0", "0,2", "0-3", "0,2-4,7" formats
  * Uses nodemask_t internally for efficient multi-node filtering
  * Output uses %*pbl format (e.g., "0-2", "0,2-4,7")
- Improved memory handling in nid_filter_write using dynamic allocation
  * Limit: (100 + 6 * MAX_NUMNODES) to handle worst-case input

These changes address feedback from v2 review:
- AI review tool (sashiko.dev) identified READ_ONCE/WRITE_ONCE issue with nodemask_t
- Andrew Morton requested documentation for filter features
- Input length calculation justification
- Code simplification using kstrtoint()
- Performance optimization for mask read

Problem Statement
=================

In production environments with large memory configurations (e.g., 250GB+),
collecting page_owner information often results in files ranging from
several gigabytes to over 10GB. This creates significant challenges:

1. Storage pressure on production systems
2. Difficulty transferring large files from production environments
3. Post-processing overhead with tools/mm/page_owner_sort.c

The primary contributor to file size is redundant stack trace
information. While the kernel already deduplicates stacks via
stackdepot, page_owner retrieves and stores full stack traces for
each page, only to deduplicate them again during post-processing.

Additionally, in NUMA-aware environments (e.g., DPDK-based cloud
deployments where QEMU processes are bound to specific NUMA nodes),
OOM events are often node-specific rather than system-wide.
Currently, page_owner cannot filter by NUMA node, forcing users to
collect and analyze data for all nodes.

Solution
========

This patch series introduces a flexible filter infrastructure with
two initial filters:

1. **Print Mode Filter**: Outputs only stack handles instead of
   full stack traces. The handle-to-stack mapping can be retrieved
   from the existing show_stacks_handles interface. This dramatically
   reduces output size while preserving all allocation metadata.

2. **NUMA Node Filter**: Allows filtering pages by specific NUMA node(s)
   using flexible nodelist format, enabling targeted analysis of memory
   issues in NUMA-aware deployments.

Implementation
==============

The series is structured as follows:

- Patch 1: Add filter infrastructure (data structures and
  debugfs directory)
- Patch 2: Implement print_mode filter
- Patch 3: Implement NUMA node filter with nodelist support
- Patch 4: Document filter features

Usage Example
=============

Enable print_mode and filter for NUMA nodes 0,2-3:

    # cd /sys/kernel/debug/page_owner_filter/
    # echo 1 > print_mode
    # echo "0,2-3" > nid
    # cat /sys/kernel/debug/page_owner > page_owner.txt

Sample print_mode output (showing handles only):

    Page allocated via order 0, mask 0x0(), pid 0, tgid 0 (swapper),
    ts 0 ns PFN 0x40000 type Unmovable Block 512 type Unmovable
    Flags 0x3fffe0000000000(node=0|zone=0|lastcpupid=0x1ffff)
    handle: 1048577

    Page allocated via order 0, mask 0x252000(__GFP_NOWARN|
    __GFP_NORETRY|__GFP_COMP|__GFP_THISNODE), pid 0, tgid 0 (swapper),
    ts 0 ns PFN 0x40002 type Unmovable Block 512 type Unmovable
    Flags 0x23fffe0000000200(workingset|node=0|zone=0|lastcpupid=0x1ffff)
    handle: 1048577

Testing
=======

Tested on a system with multiple NUMA nodes. Verified that:
- Filters work independently and in combination
- Print_mode output correlates correctly with show_stacks_handles
- Default behavior (filters disabled) remains unchanged
- NUMA filter works with single node, multiple nodes, and ranges
- Code compiles without warnings or errors (allmodconfig tested)

Example test session:
    # cat print_mode
    0
    # echo "0,1-2" > nid
    # cat nid
    0-2
    # echo "0,2-3" > nid
    # cat nid
    0,2-3
    # echo 1 > print_mode
    # head -n 100 /sys/kernel/debug/page_owner
    [Shows compact mode output with handles only]

Future Enhancements
===================

The filter infrastructure is designed to be extensible. Potential
future filters could include:
- PID/TGID filtering
- Time range filtering (allocation timestamp windows)
- GFP flag filtering
- Migration type filtering

Signed-off-by: Zhen Ni <zhen.ni@easystack.cn>
---

Zhen Ni (4):
  mm/page_owner: add filter infrastructure
  mm/page_owner: add print_mode filter
  mm/page_owner: add NUMA node filter with nodelist support
  mm/page_owner: document page_owner filter features

 Documentation/mm/page_owner.rst |  55 +++++++++++++-
 mm/page_owner.c                 | 130 +++++++++++++++++++++++++++++++-
 2 files changed, 182 insertions(+), 3 deletions(-)

--
2.20.1


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

end of thread, other threads:[~2026-04-30  6:01 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-28  7:11 [PATCH v3 0/4] mm/page_owner: add filter infrastructure for print_mode and NUMA filtering Zhen Ni
2026-04-28  7:11 ` [PATCH v3 1/4] mm/page_owner: add filter infrastructure Zhen Ni
2026-04-28  7:11 ` [PATCH v3 2/4] mm/page_owner: add print_mode filter Zhen Ni
2026-04-29  0:57   ` SeongJae Park
2026-04-29  8:19     ` zhen.ni
2026-04-28  7:11 ` [PATCH v3 3/4] mm/page_owner: add NUMA node filter with nodelist support Zhen Ni
2026-04-28 14:16   ` Andrew Morton
2026-04-29  7:30     ` zhen.ni
2026-04-29  1:28   ` SeongJae Park
2026-04-29  9:03     ` zhen.ni
2026-04-29 14:56       ` SeongJae Park
2026-04-30  3:56         ` zhen.ni
2026-04-30  5:16           ` SeongJae Park
2026-04-30  6:00             ` zhen.ni
2026-04-28  7:11 ` [PATCH v3 4/4] mm/page_owner: document page_owner filter features Zhen Ni
2026-04-29  1:35   ` SeongJae Park
2026-04-29  9:14     ` zhen.ni
2026-04-28 14:15 ` [PATCH v3 0/4] mm/page_owner: add filter infrastructure for print_mode and NUMA filtering Andrew Morton

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.