[PATCH 5/7] workqueue: Addjust pwq's max_active when CPU online/offine

From: Lai Jiangshan
Date: Wed Dec 27 2023 - 09:50:57 EST


From: Lai Jiangshan <jiangshan.ljs@xxxxxxxxxxxx>

pwq->max_active is going to be set based on the CPU online distribution
which might be changed when CPU online/offine.

Call into wq_adjust_pwqs_max_active() to update them when needed.

Signed-off-by: Lai Jiangshan <jiangshan.ljs@xxxxxxxxxxxx>
---
kernel/workqueue.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index e0101b2b5fa3..d1c671597289 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -5590,10 +5590,15 @@ int workqueue_online_cpu(unsigned int cpu)
mutex_unlock(&wq_pool_attach_mutex);
}

- /* update pod affinity of unbound workqueues */
+ /*
+ * Update pod affinity of unbound workqueues, and update max_active
+ * for PWQs of all pods due to CPU online distribution changed.
+ */
list_for_each_entry(wq, &workqueues, list) {
- if (wq->unbound_attrs)
+ if (wq->unbound_attrs) {
wq_update_pod(wq, cpu, true);
+ wq_adjust_pwqs_max_active(wq);
+ }
}

mutex_unlock(&wq_pool_mutex);
@@ -5610,11 +5615,16 @@ int workqueue_offline_cpu(unsigned int cpu)

unbind_workers(cpu);

- /* update pod affinity of unbound workqueues */
+ /*
+ * Update pod affinity of unbound workqueues, and update max_active
+ * for PWQs of all pods due to CPU online distribution changed.
+ */
mutex_lock(&wq_pool_mutex);
list_for_each_entry(wq, &workqueues, list) {
- if (wq->unbound_attrs)
+ if (wq->unbound_attrs) {
wq_update_pod(wq, cpu, false);
+ wq_adjust_pwqs_max_active(wq);
+ }
}
mutex_unlock(&wq_pool_mutex);

--
2.19.1.6.gb485710b