replace old wq(s), added WQ_PERCPU to alloc_workqueue
Subsystems (4)
v2 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!
---
Changes in v2:
- improved commit logs
- rebased on v7.0-rc1
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 v2 1/3 nvmet: replace use of system_wq with system_percpu_wq
This patch continues the effort to refactor workqueue APIs, which has begun with the changes 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")
The point of the refactoring is to eventually alter the default behavior of workqueues to become unbound by default so that their workload placement is optimized by the scheduler.
Before that to happen, workqueue users must be converted to the better named new workqueues with no intended behaviour changes:
system_wq -> system_percpu_wq
system_unbound_wq -> system_dfl_wq
This way the old obsolete workqueues (system_wq, system_unbound_wq) can be removed in the future.
--- 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
@@ -1603,7 +1603,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
@@ -391,7 +391,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.52.0
Re: [PATCH v2 1/3] nvmet: replace use of system_wq with system_percpu_wq
Quoted 1 line · Marco Crivellari
system_unbound_wq -> system_dfl_wq
"dfl" is a weird acronym, that doesn't really help understanding the code. What does it even mean?
Either way given that this has already been picked, I guess we're stuck with it, so:
Re: [PATCH v2 1/3] nvmet: replace use of system_wq with system_percpu_wq
Quoted 2 lines · Christoph Hellwig
"dfl" is a weird acronym, that doesn't really help understanding the code. What does it even mean?
default
^ ^ ^
Sebastian
PATCH v2 2/3 nvme: add WQ_PERCPU to alloc_workqueue users
In reply to Marco CrivellariThis continues the effort to refactor workqueue APIs, which began with the introduction of new workqueues and a new alloc_workqueue flag in:
commit 128ea9f6ccfb ("workqueue: Add system_percpu_wq and system_dfl_wq") commit 930c2ea566af ("workqueue: Add new WQ_PERCPU flag")
The refactoring is going to alter the default behavior of alloc_workqueue() to be unbound by default.
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. For more details see the Link tag below.
In order to keep alloc_workqueue() behavior identical, explicitly request WQ_PERCPU.
--- 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
@@ -1942,12 +1942,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
@@ -2225,7 +2225,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.52.0
Re: [PATCH v2 2/3] nvme: add WQ_PERCPU to alloc_workqueue users
Looks good:
PATCH v2 3/3 nvmet-fc: add WQ_PERCPU to alloc_workqueue users
In reply to Marco CrivellariThis continues the effort to refactor workqueue APIs, which began with the introduction of new workqueues and a new alloc_workqueue flag in:
commit 128ea9f6ccfb ("workqueue: Add system_percpu_wq and system_dfl_wq") commit 930c2ea566af ("workqueue: Add new WQ_PERCPU flag")
The refactoring is going to alter the default behavior of alloc_workqueue() to be unbound by default.
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. For more details see the Link tag below.
In order to keep alloc_workqueue() behavior identical, explicitly request WQ_PERCPU.
--- drivers/nvme/target/fc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/nvme/target/fc.c +3 -3
@@ -792,9 +792,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.52.0
Re: [PATCH v2 3/3] nvmet-fc: add WQ_PERCPU to alloc_workqueue users
Looks good:
Quoted 9 lines · Marco Crivellari
1) [P 1] Replace uses of
system_wq
system_wqis a per-CPU workqueue, but his name is not clear. Because of that,system_wqhas been replaced withsystem_percpu_wq.2) [P 2-3] add
WQ_PERCPUto all relevantalloc_workqueue()usersThis change adds a new
WQ_PERCPUflag to explicitly requestalloc_workqueue()to be per-cpu whenWQ_UNBOUNDhas not been specified.
Thanks applied to nvme-7.1.
Quoted 2 lines · Keith Busch
[...]
Thanks applied to nvme-7.1.
Many thanks!
Signature · 3 lines
Marco Crivellari L3 Support Engineer