The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH RFC 0/3] workqueue: Add WQ_PREFER_PERCPU
@ 2026-11-26 15:24 Marco Crivellari
  2026-11-26 15:24 ` [PATCH RFC 1/3] workqueue: Add WQ_PREFER_PERCPU and system_prefer_percpu_wq Marco Crivellari
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Marco Crivellari @ 2026-11-26 15:24 UTC (permalink / raw)
  To: linux-kernel
  Cc: Tejun Heo, Lai Jiangshan, Frederic Weisbecker,
	Sebastian Andrzej Siewior, Marco Crivellari, Michal Hocko,
	Breno Leitao

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@linutronix.de/

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-27 20:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 15:24 [PATCH RFC 0/3] workqueue: Add WQ_PREFER_PERCPU Marco Crivellari
2026-11-26 15:24 ` [PATCH RFC 1/3] workqueue: Add WQ_PREFER_PERCPU and system_prefer_percpu_wq Marco Crivellari
2026-11-26 15:24 ` [PATCH RFC 2/3] workqueue: Offload WQ_PREFER_PERCPU work from isolated CPUs Marco Crivellari
2026-11-27 20:54   ` Tejun Heo
2026-11-26 15:24 ` [PATCH RFC 3/3] workqueue: doc: Document WQ_PREFER_PERCPU Marco Crivellari

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox