Skip to content

Commit c5404d4

Browse files
committed
workqueue: Make wq_adjust_max_active() round-robin pwqs while activating
wq_adjust_max_active() needs to activate work items after max_active is increased. Previously, it did that by visiting each pwq once activating all that could be activated. While this makes sense with per-pwq nr_active, nr_active will be shared across multiple pwqs for unbound wqs. Then, we'd want to round-robin through pwqs to be fairer. In preparation, this patch makes wq_adjust_max_active() round-robin pwqs while activating. While the activation ordering changes, this shouldn't cause user-noticeable behavior changes. Signed-off-by: Tejun Heo <[email protected]> Reviewed-by: Lai Jiangshan <[email protected]>
1 parent 1c270b7 commit c5404d4

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

kernel/workqueue.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4710,7 +4710,7 @@ static int init_rescuer(struct workqueue_struct *wq)
47104710
*/
47114711
static void wq_adjust_max_active(struct workqueue_struct *wq)
47124712
{
4713-
struct pool_workqueue *pwq;
4713+
bool activated;
47144714

47154715
lockdep_assert_held(&wq->mutex);
47164716

@@ -4730,19 +4730,26 @@ static void wq_adjust_max_active(struct workqueue_struct *wq)
47304730
*/
47314731
WRITE_ONCE(wq->max_active, wq->saved_max_active);
47324732

4733-
for_each_pwq(pwq, wq) {
4734-
unsigned long flags;
4735-
4736-
/* this function can be called during early boot w/ irq disabled */
4737-
raw_spin_lock_irqsave(&pwq->pool->lock, flags);
4738-
4739-
while (pwq_activate_first_inactive(pwq))
4740-
;
4733+
/*
4734+
* Round-robin through pwq's activating the first inactive work item
4735+
* until max_active is filled.
4736+
*/
4737+
do {
4738+
struct pool_workqueue *pwq;
47414739

4742-
kick_pool(pwq->pool);
4740+
activated = false;
4741+
for_each_pwq(pwq, wq) {
4742+
unsigned long flags;
47434743

4744-
raw_spin_unlock_irqrestore(&pwq->pool->lock, flags);
4745-
}
4744+
/* can be called during early boot w/ irq disabled */
4745+
raw_spin_lock_irqsave(&pwq->pool->lock, flags);
4746+
if (pwq_activate_first_inactive(pwq)) {
4747+
activated = true;
4748+
kick_pool(pwq->pool);
4749+
}
4750+
raw_spin_unlock_irqrestore(&pwq->pool->lock, flags);
4751+
}
4752+
} while (activated);
47464753
}
47474754

47484755
__printf(1, 4)

0 commit comments

Comments
 (0)