Re: [PATCH] sched/wait: Queue non-exclusive waiters at the head in do_wait_intr*()

From: Oleg Nesterov

Date: Wed Nov 11 2026 - 18:21:59 EST


On 11/11, Mani Tofigh via B4 Relay wrote:
>
> --- a/kernel/sched/wait.c
> +++ b/kernel/sched/wait.c
> @@ -319,8 +319,12 @@ EXPORT_SYMBOL(prepare_to_wait_event);
> */
> int do_wait_intr(wait_queue_head_t *wq, wait_queue_entry_t *wait)
> {
> - if (likely(list_empty(&wait->entry)))
> - __add_wait_queue_entry_tail(wq, wait);
> + if (likely(list_empty(&wait->entry))) {
> + if (wait->flags & WQ_FLAG_EXCLUSIVE)
> + __add_wait_queue_entry_tail(wq, wait);
> + else
> + __add_wait_queue(wq, wait);

This look right and matches prepare_to_wait_event(). But it seems there is
another problem if WQ_FLAG_EXCLUSIVE, see the
"Exclusive waiter must not fail if it was selected by wakeup" comment in
prepare_to_wait_event().

Perhaps it makes more sense to simply kill __wait_event_interruptible_locked()
and reimplement wait_event_interruptible_locked() on top of
___wait_event(cmd => do_wait_intr) ? This way do_wait_intr() will only need
to do unlock + schedule + lock.

Oleg.