mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "zhen.ni" <zhen.ni@easystack.cn>
To: Lance Yang <lance.yang@linux.dev>
Cc: akpm@linux-foundation.org, vbabka@kernel.org, surenb@google.com,
	mhocko@suse.com, jackmanb@google.com, hannes@cmpxchg.org,
	ziy@nvidia.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v10 3/4] tools/mm: add page_owner_filter userspace tool
Date: Tue, 23 Jun 2026 14:24:15 +0800	[thread overview]
Message-ID: <b5b68a98-a947-4135-9ac7-22a9db11d99f@easystack.cn> (raw)
In-Reply-To: <20260618072103.92397-1-lance.yang@linux.dev>



在 2026/6/18 15:21, Lance Yang 写道:
> 
> On Thu, Jun 18, 2026 at 11:57:49AM +0800, Zhen Ni wrote:
> [...]
>> +	/* Read and display filtered output */
>> +	ret = 0;
>> +	while ((ret = read(fd, buf, sizeof(buf))) > 0) {
>> +		size_t written = fwrite(buf, 1, ret, output);
>> +
>> +		if (written != (size_t)ret) {
>> +			if (errno == EPIPE) {
> 
> Hmm ... does this work without handling SIGPIPE first?
> 
> With something like:
> 
> $ ./page_owner_filter -m handle | head
> 
> The writer can be killed by SIGPIPE before fwrite() returns EPIPE no?
> so this branch would usually not be reached ...
> 
>> +				/* Pipe closed, treat as success */
>> +				ret = 0;
>> +				goto out;
>> +			}
>> +			perror("write output");
>> +			ret = -1;
>> +			goto out;
>> +		}
>> +	}
>> +
>> +	if (ret < 0) {
>> +		perror("read page_owner");
>> +		goto out;
>> +	}
>> +
>> +	if (fflush(output)) {
> 
> fflush() can also be where the broken pipe is reported, but still treats
> EPIPE as an error ...
> 
> Shouldn't we ignore/handle SIGPIPE and treat EPIPE from both fwrite()
> and fflush() as succes?
> 
> Cheers, Lance
> 
>> +		perror("flush output");
>> +		ret = -1;
>> +	}
>> +
>> +out:
>> +	close(fd);
>> +	if (output != stdout)
>> +		fclose(output);
>> +	return ret < 0 ? 1 : 0;
>> +}
>> -- 
>> 2.20.1
>>
>>
> 
> 

Thanks for the review.

The SIGPIPE handling was indeed incomplete. Without ignoring SIGPIPE first,
the process gets killed before fwrite() or fflush() can return EPIPE, so 
that
error branch would never be reached.

I've fixed this in v11 by:
1. Adding signal(SIGPIPE, SIG_IGN) at the start of main()
2. Handling EPIPE from both fwrite() and fflush() as success

The fix ensures that when the output pipe is closed (e.g., `| head`), 
the program
exits cleanly instead of being terminated by SIGPIPE.

Thanks,
Zhen


  reply	other threads:[~2026-06-23  6:24 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-18  3:57 [PATCH v10 0/4] mm/page_owner: add per-fd filter infrastructure for print_mode and NUMA filtering Zhen Ni
2026-06-18  3:57 ` [PATCH v10 1/4] mm/page_owner: add print_mode filter Zhen Ni
2026-06-18  3:57 ` [PATCH v10 2/4] mm/page_owner: add NUMA node filter Zhen Ni
2026-06-18  3:57 ` [PATCH v10 3/4] tools/mm: add page_owner_filter userspace tool Zhen Ni
2026-06-18  7:21   ` Lance Yang
2026-06-23  6:24     ` zhen.ni [this message]
2026-06-18  3:57 ` [PATCH v10 4/4] mm/page_owner: document page_owner filter Zhen Ni
2026-06-25  3:15 ` [PATCH v10 0/4] mm/page_owner: add per-fd filter infrastructure for print_mode and NUMA filtering Andrew Morton
2026-06-25  7:48   ` Ye Liu

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=b5b68a98-a947-4135-9ac7-22a9db11d99f@easystack.cn \
    --to=zhen.ni@easystack.cn \
    --cc=akpm@linux-foundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=jackmanb@google.com \
    --cc=lance.yang@linux.dev \
    --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

Powered by JetHome