Re: [PATCH 5/7] sched/wait: always queue new waiters at the tail
From: Peter Zijlstra
Date: Thu Nov 26 2026 - 10:48:24 EST
On Tue, Nov 24, 2026 at 12:46:30PM -0500, Linus Torvalds wrote:
> From: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
> Date: Mon, 23 Nov 2026 16:48:44 -0800
> Subject: [PATCH 5/7] sched/wait: always queue new waiters at the tail
>
> Non-exclusive waiters have been added at the head and exclusive ones at
> the tail, so that an exclusive wakeup stopping early still woke every
> non-exclusive waiter.
>
> That only matters for waiters that mix both kinds on one queue like
> read() and poll() on a pipe - and even then it doesn't actually buy
> anything but complexity and fragility of the code.
>
> An exclusive reader consumes the event, the poller had nothing to see,
> so there's no real point in keeping the two ordered.
>
> The pointless ordering results in a special rule for everybody adding
> themselves to the wait queue, and that rule has not been consistently
> followed anyway (see for example do_wait_intr() and do_wait_intr_irq())
>
> So just queue everyone in FIFO order. LIFO might be better for
> throughput, but every time we've ever tried that optimization in real
> life, it has caused fairness issues, so let's just do the obvious thing
> and add new waiters at the end of the list.
>
> Priority entries (used by the hypervisor code - questionable special
> case) are still placed at the head by add_wait_queue_priority*().
>
> And because epoll is a pile of stinking manure that I am afraid to touch
> this leaves __add_wait_queue_exclusive() alone and it adds its entry at
> the head for epoll's ep->wq so its own wakeup order doesn't change.
>
> Now that it isn't a "real" exclusive wake event, its ordering thankfully
> doesn't actually matter for anybody else. It should be fixed, but it's
> now basically just an internal epoll thing (and that will be made more
> obvious in following patches).
I like this :-)