[PATCH RFC 1/3] workqueue: Add WQ_PREFER_PERCPU and system_prefer_percpu_wq

From: Marco Crivellari

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


There may be situations where local execution is not strictly needed
for correctness, but it is preferred for performance gains.

The Workqueue API currently does not distinguish between these two
instances.

So add WQ_PREFER_PERCPU and system_prefer_percpu_wq, so that it would
be the first choice for workloads that don't strictly need local
execution for correctness but only to maintain locality.

Link: https://lore.kernel.org/all/20250221112003.1dSuoGyc@xxxxxxxxxxxxx/
Suggested-by: Tejun Heo <tj@xxxxxxxxxx>
Signed-off-by: Marco Crivellari <marco.crivellari@xxxxxxxx>
---
include/linux/workqueue.h | 17 ++++++++++++++++-
kernel/workqueue.c | 7 ++++++-
2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h
index 1caacdb5bc8e..9c315f354b5a 100644
--- a/include/linux/workqueue.h
+++ b/include/linux/workqueue.h
@@ -403,6 +403,15 @@ enum wq_flags {
WQ_PERCPU = 1 << 8, /* bound to a specific cpu */
WQ_RT = 1 << 9, /* real-time priority, invalid with WQ_PERCPU */

+ /*
+ * Like WQ_PERCPU, for work that only prefers the queueing CPU for
+ * locality. While a CPU is isolated (isolcpus=domain or a cgroup v2
+ * isolated partition), work queued on it runs on an unbound pool on
+ * the housekeeping CPUs instead; once the CPU stops being isolated,
+ * its per-cpu pool is used again. Implies WQ_PERCPU.
+ */
+ WQ_PREFER_PERCPU = 1 << 10,
+
__WQ_DESTROYING = 1 << 15, /* internal: workqueue is destroying */
__WQ_DRAINING = 1 << 16, /* internal: workqueue is draining */
__WQ_ORDERED = 1 << 17, /* internal: workqueue is ordered */
@@ -459,6 +468,9 @@ enum wq_consts {
*
* system_bh[_highpri]_wq are convenience interface to softirq. BH work items
* are executed in the queueing CPU's BH context in the queueing order.
+ *
+ * system_prefer_percpu_wq is for work items which prefer to run on the
+ * queueing CPU for locality but don't require it; see WQ_PREFER_PERCPU.
*/
extern struct workqueue_struct *system_wq; /* use system_percpu_wq, this will be removed */
extern struct workqueue_struct *system_percpu_wq;
@@ -472,6 +484,7 @@ extern struct workqueue_struct *system_freezable_power_efficient_wq;
extern struct workqueue_struct *system_bh_wq;
extern struct workqueue_struct *system_bh_highpri_wq;
extern struct workqueue_struct *system_dfl_long_wq;
+extern struct workqueue_struct *system_prefer_percpu_wq;

void workqueue_softirq_action(bool highpri);
void workqueue_softirq_dead(unsigned int cpu);
@@ -821,7 +834,9 @@ extern void __warn_flushing_systemwide_wq(void)
(__builtin_constant_p(_wq == system_power_efficient_wq) && \
_wq == system_power_efficient_wq) || \
(__builtin_constant_p(_wq == system_freezable_power_efficient_wq) && \
- _wq == system_freezable_power_efficient_wq)) \
+ _wq == system_freezable_power_efficient_wq) || \
+ (__builtin_constant_p(_wq == system_prefer_percpu_wq) && \
+ _wq == system_prefer_percpu_wq)) \
__warn_flushing_systemwide_wq(); \
__flush_workqueue(_wq); \
})
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 558049dbb894..73c61a55d4ce 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -566,6 +566,8 @@ struct workqueue_struct *system_bh_highpri_wq;
EXPORT_SYMBOL_GPL(system_bh_highpri_wq);
struct workqueue_struct *system_dfl_long_wq __ro_after_init;
EXPORT_SYMBOL_GPL(system_dfl_long_wq);
+struct workqueue_struct *system_prefer_percpu_wq __ro_after_init;
+EXPORT_SYMBOL_GPL(system_prefer_percpu_wq);

static int worker_thread(void *__worker);
static void workqueue_sysfs_unregister(struct workqueue_struct *wq);
@@ -8483,11 +8485,14 @@ void __init workqueue_init_early(void)
system_bh_highpri_wq = alloc_workqueue("events_bh_highpri",
WQ_BH | WQ_HIGHPRI | WQ_PERCPU, 0);
system_dfl_long_wq = alloc_workqueue("events_dfl_long", WQ_UNBOUND, WQ_MAX_ACTIVE);
+ system_prefer_percpu_wq = alloc_workqueue("events_prefer_percpu",
+ WQ_PERCPU | WQ_PREFER_PERCPU, 0);
BUG_ON(!system_wq || !system_percpu_wq|| !system_highpri_wq || !system_long_wq ||
!system_unbound_wq || !system_freezable_wq || !system_dfl_wq ||
!system_power_efficient_wq ||
!system_freezable_power_efficient_wq ||
- !system_bh_wq || !system_bh_highpri_wq || !system_dfl_long_wq);
+ !system_bh_wq || !system_bh_highpri_wq || !system_dfl_long_wq ||
+ !system_prefer_percpu_wq);
}

static void __init wq_cpu_intensive_thresh_init(void)
--
2.56.0