[PATCH RFC 0/3] workqueue: Add WQ_PREFER_PERCPU

From: Marco Crivellari

Date: Thu Nov 26 2026 - 10:25:20 EST


Hi,

I would like to better understand if I'm heading in the right direction
about WQ_PREFER_PERCPU and the dynamic pool selection.

Any comment is highly appreciated, thanks in advance!

----

Today a workqueue is either per-cpu or unbound. A WQ_PERCPU workqueue
runs the work on the CPU where it was queued, and it is concurrency
managed. A WQ_UNBOUND workqueue runs the work on a CPU chosen by the
scheduler, and it only uses the housekeeping CPUs.

Many WQ_PERCPU users don't need the work to run on the local CPU for
correctness: they only want cache locality. But because they are
per-cpu, they also run on isolated CPUs. When a CPU is isolated with
isolcpus=domain, or at runtime with a cgroup v2 isolated partition, the
per-cpu work queued on it still runs there and disturbs the isolated
workload.

This series adds WQ_PREFER_PERCPU for these users, following the
discussion in [1]. The flag implies WQ_PERCPU, so normally the
workqueue is a regular per-cpu workqueue, concurrency managed. While a
CPU is isolated, the pwq of that CPU is backed by an unbound pool on
the housekeeping CPUs, so the work queued there runs on another CPU.
When the CPU is not isolated anymore, the per-cpu pool is used again.

The pwqs are switched when the isolated cpumask changes, in
workqueue_unbound_housekeeping_update(), and also when the workqueue
cpumask is changed through sysfs. Only the CPUs that need it get a new
pwq. On an isolated CPU the work is not concurrency managed anymore,
like on an unbound workqueue, but max_active is still counted per pwq,
because the workqueue is not WQ_UNBOUND.

Note:

- Work items already queued on a CPU when it becomes isolated still run
there. Only the work queued after the switch goes to the unbound pool.

Changes introduced:

- [P1] workqueue: Add WQ_PREFER_PERCPU and system_prefer_percpu_wq

Adds the flag and system_prefer_percpu_wq

- [P2] workqueue: Offload WQ_PREFER_PERCPU work from isolated CPUs

Runtime switch of the backed pool when a workqueue with
WQ_PREFER_PERCPU run on an isolated CPU.

- [P3] workqueue: doc: Document WQ_PREFER_PERCPU

Documents the flag.

I tested it in virtme-ng guests with a test module that checks where
the work runs and which pool is behind the pwq: runtime partitions,
isolcpus=domain, the sysfs cpumask, CPU hotplug and a stress test that
queues work from every CPU while CPUs are isolated and released.

Thanks,

- [1] https://lore.kernel.org/all/20250221112003.1dSuoGyc@xxxxxxxxxxxxx/

Marco Crivellari (3):
workqueue: Add WQ_PREFER_PERCPU and system_prefer_percpu_wq
workqueue: Offload WQ_PREFER_PERCPU work from isolated CPUs
workqueue: doc: Document WQ_PREFER_PERCPU

Documentation/core-api/workqueue.rst | 8 ++
include/linux/workqueue.h | 17 ++-
kernel/workqueue.c | 150 +++++++++++++++++++++++----
3 files changed, 156 insertions(+), 19 deletions(-)

--
2.56.0