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.
Showing the changes to kernel/workqueue.c (1 of 1 file). Show all
Unified · Split
| @@ -4710,7 +4710,7 @@ static int init_rescuer(struct workqueue_struct *wq) · 4709 unmodified lines | ||
| 4710 | 4710 | */ |
| 4711 | 4711 | static void wq_adjust_max_active(struct workqueue_struct *wq) |
| 4712 | 4712 | { |
| 4713 | − struct pool_workqueue *pwq; | |
| 4713 | + bool activated; | |
| 4714 | 4714 | |
| 4715 | 4715 | lockdep_assert_held(&wq->mutex); |
| 4716 | 4716 | |
| @@ -4730,19 +4730,26 @@ static void wq_adjust_max_active(struct workqueue_struct *wq) · 13 unmodified lines | ||
| 4730 | 4730 | */ |
| 4731 | 4731 | WRITE_ONCE(wq->max_active, wq->saved_max_active); |
| 4732 | 4732 | |
| 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; | |
| 4741 | 4739 | |
| 4742 | − kick_pool(pwq->pool); | |
| 4740 | + activated = false; | |
| 4741 | + for_each_pwq(pwq, wq) { | |
| 4742 | + unsigned long flags; | |
| 4743 | 4743 | |
| 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); | |
| 4746 | 4753 | } |
| 4747 | 4754 | |
| 4748 | 4755 | __printf(1, 4) |