replace old wq(s), added WQ_PERCPU to alloc_workqueue
Subsystems (4)
cover replace old wq(s), added WQ_PERCPU to alloc_workqueue
Hi,
=== Current situation: problems ===
Let's consider a nohz_full system with isolated CPUs: wq_unbound_cpumask is set to the housekeeping CPUs, for !WQ_UNBOUND the local CPU is selected.
This leads to different scenarios if a work item is scheduled on an isolated CPU where "delay" value is 0 or greater then 0:
schedule_delayed_work(, 0);
This will be handled by __queue_work() that will queue the work item on the current local (isolated) CPU, while:
schedule_delayed_work(, 1);
Will move the timer on an housekeeping CPU, and schedule the work there.
Currently if a user enqueue a work item using schedule_delayed_work() the used wq is "system_wq" (per-cpu wq) while queue_delayed_work() use WORK_CPU_UNBOUND (used when a cpu is not specified). The same applies to schedule_work() that is using system_wq and queue_work(), that makes use again of WORK_CPU_UNBOUND.
This lack of consistency cannot be addressed without refactoring the API.
=== Recent changes to the WQ API ===
The following, address the recent changes in the Workqueue API:
- commit 128ea9f6ccfb ("workqueue: Add system_percpu_wq and system_dfl_wq")
- commit 930c2ea566af ("workqueue: Add new WQ_PERCPU flag")
The old workqueues will be removed in a future release cycle.
=== Introduced Changes by this series ===
1) [P 1] Replace uses of system_wq
system_wq is a per-CPU workqueue, but his name is not clear. Because of that, system_wq has been replaced with system_percpu_wq.
2) [P 2-3] add WQ_PERCPU to all relevant alloc_workqueue() users
This change adds a new WQ_PERCPU flag to explicitly request alloc_workqueue() to be per-cpu when WQ_UNBOUND has not been specified.
Thanks!
Marco Crivellari (3):
nvmet: replace use of system_wq with system_percpu_wq
nvme: add WQ_PERCPU to alloc_workqueue users
nvmet-fc: add WQ_PERCPU to alloc_workqueue users
drivers/nvme/target/admin-cmd.c | 2 +- drivers/nvme/target/core.c | 5 +++-- drivers/nvme/target/fabrics-cmd-auth.c | 2 +- drivers/nvme/target/fc.c | 6 +++--- drivers/nvme/target/tcp.c | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-)
Signature · 1 line
2.51.1
PATCH 1/3 nvmet: replace use of system_wq with system_percpu_wq
Currently if a user enqueue a work item using schedule_delayed_work() the used wq is "system_wq" (per-cpu wq) while queue_delayed_work() use WORK_CPU_UNBOUND (used when a cpu is not specified). The same applies to schedule_work() that is using system_wq and queue_work(), that makes use again of WORK_CPU_UNBOUND.
This lack of consistentcy cannot be addressed without refactoring the API.
This patch continues the effort to refactor worqueue APIs, which has begun with the change introducing new workqueues and a new alloc_workqueue flag:
commit 128ea9f6ccfb ("workqueue: Add system_percpu_wq and system_dfl_wq") commit 930c2ea566af ("workqueue: Add new WQ_PERCPU flag")
system_wq should be the per-cpu workqueue, yet in this name nothing makes that clear, so replace system_wq with system_percpu_wq.
The old wq (system_wq) will be kept for a few release cycles.
--- drivers/nvme/target/admin-cmd.c | 2 +- drivers/nvme/target/fabrics-cmd-auth.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/nvme/target/admin-cmd.c +1 -1
@@ -1604,7 +1604,7 @@ void nvmet_execute_keep_alive(struct nvmet_req *req)pr_debug ("ctrl %d update keep-alive timer for %d secs\n" , ctrl->cntlid, ctrl->kato); -mod_delayed_work (system_wq, &ctrl->ka_work, ctrl->kato *HZ ); +mod_delayed_work (system_percpu_wq, &ctrl->ka_work, ctrl->kato *HZ ); out:nvmet_req_complete (req, status); }
drivers/nvme/target/fabrics-cmd-auth.c +1 -1
@@ -390,7 +390,7 @@ void nvmet_execute_auth_send(struct nvmet_req *req) req->sq->dhchap_step != NVME_AUTH_DHCHAP_MESSAGE_FAILURE2) {unsigned long auth_expire_secs = ctrl->kato ? ctrl->kato :120 ; -mod_delayed_work (system_wq, &req->sq->auth_expired_work, +mod_delayed_work (system_percpu_wq, &req->sq->auth_expired_work, auth_expire_secs *HZ ); goto complete; }
Signature · 1 line
2.51.1
PATCH 2/3 nvme: add WQ_PERCPU to alloc_workqueue users
In reply to Marco CrivellariCurrently if a user enqueue a work item using schedule_delayed_work() the used wq is "system_wq" (per-cpu wq) while queue_delayed_work() use WORK_CPU_UNBOUND (used when a cpu is not specified). The same applies to schedule_work() that is using system_wq and queue_work(), that makes use again of WORK_CPU_UNBOUND.
This lack of consistentcy cannot be addressed without refactoring the API.
alloc_workqueue() treats all queues as per-CPU by default, while unbound workqueues must opt-in via WQ_UNBOUND.
This default is suboptimal: most workloads benefit from unbound queues, allowing the scheduler to place worker threads where they’re needed and reducing noise when CPUs are isolated.
This change adds a new WQ_PERCPU flag to explicitly request alloc_workqueue() to be per-cpu when WQ_UNBOUND has not been specified.
This patch continues the effort to refactor worqueue APIs, which has begun with the change introducing new workqueues and a new alloc_workqueue flag:
commit 128ea9f6ccfb ("workqueue: Add system_percpu_wq and system_dfl_wq") commit 930c2ea566af ("workqueue: Add new WQ_PERCPU flag")
With the introduction of the WQ_PERCPU flag (equivalent to !WQ_UNBOUND), any alloc_workqueue() caller that doesn’t explicitly specify WQ_UNBOUND must now use WQ_PERCPU.
Once migration is complete, WQ_UNBOUND can be removed and unbound will become the implicit default.
--- drivers/nvme/target/core.c | 5 +++-- drivers/nvme/target/tcp.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-)
drivers/nvme/target/core.c +3 -2
@@ -1943,12 +1943,13 @@ static int __init nvmet_init(void)if (!nvmet_bvec_cache)return -ENOMEM ; - zbd_wq =alloc_workqueue ("nvmet-zbd-wq" ,WQ_MEM_RECLAIM ,0 ); + zbd_wq =alloc_workqueue ("nvmet-zbd-wq" ,WQ_MEM_RECLAIM |WQ_PERCPU , +0 );if (!zbd_wq) goto out_destroy_bvec_cache; buffered_io_wq =alloc_workqueue ("nvmet-buffered-io-wq" , -WQ_MEM_RECLAIM ,0 ); +WQ_MEM_RECLAIM |WQ_PERCPU ,0 );if (!buffered_io_wq) goto out_free_zbd_work_queue;
drivers/nvme/target/tcp.c +1 -1
@@ -2198,7 +2198,7 @@ static int __init nvmet_tcp_init(void)int ret; nvmet_tcp_wq =alloc_workqueue ("nvmet_tcp_wq" , -WQ_MEM_RECLAIM |WQ_HIGHPRI ,0 ); +WQ_MEM_RECLAIM |WQ_HIGHPRI |WQ_PERCPU ,0 );if (!nvmet_tcp_wq)return -ENOMEM ;
Signature · 1 line
2.51.1
PATCH 3/3 nvmet-fc: add WQ_PERCPU to alloc_workqueue users
In reply to Marco CrivellariCurrently if a user enqueue a work item using schedule_delayed_work() the used wq is "system_wq" (per-cpu wq) while queue_delayed_work() use WORK_CPU_UNBOUND (used when a cpu is not specified). The same applies to schedule_work() that is using system_wq and queue_work(), that makes use again of WORK_CPU_UNBOUND.
This lack of consistentcy cannot be addressed without refactoring the API.
alloc_workqueue() treats all queues as per-CPU by default, while unbound workqueues must opt-in via WQ_UNBOUND.
This default is suboptimal: most workloads benefit from unbound queues, allowing the scheduler to place worker threads where they’re needed and reducing noise when CPUs are isolated.
This change adds a new WQ_PERCPU flag to explicitly request alloc_workqueue() to be per-cpu when WQ_UNBOUND has not been specified.
This patch continues the effort to refactor worqueue APIs, which has begun with the change introducing new workqueues and a new alloc_workqueue flag:
commit 128ea9f6ccfb ("workqueue: Add system_percpu_wq and system_dfl_wq") commit 930c2ea566af ("workqueue: Add new WQ_PERCPU flag")
With the introduction of the WQ_PERCPU flag (equivalent to !WQ_UNBOUND), any alloc_workqueue() caller that doesn’t explicitly specify WQ_UNBOUND must now use WQ_PERCPU.
Once migration is complete, WQ_UNBOUND can be removed and unbound will become the implicit default.
--- drivers/nvme/target/fc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/nvme/target/fc.c +3 -3
@@ -795,9 +795,9 @@ nvmet_fc_alloc_target_queue(struct nvmet_fc_tgt_assoc *assoc,if (!queue)return NULL ; - queue->work_q =alloc_workqueue ("ntfc%d.%d.%d" ,0 ,0 , - assoc->tgtport->fc_target_port.port_num, - assoc->a_id, qid); + queue->work_q =alloc_workqueue ("ntfc%d.%d.%d" ,WQ_PERCPU ,0 , + assoc->tgtport->fc_target_port.port_num, + assoc->a_id, qid);if (!queue->work_q) goto out_free_queue;
Signature · 1 line
2.51.1
Re: [PATCH 3/3] nvmet-fc: add WQ_PERCPU to alloc_workqueue users
Regards,
Justin
Re: [PATCH 3/3] nvmet-fc: add WQ_PERCPU to alloc_workqueue users
In reply to Marco Crivellaridrivers/nvme/target/fc.c
Quoted 8 lines · Marco Crivellari
[...]
drivers/nvme/target/fc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/nvme/target/fc.c +0
-0
Hi,
Gentle ping.
Thanks!
Signature · 3 lines
Marco Crivellari L3 Support Engineer