Re: [PATCH 2/7] sched/wait: add WQ_FLAG_POLL_EXCLUSIVE for user space waiters

From: Linus Torvalds

Date: Wed Nov 25 2026 - 11:36:36 EST


On Wed, 25 Nov 2026 at 03:43, Oleg Nesterov <oleg@xxxxxxxxxx> wrote:
>
> On 11/24, Linus Torvalds wrote:
> >
> > + if (flags & WQ_FLAG_POLL_EXCLUSIVE)
> > + poll_woken = nr_exclusive > 0;
> > + else if ((flags & WQ_FLAG_EXCLUSIVE) && !--nr_exclusive)
> > break;
>
> I obviously like this change, but note that wake_up_all*() helpers
> use nr_exclusive == 0, so
>
> poll_woken = nr_exclusive > 0;
>
> doesn't look correct.

No, I think it is correct. I agree that this logic is a bit messy, but
the intent was to keep the patch minimal and the code as close to the
old code as possible.

The logic in the new code is that WQ_FLAG_POLL_EXCLUSIVE should only
wakes up one of the entries that have it, *except* if it's a wake-all.

For wake_all, the poll_woken is never triggered.

And notice that "nr_exclusive goes negative" is exactly the *same* as
"nr_exclusive was originally zero".

So maybe it's a bit subtle, but "nr_exclusive" has never really had
"zero is wake-all". The logic has always actually been "zero or
negative is wake-all".

Only positive values (that then go *down* to zero) stop the walk.

The poll_woken logic is just an extension of that rule.

But maybe I'm missing something. That's always possible.

Linus