Linux Documentation
 help / color / mirror / Atom feed
From: "zhen.ni" <zhen.ni@easystack.cn>
To: Andrew Morton <akpm@linux-foundation.org>,
	"Lorenzo Stoakes (ARM)" <ljs@kernel.org>
Cc: David Hildenbrand <david@kernel.org>,
	"Liam R . Howlett" <liam@infradead.org>,
	Vlastimil Babka <vbabka@kernel.org>,
	Mike Rapoport <rppt@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>, Jonathan Corbet <corbet@lwn.net>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	Brendan Jackman <brendan.jackman@linux.dev>,
	Johannes Weiner <hannes@cmpxchg.org>, Zi Yan <ziy@nvidia.com>,
	linux-mm@kvack.org, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 0/8] mm/page_owner: Add PID/TGID/COMM and cgroup filtering
Date: Tue, 1 Sep 2026 14:34:34 +0800	[thread overview]
Message-ID: <9fce3210-3548-4df3-ae00-730b666f5d57@easystack.cn> (raw)
In-Reply-To: <20260828113654.d01abd8baed3f73e87506eb3@linux-foundation.org>



在 2026/8/29 02:36, Andrew Morton 写道:
> On Fri, 28 Aug 2026 08:03:38 +0100 "Lorenzo Stoakes (ARM)" <ljs@kernel.org> wrote:
> 
>> On Fri, Aug 28, 2026 at 11:13:31AM +0800, Zhen Ni wrote:
>>> This patch series adds process and memory cgroup filtering support to
>>> page_owner. Following the previous series that introduced print_mode and
>>> NUMA node filters:
>>>    https://lore.kernel.org/linux-mm/20260707115411.1714314-1-zhen.ni@easystack.cn/
>>>
>>> This series adds filtering capabilities to page_owner, allowing users to
>>> filter output by specific processes and memory cgroups. Users can now
>>> filter page_owner output by PID, TGID, COMM (with wildcard support), and
>>> memory cgroup path. This makes page_owner debugging more focused and
>>> efficient for tracking memory allocations in specific contexts.
>>
>> The majority of this cover letter feels like it should have been
>> documentation put somewhere :)
> 
> yes please.
> 
> The only thing longer than the cover letter is the Sashiko report ;)
> 
> 	https://sashiko.dev/#/patchset/20260828031339.1270699-1-zhen.ni@easystack.cn
> 
> 

Hi Andrew, Lorenzo,

Thanks for the review.

I have analyzed all the Sashiko report findings. Some will be fixed in
the next version, and for the rest I propose not to fix them, with
reasons below. If there are no objections I will send v2 accordingly.

Will be fixed in the next version:

- mm/page_owner.c: drop the kstrdup() copy in parse_pid_t_list(); the
   token will be parsed in place. This also fixes a leak on the success
   path and a kfree() of an advanced (interior) pointer on the error
   path. cmp_int() will replace plain subtraction in cmp_pid_t(), and
   pid values exceeding PID_MAX_LIMIT will be rejected.
- mm/page_owner.c: PAGE_OWNER will select GLOB so glob_match() is
   always linked in; parse_comm_list() will drop its kstrdup() copy the
   same way.
- mm/page_owner.c: the cgroup path buffer will be allocated once per
   read() outside the page_ext RCU read-side critical section instead of
   per page inside get_page_memcg_info() (GFP_KERNEL allocations must
   not sleep there). The memcg= parsing branch will be guarded by
   CONFIG_MEMCG so kernels built without memcg reject the command
   instead of silently enabling a filter that never matches.
- tools/mm/page_owner_filter.c: user-visible input errors (empty
   -p/-t/-c/-g arguments) will print error messages instead of exiting
   silently.
- Documentation: the wildcard pattern in the -c example will be quoted
   to prevent shell glob expansion.

Proposed not to fix, by design:

1. Shared-fd concurrent read/write races (READ_ONCE around the pid
    passed to bsearch, torn reads of pid/tgid lists, glob_match() racing
    comm rewrites, concurrent write() leading to state->memcg_path
    double-allocation): multi-threaded sharing of one page_owner fd is
    not a designed use of this interface. The filters are per-fd state
    meant to be configured once and then read, which is what the
    page_owner_filter tool does. Adding locking to the read path would
    put overhead into the per-page scan loop for no designed benefit.
    This matches the semantics of the original filter introduction.

2. No "clear filter" support (empty pid=/tgid= lists partially clearing
    proc filters, empty memcg=/nid= being rejected): write commands are
    incremental -- "keep the unmentioned filters" -- and there is no
    clear operation by design. To start over, close the fd and open a
    fresh one; the page_owner_filter tool already works this way. This
    also matches the semantics of the original filter introduction.

3. kcalloc() vs kmalloc_array() for new_comm_list: no consumer of the
    list reads past strscpy()'s NUL terminator, so uninitialized bytes
    are unreachable.

4. char cgroup_path[512] in validate_cgroup_path(): acknowledged that
    the kernel side accepts paths up to PATH_MAX (4096). The userspace
    check truncates an over-long path with snprintf() and then fails
    access(), so it is rejected, never silently accepted. Bumping the
    buffer to PATH_MAX would only serve pathological paths; realistic
    cgroup paths are well under 100 bytes, so 512 wastes nothing in
    practice.

If this plan looks reasonable I will send v2.

Thanks,
Zhen Ni

  reply	other threads:[~2026-09-01  6:49 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-28  3:13 [PATCH 0/8] mm/page_owner: Add PID/TGID/COMM and cgroup filtering Zhen Ni
2026-08-28  3:13 ` [PATCH 1/8] mm/page_owner: Add PID filtering support Zhen Ni
2026-08-28  3:13 ` [PATCH 2/8] mm/page_owner: Add TGID " Zhen Ni
2026-08-28  3:13 ` [PATCH 3/8] mm/page_owner: Add COMM filtering with wildcard support Zhen Ni
2026-08-28  3:13 ` [PATCH 4/8] mm/page_owner: Refactor memcg handling for cgroup filter support Zhen Ni
2026-08-28  3:13 ` [PATCH 5/8] mm/page_owner: Add memcg " Zhen Ni
2026-08-28  3:13 ` [PATCH 6/8] tools/mm: Add PID/TGID/COMM filtering support to page_owner_filter Zhen Ni
2026-08-28  3:13 ` [PATCH 7/8] tools/mm: Add memory cgroup " Zhen Ni
2026-08-28  3:13 ` [PATCH 8/8] Documentation: page_owner: Document PID/TGID/COMM and cgroup filters Zhen Ni
2026-08-28  7:03 ` [PATCH 0/8] mm/page_owner: Add PID/TGID/COMM and cgroup filtering Lorenzo Stoakes (ARM)
2026-08-28 18:36   ` Andrew Morton
2026-09-01  6:34     ` zhen.ni [this message]
2026-09-01  7:27       ` Lorenzo Stoakes (ARM)
2026-09-01  8:01         ` zhen.ni
2026-09-01  8:10           ` Lorenzo Stoakes (ARM)
2026-09-01  9:29             ` zhen.ni

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=9fce3210-3548-4df3-ae00-730b666f5d57@easystack.cn \
    --to=zhen.ni@easystack.cn \
    --cc=akpm@linux-foundation.org \
    --cc=brendan.jackman@linux.dev \
    --cc=corbet@lwn.net \
    --cc=david@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=liam@infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@suse.com \
    --cc=rdunlap@infradead.org \
    --cc=rppt@kernel.org \
    --cc=skhan@linuxfoundation.org \
    --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