workqueue: Move pwq_dec_nr_in_flight() to the end of work item handling
authorTejun Heo <tj@kernel.org>
Mon, 29 Jan 2024 18:11:24 +0000 (08:11 -1000)
committerTejun Heo <tj@kernel.org>
Mon, 29 Jan 2024 18:11:24 +0000 (08:11 -1000)
commitdd6c3c5441263723305a9c52c5ccc899a4653000
tree7ef6b5e2b162e74355bda35ed47c6aa846e2fe28
parent9f66cff212bb3c1cd25996aaa0dfd0c9e9d8baab
workqueue: Move pwq_dec_nr_in_flight() to the end of work item handling

The planned shared nr_active handling for unbound workqueues will make
pwq_dec_nr_active() sometimes drop the pool lock temporarily to acquire
other pool locks, which is necessary as retirement of an nr_active count
from one pool may need kick off an inactive work item in another pool.

This patch moves pwq_dec_nr_in_flight() call in try_to_grab_pending() to the
end of work item handling so that work item state changes stay atomic.
process_one_work() which is the other user of pwq_dec_nr_in_flight() already
calls it at the end of work item handling. Comments are added to both call
sites and pwq_dec_nr_in_flight().

This shouldn't cause any behavior changes.

Signed-off-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Lai Jiangshan <jiangshanlai@gmail.com>
kernel/workqueue.c