workqueue: don't use wq_select_unbound_cpu() for bound works
PATCH 1/1 workqueue: don't use wq_select_unbound_cpu() for bound works
From: Hillf Danton <[email protected]>
wq_select_unbound_cpu() is designed for unbound workqueues only, but it's wrongly called when using a bound workqueue too.
Fixing this ensures work queued to a bound workqueue with cpu=WORK_CPU_UNBOUND always runs on the local CPU.
Before, that would happen only if wq_unbound_cpumask happened to include it (likely almost always the case), or was empty, or we got lucky with forced round-robin placement. So restricting /sys/devices/virtual/workqueue/cpumask to a small subset of a machine's CPUs would cause some bound work items to run unexpectedly there.
--- kernel/workqueue.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
kernel/workqueue.c +8 -6
@@ -1411,14 +1411,16 @@ static void __queue_work(int cpu, struct workqueue_struct *wq,return ;rcu_read_lock (); retry: -if (req_cpu ==WORK_CPU_UNBOUND ) - cpu =wq_select_unbound_cpu (raw_smp_processor_id ()); -/* pwq which will be used unless @work is executing elsewhere */ -if (!(wq->flags &WQ_UNBOUND )) - pwq =per_cpu_ptr (wq->cpu_pwqs, cpu); -else +if (wq->flags &WQ_UNBOUND ) { +if (req_cpu ==WORK_CPU_UNBOUND ) + cpu =wq_select_unbound_cpu (raw_smp_processor_id ()); pwq =unbound_pwq_by_node (wq,cpu_to_node (cpu)); + }else { +if (req_cpu ==WORK_CPU_UNBOUND ) + cpu =raw_smp_processor_id (); + pwq =per_cpu_ptr (wq->cpu_pwqs, cpu); + }/* * If @work was previously on a different pool, it might still be
Signature · 1 line
2.24.1
Quoted 14 lines · Daniel Jordan
From: Hillf Danton <[email protected]>
wq_select_unbound_cpu()is designed for unbound workqueues only, but it's wrongly called when using a bound workqueue too.Fixing this ensures work queued to a bound workqueue with cpu=WORK_CPU_UNBOUND always runs on the local CPU.
Before, that would happen only if
wq_unbound_cpumaskhappened to include it (likely almost always the case), or was empty, or we got lucky with forced round-robin placement. So restricting/sys/devices/virtual/workqueue/cpumaskto a small subset of a machine's CPUs would cause some bound work items to run unexpectedly there.
Quoted 7 lines
Fixes ef557180447f ("workqueue: schedule WORK_CPU_UNBOUND work on wq_unbound_cpumask CPUs")Signed-off-by Hillf Danton <[email protected]>[dj: massage changelog]Signed-off-by Daniel Jordan <[email protected]>Cc Tejun Heo <[email protected]>Cc Lai Jiangshan <[email protected]>
Applied to wq/for-5.6-fixes.
Thanks.
Signature · 1 line
tejun