Re: [PATCH] pipe: keep per-write wakeups for EPOLLEXCLUSIVE consumers

From: Linus Torvalds

Date: Tue Nov 17 2026 - 14:49:09 EST


On Tue, 17 Nov 2026 at 11:12, Linus Torvalds
<torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> Ok, I looked at this, and it gets ugly

Side note: as part of looking at it, I did look at what it would
involve in our wait.h infrastructure.

That header isn't _horrible_, but some of it was uglier than needed,
and adding WQ_FLAG_PRIORITY would have been a huge pain because the
code unnecessarily special-cases WQ_FLAG_EXCLUSIVE.

So while I threw the rest of my trial patch away, this patch remained
as a cleanup. It *looks* sane to me, and I think the end result looks
better and would be more flexible.

For example, it would have allowed just adding a new user of
___wait_event() that used WQ_FLAG_PRIORITY to put itself at the head
of the queue.

NOTE! Entirely untested. Comments?

Linus
From c8f60d670fa1215ce5cd38f9c7e7cb2758bc5a58 Mon Sep 17 00:00:00 2001
From: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 17 Nov 2026 11:42:03 -0800
Subject: [PATCH] wait-event: clean up the internal helper arguments

The ___wait_event() helper for historical reasons took a "0/1" argument
for whether the wait-queue entry should be marked WQ_FLAG_EXCLUSIVE or
not. That didn't really help readability, but it also limited the
wq_flags for that helper to only that one flag.

Just make that macro argument be the actual 'wq_flags' value, which
simplifies the helper, and makes it more generic. It also happens to
make the users of this macro more obvious when an unexplained '1'
argument becomes a more self-explanatory 'WQ_FLAG_EXCLUSIVE'.

Also change the existing users that use that raw ___wait_event()
interface with just a plain schedule() to use the pre-existing helpers
macros: __wait_event_state() and __wait_event_state_exclusive().

Signed-off-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
---
include/linux/wait.h | 36 +++++++++++++++---------------------
1 file changed, 15 insertions(+), 21 deletions(-)

diff --git a/include/linux/wait.h b/include/linux/wait.h
index c2af98b0074d..b3e94c71cd3e 100644
--- a/include/linux/wait.h
+++ b/include/linux/wait.h
@@ -299,13 +299,13 @@ extern void init_wait_entry(struct wait_queue_entry *wq_entry, int flags);
* otherwise.
*/

-#define ___wait_event(wq_head, condition, state, exclusive, ret, cmd) \
+#define ___wait_event(wq_head, condition, state, wq_flag, ret, cmd) \
({ \
__label__ __out; \
struct wait_queue_entry __wq_entry; \
long __ret = ret; /* explicit shadow */ \
\
- init_wait_entry(&__wq_entry, exclusive ? WQ_FLAG_EXCLUSIVE : 0); \
+ init_wait_entry(&__wq_entry, wq_flag); \
for (;;) { \
long __int = prepare_to_wait_event(&wq_head, &__wq_entry, state);\
\
@@ -327,8 +327,7 @@ __out: __ret; \
})

#define __wait_event(wq_head, condition) \
- (void)___wait_event(wq_head, condition, TASK_UNINTERRUPTIBLE, 0, 0, \
- schedule())
+ (void)__wait_event_state(wq_head, condition, TASK_UNINTERRUPTIBLE)

/**
* wait_event - sleep until a condition gets true
@@ -366,8 +365,7 @@ do { \
} while (0)

#define __wait_event_freezable(wq_head, condition) \
- ___wait_event(wq_head, condition, (TASK_INTERRUPTIBLE|TASK_FREEZABLE), \
- 0, 0, schedule())
+ __wait_event_state(wq_head, condition, (TASK_INTERRUPTIBLE|TASK_FREEZABLE))

/**
* wait_event_freezable - sleep (or freeze) until a condition gets true
@@ -442,8 +440,8 @@ do { \
})

#define __wait_event_exclusive_cmd(wq_head, condition, cmd1, cmd2) \
- (void)___wait_event(wq_head, condition, TASK_UNINTERRUPTIBLE, 1, 0, \
- cmd1; schedule(); cmd2)
+ (void)___wait_event(wq_head, condition, TASK_UNINTERRUPTIBLE, \
+ WQ_FLAG_EXCLUSIVE, 0, cmd1; schedule(); cmd2)
/*
* Just like wait_event_cmd(), except it sets exclusive flag
*/
@@ -480,8 +478,7 @@ do { \
} while (0)

#define __wait_event_interruptible(wq_head, condition) \
- ___wait_event(wq_head, condition, TASK_INTERRUPTIBLE, 0, 0, \
- schedule())
+ __wait_event_state(wq_head, condition, TASK_INTERRUPTIBLE)

/**
* wait_event_interruptible - sleep until a condition gets true
@@ -620,8 +617,7 @@ do { \
})

#define __wait_event_interruptible_exclusive(wq, condition) \
- ___wait_event(wq, condition, TASK_INTERRUPTIBLE, 1, 0, \
- schedule())
+ __wait_event_state_exclusive(wq, condition, TASK_INTERRUPTIBLE)

#define wait_event_interruptible_exclusive(wq, condition) \
({ \
@@ -633,8 +629,7 @@ do { \
})

#define __wait_event_killable_exclusive(wq, condition) \
- ___wait_event(wq, condition, TASK_KILLABLE, 1, 0, \
- schedule())
+ __wait_event_state_exclusive(wq, condition, TASK_KILLABLE)

#define wait_event_killable_exclusive(wq, condition) \
({ \
@@ -647,8 +642,7 @@ do { \


#define __wait_event_freezable_exclusive(wq, condition) \
- ___wait_event(wq, condition, (TASK_INTERRUPTIBLE|TASK_FREEZABLE), 1, 0,\
- schedule())
+ __wait_event_state_exclusive(wq, condition, (TASK_INTERRUPTIBLE|TASK_FREEZABLE))

#define wait_event_freezable_exclusive(wq, condition) \
({ \
@@ -676,7 +670,7 @@ do { \
do { \
might_sleep(); \
if (!(condition)) \
- ___wait_event(wq_head, condition, TASK_IDLE, 0, 0, schedule()); \
+ __wait_event_state(wq_head, condition, TASK_IDLE); \
} while (0)

/**
@@ -700,7 +694,7 @@ do { \
do { \
might_sleep(); \
if (!(condition)) \
- ___wait_event(wq_head, condition, TASK_IDLE, 1, 0, schedule()); \
+ __wait_event_state_exclusive(wq_head, condition, TASK_IDLE); \
} while (0)

#define __wait_event_idle_timeout(wq_head, condition, timeout) \
@@ -738,7 +732,7 @@ do { \

#define __wait_event_idle_exclusive_timeout(wq_head, condition, timeout) \
___wait_event(wq_head, ___wait_cond_timeout(condition), \
- TASK_IDLE, 1, timeout, \
+ TASK_IDLE, WQ_FLAG_EXCLUSIVE, timeout, \
__ret = schedule_timeout(__ret))

/**
@@ -911,7 +905,7 @@ extern int do_wait_intr_irq(wait_queue_head_t *, wait_queue_entry_t *);


#define __wait_event_killable(wq, condition) \
- ___wait_event(wq, condition, TASK_KILLABLE, 0, 0, schedule())
+ __wait_event_state(wq, condition, TASK_KILLABLE)

/**
* wait_event_killable - sleep until a condition gets true
@@ -981,7 +975,7 @@ extern int do_wait_intr_irq(wait_queue_head_t *, wait_queue_entry_t *);
})

#define __wait_event_state_exclusive(wq, condition, state) \
- ___wait_event(wq, condition, state, 1, 0, schedule())
+ ___wait_event(wq, condition, state, WQ_FLAG_EXCLUSIVE, 0, schedule())

#define wait_event_state_exclusive(wq, condition, state) \
({ \
--
2.56.0.313.g975a75ca90