From: Tejun Heo <tj@kernel.org>
To: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>
Cc: Lai Jiangshan <jiangshanlai@gmail.com>,
linux-kernel@vger.kernel.org,
syzbot+8922e6b8343f70be92e8@syzkaller.appspotmail.com,
Breno Leitao <leitao@debian.org>
Subject: Re: [PATCH] workqueue: annotate the lockless nr_running read in need_more_worker()
Date: Mon, 12 Oct 2026 08:25:47 -1000 [thread overview]
Message-ID: <4a5abe9a312053d13afde2704d0b7061@kernel.org> (raw)
In-Reply-To: <20261012143605.281358-1-ngocthang2710.1999@gmail.com>
Hello,
On Mon, Oct 12, 2026 at 09:36:05PM +0700, Nguyen Ngoc Thang wrote:
> Subject: [PATCH] workqueue: annotate the lockless nr_running read in need_more_worker()
The read is under pool->lock. The lockless side is the increment in
wq_worker_running(). Can you fix the subject?
> The race is benign: nr_running only goes 0 -> 1 here, and a stale 0
> merely causes a spurious wakeup of an idle worker. Annotate the read
> with data_race().
The increment can also go 1 -> 2: a worker sleeping in a work item wakes
up after kick_pool() woke another worker which is now running. The reason
it's benign is that the only lockless write is an increment. Decrements
and the reset are under pool->lock, so a reader holding the lock sees
either the old or the new count. 0 costs at most a spurious wakeup.
Nonzero is correct because the incrementing worker is running and
re-checks the worklist under pool->lock before it stops counting. Can you
update the description accordingly?
> + /*
> + * wq_worker_running() bumps nr_running without pool->lock. A stale
> + * read at worst causes a spurious wakeup, so the race is benign.
> + */
This duplicates the comment on nr_running in struct worker_pool. A pointer
to that would do.
Thanks.
--
tejun
prev parent reply other threads:[~2026-10-12 18:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-12 14:36 Nguyen Ngoc Thang
2026-10-12 18:25 ` Tejun Heo [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4a5abe9a312053d13afde2704d0b7061@kernel.org \
--to=tj@kernel.org \
--cc=jiangshanlai@gmail.com \
--cc=leitao@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ngocthang2710.1999@gmail.com \
--cc=syzbot+8922e6b8343f70be92e8@syzkaller.appspotmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®