All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lance Yang <lance.yang@linux.dev>
To: zhen.ni@easystack.cn
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,
	Lance Yang <lance.yang@linux.dev>
Subject: Re: [PATCH v10 3/4] tools/mm: add page_owner_filter userspace tool
Date: Thu, 18 Jun 2026 15:21:03 +0800	[thread overview]
Message-ID: <20260618072103.92397-1-lance.yang@linux.dev> (raw)
In-Reply-To: <20260618035750.3724613-4-zhen.ni@easystack.cn>


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
>
>


  reply	other threads:[~2026-06-18  7:21 UTC|newest]

Thread overview: 6+ 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 [this message]
2026-06-18  3:57 ` [PATCH v10 4/4] mm/page_owner: document page_owner filter 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=20260618072103.92397-1-lance.yang@linux.dev \
    --to=lance.yang@linux.dev \
    --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=zhen.ni@easystack.cn \
    --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 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.