Re: [PATCH v2] workqueue: annotate the lockless nr_running increment racing with need_more_worker()
From: Nguyen Ngoc Thang
Date: Wed Oct 14 2026 - 11:50:37 EST
On Wed, Oct 14, 2026, Breno Leitao wrote:
> Isn't it better to annotate the nr_running field in the structure, rather than
> at reading time?
Agreed. The lockless increment is how nr_running is meant to work, so
the field is the right place for the annotation. v3 marks it
__data_racy and drops the data_race() in need_more_worker():
https://lore.kernel.org/all/20261014154342.20661-1-ngocthang2710.1999@xxxxxxxxx/
The trade-off is that KCSAN now ignores every access to nr_running,
including the locked ones. If someone later adds a decrement without
pool->lock, KCSAN won't catch it. I think that's acceptable, because
the rules are documented right above the field.
Thanks,
Nguyen Ngoc Thang