Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <tj@kernel.org>
Reviewed-by: Lai Jiangshan <jiangshanlai@gmail.com>

+19 -12
+19 -12
kernel/workqueue.c
··· 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 4730 */ 4731 4731 WRITE_ONCE(wq->max_active, wq->saved_max_active); 4732 4732 4733 - for_each_pwq(pwq, wq) { 4734 - unsigned long flags; 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; 4735 4739 4736 - /* this function can be called during early boot w/ irq disabled */ 4737 - raw_spin_lock_irqsave(&pwq->pool->lock, flags); 4740 + activated = false; 4741 + for_each_pwq(pwq, wq) { 4742 + unsigned long flags; 4738 4743 4739 - while (pwq_activate_first_inactive(pwq)) 4740 - ; 4741 - 4742 - kick_pool(pwq->pool); 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)