Skip to content

Commit 0c29f9f

Browse files
Li Fengkeithbusch
authored andcommitted
nvme/tcp: Add wq_unbound modparam for nvme_tcp_wq
The default nvme_tcp_wq will use all CPUs to process tasks. Sometimes it is necessary to set CPU affinity to improve performance. A new module parameter wq_unbound is added here. If set to true, users can configure cpu affinity through /sys/devices/virtual/workqueue/nvme_tcp_wq/cpumask. Signed-off-by: Li Feng <fengli@smartx.com> Reviewed-by: Sagi Grimberg <sagi@grimberg.me> Signed-off-by: Keith Busch <kbusch@kernel.org>
1 parent ec58afb commit 0c29f9f

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

drivers/nvme/host/tcp.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ static int so_priority;
3636
module_param(so_priority, int, 0644);
3737
MODULE_PARM_DESC(so_priority, "nvme tcp socket optimize priority");
3838

39+
/*
40+
* Use the unbound workqueue for nvme_tcp_wq, then we can set the cpu affinity
41+
* from sysfs.
42+
*/
43+
static bool wq_unbound;
44+
module_param(wq_unbound, bool, 0644);
45+
MODULE_PARM_DESC(wq_unbound, "Use unbound workqueue for nvme-tcp IO context (default false)");
46+
3947
/*
4048
* TLS handshake timeout
4149
*/
@@ -1551,7 +1559,10 @@ static void nvme_tcp_set_queue_io_cpu(struct nvme_tcp_queue *queue)
15511559
else if (nvme_tcp_poll_queue(queue))
15521560
n = qid - ctrl->io_queues[HCTX_TYPE_DEFAULT] -
15531561
ctrl->io_queues[HCTX_TYPE_READ] - 1;
1554-
queue->io_cpu = cpumask_next_wrap(n - 1, cpu_online_mask, -1, false);
1562+
if (wq_unbound)
1563+
queue->io_cpu = WORK_CPU_UNBOUND;
1564+
else
1565+
queue->io_cpu = cpumask_next_wrap(n - 1, cpu_online_mask, -1, false);
15551566
}
15561567

15571568
static void nvme_tcp_tls_done(void *data, int status, key_serial_t pskid)
@@ -2790,6 +2801,8 @@ static struct nvmf_transport_ops nvme_tcp_transport = {
27902801

27912802
static int __init nvme_tcp_init_module(void)
27922803
{
2804+
unsigned int wq_flags = WQ_MEM_RECLAIM | WQ_HIGHPRI | WQ_SYSFS;
2805+
27932806
BUILD_BUG_ON(sizeof(struct nvme_tcp_hdr) != 8);
27942807
BUILD_BUG_ON(sizeof(struct nvme_tcp_cmd_pdu) != 72);
27952808
BUILD_BUG_ON(sizeof(struct nvme_tcp_data_pdu) != 24);
@@ -2799,8 +2812,10 @@ static int __init nvme_tcp_init_module(void)
27992812
BUILD_BUG_ON(sizeof(struct nvme_tcp_icresp_pdu) != 128);
28002813
BUILD_BUG_ON(sizeof(struct nvme_tcp_term_pdu) != 24);
28012814

2802-
nvme_tcp_wq = alloc_workqueue("nvme_tcp_wq",
2803-
WQ_MEM_RECLAIM | WQ_HIGHPRI | WQ_SYSFS, 0);
2815+
if (wq_unbound)
2816+
wq_flags |= WQ_UNBOUND;
2817+
2818+
nvme_tcp_wq = alloc_workqueue("nvme_tcp_wq", wq_flags, 0);
28042819
if (!nvme_tcp_wq)
28052820
return -ENOMEM;
28062821

0 commit comments

Comments
 (0)