Skip to contentSkip to conversation

replace old wq(s), added WQ_PERCPU to alloc_workqueue

PATCH Applied Marco Crivellari 3 participants 9 messages Oct 31, 2025 – Nov 20, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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 and system_unbound_wq

system_unbound_wq is to be used when locality is not required.

Because of that, system_unbound_wq has been replaced with
system_dfl_wq, to make clear it should be used when locality is not required.

2) [P 2-3-4] WQ_PERCPU added to alloc_workqueue()

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 (4):
scsi: replace use of system_unbound_wq with system_dfl_wq
scsi: qla2xxx: WQ_PERCPU added to alloc_workqueue users
scsi: scsi_dh_alua: WQ_PERCPU added to alloc_workqueue users
scsi: scsi_transport_fc: WQ_PERCPU added to alloc_workqueue users

 drivers/scsi/device_handler/scsi_dh_alua.c | 2 +-
 drivers/scsi/qla2xxx/qla_os.c              | 4 ++--
 drivers/scsi/scsi_transport_fc.c           | 5 +++--
 drivers/scsi/scsi_transport_iscsi.c        | 2 +-
 4 files changed, 7 insertions(+), 6 deletions(-)
Signature · 1 line
2.51.0
#1 lore raw

PATCH 1/4 scsi: replace use of system_unbound_wq with system_dfl_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 consistency cannot be addressed without refactoring the API.

system_unbound_wq should be the default workqueue so as not to enforce locality constraints for random work whenever it's not required.

Adding system_dfl_wq to encourage its use when unbound work should be used.

The old system_unbound_wq will be kept for a few release cycles.

---
 drivers/scsi/qla2xxx/qla_os.c       | 2 +-
 drivers/scsi/scsi_transport_iscsi.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/qla2xxx/qla_os.c +1 -1
index 5ffd94586652..d48d8671c18a 100644
@@ -5280,7 +5280,7 @@ void qla24xx_sched_upd_fcport(fc_port_t *fcport)
 	qla2x00_set_fcport_disc_state(fcport, DSC_UPD_FCPORT);
 	spin_unlock_irqrestore(&fcport->vha->work_lock, flags);
 
-	queue_work(system_unbound_wq, &fcport->reg_work);
+	queue_work(system_dfl_wq, &fcport->reg_work);
 }
 
 static
drivers/scsi/scsi_transport_iscsi.c +1 -1
index 743b4c792ceb..ed21c032bbc4 100644
@@ -3961,7 +3961,7 @@ iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, uint32_t *group)
 			list_del_init(&session->sess_list);
 			spin_unlock_irqrestore(&sesslock, flags);
 
-			queue_work(system_unbound_wq, &session->destroy_work);
+			queue_work(system_dfl_wq, &session->destroy_work);
 		}
 		break;
 	case ISCSI_UEVENT_UNBIND_SESSION:
Signature · 1 line
2.51.0
#2 lore raw

PATCH 2/4 scsi: qla2xxx: WQ_PERCPU added to alloc_workqueue users

In reply to Marco Crivellari

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.

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.

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/scsi/qla2xxx/qla_os.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/qla2xxx/qla_os.c +1 -1
index d48d8671c18a..af51f1cf5daa 100644
@@ -3397,7 +3397,7 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
 	    "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
 	    req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
 
-	ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 0);
+	ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM | WQ_PERCPU, 0);
 	if (unlikely(!ha->wq)) {
 		ret = -ENOMEM;
 		goto probe_failed;
Signature · 1 line
2.51.0
#3 lore raw

PATCH 3/4 scsi: scsi_dh_alua: WQ_PERCPU added to alloc_workqueue users

In reply to Marco Crivellari

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.

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.

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/scsi/device_handler/scsi_dh_alua.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/device_handler/scsi_dh_alua.c +1 -1
index 1bf5948d1188..6fd89ae33059 100644
@@ -1300,7 +1300,7 @@ static int __init alua_init(void)
 {
 	int r;
 
-	kaluad_wq = alloc_workqueue("kaluad", WQ_MEM_RECLAIM, 0);
+	kaluad_wq = alloc_workqueue("kaluad", WQ_MEM_RECLAIM | WQ_PERCPU, 0);
 	if (!kaluad_wq)
 		return -ENOMEM;
 
Signature · 1 line
2.51.0
#4 lore raw

PATCH 4/4 scsi: scsi_transport_fc: WQ_PERCPU added to alloc_workqueue users

In reply to Marco Crivellari

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.

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.

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/scsi/scsi_transport_fc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/scsi/scsi_transport_fc.c +3 -2
index 3a821afee9bc..987befb02408 100644
@@ -441,7 +441,8 @@ static int fc_host_setup(struct transport_container *tc, struct device *dev,
 	fc_host->next_vport_number = 0;
 	fc_host->npiv_vports_inuse = 0;
 
-	fc_host->work_q = alloc_workqueue("fc_wq_%d", 0, 0, shost->host_no);
+	fc_host->work_q = alloc_workqueue("fc_wq_%d", WQ_PERCPU, 0,
+					  shost->host_no);
 	if (!fc_host->work_q)
 		return -ENOMEM;
 
@@ -3088,7 +3089,7 @@ fc_remote_port_create(struct Scsi_Host *shost, int channel,
 
 	spin_unlock_irqrestore(shost->host_lock, flags);
 
-	rport->devloss_work_q = alloc_workqueue("fc_dl_%d_%d", 0, 0,
+	rport->devloss_work_q = alloc_workqueue("fc_dl_%d_%d", WQ_PERCPU, 0,
 						shost->host_no, rport->number);
 	if (!rport->devloss_work_q) {
 		printk(KERN_ERR "FC Remote Port alloc_workqueue failed\n");
Signature · 1 line
2.51.0
#6 lore raw
In reply to Marco Crivellari

Marco,

Quoted 3 lines

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.

I applied this series and your other applicable workqueue patches to 6.19/scsi-staging. But ugh, that was a lot of work.

Next time, instead of posting individual patches, please prepare one comprehensive series for the entire subsystem and submit that as a unit so I don't have to stitch everything together, deal with dupes, etc.

Signature · 1 line
Martin K. Petersen
#7 lore raw
Quoted 11 lines · Martin K. Petersen

Marco,

Quoted 3 lines

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.

I applied this series and your other applicable workqueue patches to 6.19/scsi-staging. But ugh, that was a lot of work.

Quoted 6 lines

Next time, instead of posting individual patches, please prepare one comprehensive series for the entire subsystem and submit that as a unit so I don't have to stitch everything together, deal with dupes, etc.

--
Martin K. Petersen

Sure Martin, thank you!

--

Marco Crivellari

L3 Support Engineer, Technology & Product

#8 lore raw
In reply to Marco Crivellari
Quoted 10 lines · Marco Crivellari

=== 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);

[...]

Applied to 6.19/scsi-queue, thanks!

[1/4] scsi: replace use of system_unbound_wq with system_dfl_wq

      https://git.kernel.org/mkp/scsi/c/cd87aa2e507a
[2/4] scsi: qla2xxx: WQ_PERCPU added to alloc_workqueue users
      https://git.kernel.org/mkp/scsi/c/5ca003bb4381
[3/4] scsi: scsi_dh_alua: WQ_PERCPU added to alloc_workqueue users
      https://git.kernel.org/mkp/scsi/c/afad6b34defe
[4/4] scsi: scsi_transport_fc: WQ_PERCPU added to alloc_workqueue users
      https://git.kernel.org/mkp/scsi/c/f76e4e1e836d
Signature · 1 line
Martin K. Petersen