From: Saurabh Sengar <ssengar@linux.microsoft.com>
To: tj@kernel.org, jiangshanlai@gmail.com, linux-kernel@vger.kernel.org
Cc: ssengar@microsoft.com, Saurabh Sengar <ssengar@linux.microsoft.com>
Subject: [PATCH] workqueue: Skip redundant unbound updates during CPU bringup
Date: Tue, 24 Nov 2026 10:00:10 -0800 [thread overview]
Message-ID: <20261124180010.1505819-1-ssengar@linux.microsoft.com> (raw)
Before workqueue_init_topology(), all CPUs share the SYSTEM pod,
which contains every possible CPU. The effective cpumask and the
per-pod cpumask of an unbound workqueue are therefore identical,
regardless of which CPUs are online.
During this stage, workqueue_online_cpu() walks every possible CPU for
every unbound workqueue each time a secondary CPU comes online. The
pwq mappings cannot change yet, so this repeats redundant work that
scales quadratically with CPU count.
On a 640-vCPU Hyper-V VM, each of the 639 secondary CPU-online
callbacks walks all 640 possible CPUs for each of the 8 unbound
workqueues, giving 3,271,680 unbound_wq_update_pwq() calls that took
about 975 ms in total.
Skip these updates until workqueue_init_topology(). The pwq mappings
already match the effective cpumask, and wq_update_node_max_active()
does nothing before topology initialization. workqueue_init_topology()
will apply the topology-specific mappings and node limits once ready.
Keep worker rebinding and restoration of unbound worker affinity before
the guard. CPU hotplug after topology initialization is unchanged.
On the same VM running a v7.3 kernel, smp_init() took 1054 ms with this
change, compared to 2008 ms without it, a 47.5% reduction.
Before After Reduction
smp_init() 2008 ms 1054 ms 47.5%
Signed-off-by: Saurabh Sengar <ssengar@linux.microsoft.com>
---
kernel/workqueue.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index baadc7815585..a3767dbf77f0 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -7252,6 +7252,14 @@ int workqueue_online_cpu(unsigned int cpu)
mutex_unlock(&wq_pool_attach_mutex);
}
+ /*
+ * Before topology initialization, the SYSTEM pod covers all possible
+ * CPUs, so CPU onlining does not require updating pwq mappings.
+ * wq_update_node_max_active() also returns early at this stage.
+ */
+ if (!wq_topo_initialized)
+ goto out_unlock;
+
/* update pod affinity of unbound workqueues */
list_for_each_entry(wq, &workqueues, list) {
struct workqueue_attrs *attrs = wq->attrs;
@@ -7269,6 +7277,7 @@ int workqueue_online_cpu(unsigned int cpu)
}
}
+out_unlock:
mutex_unlock(&wq_pool_mutex);
return 0;
}
--
2.43.0
next reply other threads:[~2026-11-24 18:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 18:00 Saurabh Sengar [this message]
2026-11-24 19:57 ` Tejun Heo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261124180010.1505819-1-ssengar@linux.microsoft.com \
--to=ssengar@linux.microsoft.com \
--cc=jiangshanlai@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ssengar@microsoft.com \
--cc=tj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®