workqueue: Keep max_active and percpu_max_active in sync
Get series with b4
b4 am [email protected] change-id 20260914-wq_final-bcfbcd3b0f79Versions newest first
- v4 Latest2 patches 3 repliesIn review
- v33 patches 5 repliesSuperseded
- v23 patches 4 repliesSuperseded
Earlier versions · 1
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v1 RFC | 3 patches | 5 replies | Superseded |
Changes in v4 from the cover letter
- Folded the topology rescale (v3 3/3) into patch 2 (Tejun)
- Added wq_rescale_max_active(): it derives the other domain from the backend's own saved limits and publishes both through wq_adjust_max_active(). The setters, apply_wqattrs_commit() and workqueue_init_topology() call it, so the topology pass no longer passes a derived limit back in, resets min_active or writes the live limits directly (Tejun)
- Rederive in apply_wqattrs_commit() so N follows cpumask changes, and set only the backend's own limits in wq_init_max_active() (Tejun)
- Test WQ_UNBOUND in wq_nr_effective_cpus() instead of installed_pwq() (Tejun)
- Pair the READ_ONCE() in wq_user_max_active() with WRITE_ONCE() (Tejun)
- Reworded the wq_adjust_max_active() comment as a contract (Tejun)
- Patch 2 changelog: spelled out the conversions, explained the wq_user_max_active() readers and what is not resampled, dropped the CM/RCU wording (Tejun)
- Dropped the PS from patch 1's changelog (Tejun)
- Rebased on wq/for-7.5
- Link to v3: https://patch.msgid.link/[email protected]
Patches in v4 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/2 | workqueue: Move the initial max_active setup into a helperkernel/ | +27 | 0 replies | |
| 2/2 | workqueue: Keep the limits of both max_active domains currentkernel/ | +120 | 3 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v4 yet.
Cover letter [PATCH wq/for-7.5 v4 0/2] workqueue: Keep max_active and percpu_max_active in sync
Commit 27db9dd7f84f3a ("workqueue: Give percpu workqueues their own max_active") gave the percpu backend a limit of its own, so a workqueue now carries both percpu_max_active and max_active.
__alloc_workqueue() only ever sets the pair matching the backend the workqueue is created on, so the other stays at zero for its lifetime.
Nothing reads "the other scope" max_active today, so this is groundwork rather than a fix.
Two patches. The first moves the initial limit setup out of __alloc_workqueue() into wq_init_max_active().
The second sets both domains rather than one, according to Tejun's recommendation:
U = unbound max_active, the system-wide target
L = unbound min_active, the floor on each node
P = percpu_max_active, the limit on each CPU
N = online CPUs in the effective unbound mask, at least 1
Setting P:
U = min(P * N, WQ_MAX_ACTIVE)
L = P
Setting U:
L = min(L, U)
P = max(DIV_ROUND_UP(U, N), L)Setting L:
L = clamp(L, 0, U)
P = max(DIV_ROUND_UP(U, N), L)It rederives the other domain when the cpumask changes and once CPU topology is known, as workqueues created before smp_init() count only the boot CPU.
This shouldn't change the behaviour of workqueue for now, but keeps the groundwork correct for the PERCPU affinity scope work it's meant to enable.
---
Changes in v4:
- Folded the topology rescale (v3 3/3) into patch 2 (Tejun)
- Added wq_rescale_max_active(): it derives the other domain from the backend's own saved limits and publishes both through wq_adjust_max_active(). The setters, apply_wqattrs_commit() and workqueue_init_topology() call it, so the topology pass no longer passes a derived limit back in, resets min_active or writes the live limits directly (Tejun)
- Rederive in apply_wqattrs_commit() so N follows cpumask changes, and set only the backend's own limits in wq_init_max_active() (Tejun)
- Test WQ_UNBOUND in wq_nr_effective_cpus() instead of installed_pwq() (Tejun)
- Pair the READ_ONCE() in wq_user_max_active() with WRITE_ONCE() (Tejun)
- Reworded the wq_adjust_max_active() comment as a contract (Tejun)
- Patch 2 changelog: spelled out the conversions, explained the wq_user_max_active() readers and what is not resampled, dropped the CM/RCU wording (Tejun)
- Dropped the PS from patch 1's changelog (Tejun)
- Rebased on wq/for-7.5
- Link to v3: https://patch.msgid.link/[email protected]
Changes in v3:
- Dropped the silly percpu_concurrency_managed attribute patch.
- Fixed N to come from the workqueue's own unbound_effective_cpumask()
- Added a patch rederiving both domains once workqueue_init_topology() knows the real CPU count.
- Handled BH in one place: wq_init_max_active() sets the limits of a BH workqueue through wq_init_bh_max_active() and returns, instead of giving BH its own branch further down (Tejun)
- Set min_active to percpu_max_active when deriving from a percpu limit instead of min(percpu_max_active, max_active), as max_active can never be lower (Tejun)
- Changelog of patch 2 now refers to the new PERCPU affinity scope rather than WQ_AFFN_CPU (Tejun)
- Link to v2: https://patch.msgid.link/[email protected]
Changes in v2:
- Cut the series down to the three patches that change nothing observable. The runtime scaling, the affinity scopes, the backend rework, the concurrency management attribute and the sysfs files are all held back.
- Set both max_active domains instead of holding them equal, deriving one from the other rather than duplicating the value (Tejun)
- Link to v1:
https://patch.msgid.link/[email protected]
---
Breno Leitao (2):
workqueue: Move the initial max_active setup into a helper
workqueue: Keep the limits of both max_active domains current
kernel/workqueue.c | 186 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 141 insertions(+), 45 deletions(-)
---
base-commit: e92304919f8104ef1452a6389fc54311e857b953
base-tree: git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq.git for-7.5
change-id: 20260914-wq_final-bcfbcd3b0f79
Best regards,
Signature · 1 line
Breno Leitao <[email protected]>