Re: [PATCH v3 1/1] pipe: only enable the extra wake_up(rd_wait) for edge-triggered consumers
From: Breno Leitao
Date: Thu Jul 30 2026 - 10:38:46 EST
On Thu, Jul 30, 2026 at 04:12:22PM +0200, Oleg Nesterov wrote:
> pipe_poll() unconditionally sets poll_usage on the first call, forcing
> anon_pipe_write() to wake up readers on every write even if the pipe was
> not empty. But this is only needed for edge-triggered consumers: epoll
> with EPOLLET and io_uring without (unsupported) IORING_POLL_ADD_LEVEL.
> poll() and select() users pay for it for no reason.
>
> Rename ->poll_usage to ->poll_et to make the purpose clearer, update the
> comments to explain that io_uring depends on the "nasty semantics" too,
> and change pipe_poll() to set ->poll_et only if wait->_key & EPOLLET is
> true; this check should catch both users.
This look great at first sight, thanks!
> @@ -760,9 +759,11 @@ pipe_poll(struct file *filp, poll_table *wait)
> struct pipe_inode_info *pipe = filp->private_data;
> union pipe_index idx;
>
> - /* Epoll has some historical nasty semantics, this enables them */
> - if (unlikely(!READ_ONCE(pipe->poll_usage)))
> - WRITE_ONCE(pipe->poll_usage, true);
> + /* Enable edge-triggered (epoll, io_uring) per-write wakeups */
> + if ((filp->f_mode & FMODE_READ) &&
> + wait && (wait->_key & EPOLLET) &&
> + unlikely(!READ_ONCE(pipe->poll_et)))
> + WRITE_ONCE(pipe->poll_et, true);
Can I ask you to factor this out set code, and comment this nasty
semantics in the function and why we need to do it?
Tha would help to make this corner case more visible for readers, other
than hidden on commit messages.
Thanks,
--breno