Re: [PATCH wq/for-7.4 v2 2/3] workqueue: Keep the limits of both max_active domains current

From: Breno Leitao

Date: Tue Sep 29 2026 - 10:42:45 EST


Hello Tejun,

On Mon, Sep 28, 2026 at 10:15:31AM -1000, Tejun Heo wrote:
> On Fri, Sep 25, 2026 at 06:09:51AM -0700, Breno Leitao wrote:
> > Given that we are introducing a WQ_AFFN_CPU which will be able to do CM,
> > we want to keep both values set, so, the transition from scopes would be
> > able to succeed.
>
> This would be the new PERCPU scope rather than WQ_AFFN_CPU.

yes, sorry, that is waht I meant.

> > + int nr_cpus = wq_nr_online_cpus(wq_unbound_cpumask);
>
> Workqueues from workqueue_init_early() and early initcalls are created
> before smp_init(), when only the boot CPU is online, so nr_cpus is 1 for
> them. For example, system_dfl_wq ends up with percpu_max_active 2048 where
> 32 would be right on a 64 CPU machine, and nothing rederives it once all
> CPUs are up. Maybe rederive the other domain in workqueue_init_topology(),
> which already walks all workqueues to update node max_active?

Very good point, and I've just tested it and reproduce the behaviour you
raised.

>
> > + } else if (wq->flags & WQ_BH) { /* BH implies !WQ_UNBOUND */
> > + wq->max_active = effective_max_active;
> > + wq->min_active = effective_max_active;
> > + wq->percpu_max_active = effective_max_active;
>
> Maybe set these in the WQ_BH branch at the top so that BH is handled in one
> place?

Ack!

> > } else {
> > wq->percpu_max_active = effective_max_active;
> > + wq->max_active = wq_scale_to_unbound(effective_max_active,
> > + nr_cpus);
> > + wq->min_active = min(effective_max_active, wq->max_active);
>
> max_active can't be lower than percpu_max_active here, so min_active can
> just be percpu_max_active. Same in workqueue_set_max_active().

Ack!

> > max_active = wq_clamp_max_active(max_active, wq->flags, wq->name);
> > + nr_cpus = wq_nr_online_cpus(wq_unbound_cpumask);
>
> For unbound workqueues, nr_cpus should match what
> wq_update_node_max_active() distributes max_active over, the online CPUs in
> unbound_effective_cpumask(). With wq_unbound_cpumask, percpu_max_active
> comes out too low for a workqueue with a narrowed cpumask, e.g. 8 instead of
> 64 for max_active 256 on 4 of 64 CPUs. Same in workqueue_set_min_active().
> wq_unbound_cpumask is right for percpu workqueues.

Right, thanks for catching that. I'll change both setters to use
unbound_effective_cpumask() once the workqueue has a pwq installed, and
only fall back to wq_unbound_cpumask before that (percpu workqueues, or
unbound ones still being set up), so it lines up with what
wq_update_node_max_active() already does.

Thanks for the review,
--breno