Re: [PATCH wq/for-7.4 v3 3/3] workqueue: Rescale max_active domains once CPU topology is known

From: Tejun Heo

Date: Fri Oct 16 2026 - 13:35:44 EST


Hello, Breno.

The following is a Claude-generated review.

On Fri, Oct 09, 2026 at 05:18:36AM -0700, Breno Leitao wrote:
> per-node max_active. With one CPU online both domains were equal, so
> saved_max_active is still the max_active the workqueue was created with
> and can be passed back as is.

Nothing guarantees that every workqueue on the list was created with one
CPU online. wq_init_max_active() runs before __alloc_workqueue() takes
wq_pool_mutex, so a workqueue can be created while smp_init() brings CPUs
up.

For a percpu workqueue, saved_max_active is the derived unbound limit:
percpu_max_active times the CPUs online at creation, capped at
WQ_MAX_ACTIVE. Passing it back as the percpu argument multiplies the live
per-CPU limit by that CPU count. A create_workqueue() workqueue created
with two CPUs online goes from 1 to 2. The same happens after a
workqueue_set_max_active() on a percpu workqueue in that window. No such
workqueue was found today, but nothing enforces it.

> + mutex_lock(&wq->mutex);
> + wq_init_max_active(wq, wq->saved_max_active);
> + mutex_unlock(&wq->mutex);

Re-running the creation helper also:

1. Resets saved_min_active to min(max_active, WQ_DFL_MIN_ACTIVE), dropping
any earlier workqueue_set_min_active(). async_init() is safe only
because it runs right after workqueue_init_topology().

2. Writes the live limits directly with plain stores instead of
publishing them through wq_adjust_max_active().

3. Takes N from wq_unbound_cpumask instead of wq_nr_effective_cpus(),
unlike the setters.

4. Takes wq->mutex a second time right before the existing
wq_update_node_max_active() section.

Maybe, under one wq->mutex section, rederive only the saved limits of the
domain the workqueue isn't using from the one it is, with the setters'
conversion and wq_nr_effective_cpus(), and then call
wq_adjust_max_active()? That could be a helper shared with the setters,
and this patch might then fold into 2/3.

Thanks.

--
tejun