Re: [PATCH v10 3/4] tools/mm: add page_owner_filter userspace tool

From: Lance Yang

Date: Thu Jun 18 2026 - 03:21:46 EST



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