Re: [GIT PULL] workqueue: Fixes for v7.4-rc2

From: Linus Torvalds

Date: Mon Nov 16 2026 - 12:29:59 EST


On Mon, 16 Nov 2026 at 09:09, Tejun Heo <tj@xxxxxxxxxx> wrote:
>
> Hmm... so, draining looks like this:
>
> set DRAINING;
> read seq;
> flush wq:
> for each pwq:
> flush them;
> for each pwq:
> lock and check whether empty;
> if not drained or seq bumped, try again;
>
> and the queueing side tests DRAINING and incs the seq while the queueing
> work item is still in flight on its pwq. The chained insertion is under the
> pool lock.

So now I don't have the patch in my tree any more (I could fetch it
again, but I'm lazy), but from memory and my lkimited quoting the
queueing side only incremented the seq number *if* it saw DRAINING.

And that seemed to be the biggest issue.

If the queueing side did *not* see DRAINING, it also wouldn't
increment the sequence number, and it also didn't have any memory
barriers.

So it looked to me like the code basically fell back to the exact old
sequence that the patch claimed to fix: if the queuing side missed
seeing that "set DRAINING" part, all the changes in the commit became
no-ops. Yes, the draining side would re-read the sequence counter and
retry, but the sequence counter didn't actually change because the
queueing side wouldn't be updating it.

But I'll freely admit that I really only looked at the "shape" of the
code, and it all felt wrong to me. This was not some deep-dive
understanding, it was a "this doesn't feel right".

> I don't think it's broken but it is adhoc and difficult to get one's head
> around including my own. It'd be a lot simpler w/ seqcount. I'm traveling
> this week, so might be slower but will redo it.

Thanks.

The main problem with a seqcount might be performance - I'm assuming
you tried to avoid the write for the common cases. I assume *draining*
is the slow and uncommon case, and typically *that* side is where you
want to do the writer side of the seqcount, and then the fast and
common case is the one that wants to do the sequence number read.

So maybe the generic seqcount code isn't what you want, and maybe your
current code is the right thing, and my "it feels wrong" is the wrong
reaction.

Put another way: you should also just feel free to tell me that I was
wrong, and explain *why* it all works the way you did it. Use small
words and call me names.

Linus