]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
workqueue: Process rescuer work items one-by-one using a cursor
authorLai Jiangshan <jiangshan.ljs@antgroup.com>
Mon, 8 Dec 2025 13:25:18 +0000 (21:25 +0800)
committerTejun Heo <tj@kernel.org>
Mon, 8 Dec 2025 19:17:49 +0000 (09:17 -1000)
commite5a30c303b07a4d6083e0f7f051b53add6d93c5d
tree5763b34b371e5ad86041208682b07ea9bd452d73
parentfc5ff53d2aa088713870cd684b160ee95c018520
workqueue: Process rescuer work items one-by-one using a cursor

Previously, the rescuer scanned for all matching work items at once and
processed them within a single rescuer thread, which could cause one
blocking work item to stall all others.

Make the rescuer process work items one-by-one instead of slurping all
matches in a single pass.

Break the rescuer loop after finding and processing the first matching
work item, then restart the search to pick up the next. This gives
normal worker threads a chance to process other items which gives them
the opportunity to be processed instead of waiting on the rescuer's
queue and prevents a blocking work item from stalling the rest once
memory pressure is relieved.

Introduce a dummy cursor work item to avoid potentially O(N^2)
rescans of the work list.  The marker records the resume position for
the next scan, eliminating redundant traversals.

Also introduce RESCUER_BATCH to control the maximum number of work items
the rescuer processes in each turn, and move on to other PWQs when the
limit is reached.

Cc: ying chen <yc1082463@gmail.com>
Reported-by: ying chen <yc1082463@gmail.com>
Fixes: e22bee782b3b ("workqueue: implement concurrency managed dynamic worker pool")
Signed-off-by: Lai Jiangshan <jiangshan.ljs@antgroup.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
kernel/workqueue.c