[PATCH 3/3] nvme-tcp: per-controller I/O workqueues
Hannes Reinecke
hare at kernel.org
Mon Jul 8 00:10:13 PDT 2024
From: Hannes Reinecke <hare at suse.de>
Implement per-controller I/O workqueues to reduce workqueue contention
during I/O and improve I/O performance.
Performance comparison:
baseline rx/tx blk-mq multiple workqueues
4k seq write: 449MiB/s 480MiB/s 524MiB/s 540MiB/s
4k rand write: 410MiB/s 481MiB/s 524MiB/s 539MiB/s
4k seq read: 478MiB/s 481MiB/s 566MiB/s 582MiB/s
4k rand read: 547MiB/s 480MiB/s 511MiB/s 633MiB/s
Signed-off-by: Hannes Reinecke <hare at kernel.org>
---
drivers/nvme/host/tcp.c | 34 ++++++++++++++++++----------------
1 file changed, 18 insertions(+), 16 deletions(-)
diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
index a5c42a7b4bee..fc8f682f686d 100644
--- a/drivers/nvme/host/tcp.c
+++ b/drivers/nvme/host/tcp.c
@@ -194,6 +194,7 @@ struct nvme_tcp_ctrl {
struct sockaddr_storage src_addr;
struct nvme_ctrl ctrl;
+ struct workqueue_struct *io_wq;
struct work_struct err_work;
struct delayed_work connect_work;
struct nvme_tcp_request async_req;
@@ -202,7 +203,6 @@ struct nvme_tcp_ctrl {
static LIST_HEAD(nvme_tcp_ctrl_list);
static DEFINE_MUTEX(nvme_tcp_ctrl_mutex);
-static struct workqueue_struct *nvme_tcp_wq;
static const struct blk_mq_ops nvme_tcp_mq_ops;
static const struct blk_mq_ops nvme_tcp_admin_mq_ops;
static int nvme_tcp_try_send(struct nvme_tcp_queue *queue);
@@ -410,7 +410,7 @@ static inline void nvme_tcp_queue_request(struct nvme_tcp_request *req,
}
if (last && nvme_tcp_queue_has_pending(queue))
- queue_work_on(queue->io_cpu, nvme_tcp_wq, &queue->io_work);
+ queue_work_on(queue->io_cpu, queue->ctrl->io_wq, &queue->io_work);
}
static void nvme_tcp_process_req_list(struct nvme_tcp_queue *queue)
@@ -987,7 +987,7 @@ static void nvme_tcp_data_ready(struct sock *sk)
queue = sk->sk_user_data;
if (likely(queue && queue->rd_enabled) &&
!test_bit(NVME_TCP_Q_POLLING, &queue->flags))
- queue_work_on(queue->io_cpu, nvme_tcp_wq, &queue->io_work);
+ queue_work_on(queue->io_cpu, queue->ctrl->io_wq, &queue->io_work);
read_unlock_bh(&sk->sk_callback_lock);
}
@@ -999,7 +999,7 @@ static void nvme_tcp_write_space(struct sock *sk)
queue = sk->sk_user_data;
if (likely(queue && sk_stream_is_writeable(sk))) {
clear_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
- queue_work_on(queue->io_cpu, nvme_tcp_wq, &queue->io_work);
+ queue_work_on(queue->io_cpu, queue->ctrl->io_wq, &queue->io_work);
}
read_unlock_bh(&sk->sk_callback_lock);
}
@@ -1325,7 +1325,7 @@ static void nvme_tcp_io_work(struct work_struct *w)
dev_dbg(queue->ctrl->ctrl.device, "queue %d: queue stall (%u msecs)\n",
nvme_tcp_queue_id(queue), jiffies_to_msecs(overrun));
- queue_work_on(queue->io_cpu, nvme_tcp_wq, &queue->io_work);
+ queue_work_on(queue->io_cpu, queue->ctrl->io_wq, &queue->io_work);
}
static void nvme_tcp_free_crypto(struct nvme_tcp_queue *queue)
@@ -2486,6 +2486,8 @@ static void nvme_tcp_free_ctrl(struct nvme_ctrl *nctrl)
nvmf_free_options(nctrl->opts);
free_ctrl:
+ destroy_workqueue(ctrl->io_wq);
+
kfree(ctrl->queues);
kfree(ctrl);
}
@@ -2676,7 +2678,7 @@ static void nvme_tcp_commit_rqs(struct blk_mq_hw_ctx *hctx)
struct nvme_tcp_queue *queue = hctx->driver_data;
if (!llist_empty(&queue->req_list))
- queue_work_on(queue->io_cpu, nvme_tcp_wq, &queue->io_work);
+ queue_work_on(queue->io_cpu, queue->ctrl->io_wq, &queue->io_work);
}
static blk_status_t nvme_tcp_queue_rq(struct blk_mq_hw_ctx *hctx,
@@ -2812,6 +2814,7 @@ static struct nvme_tcp_ctrl *nvme_tcp_alloc_ctrl(struct device *dev,
struct nvmf_ctrl_options *opts)
{
struct nvme_tcp_ctrl *ctrl;
+ unsigned int wq_flags = WQ_MEM_RECLAIM | WQ_HIGHPRI | WQ_SYSFS;
int ret;
ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL);
@@ -2883,6 +2886,15 @@ static struct nvme_tcp_ctrl *nvme_tcp_alloc_ctrl(struct device *dev,
if (ret)
goto out_kfree_queues;
+ if (wq_unbound)
+ wq_flags |= WQ_UNBOUND;
+ ctrl->io_wq = alloc_workqueue("nvme_tcp_wq_%d", wq_flags, 0,
+ ctrl->ctrl.instance);
+ if (!ctrl->io_wq) {
+ nvme_put_ctrl(&ctrl->ctrl);
+ return ERR_PTR(-ENOMEM);
+ }
+
return ctrl;
out_kfree_queues:
kfree(ctrl->queues);
@@ -2948,7 +2960,6 @@ static struct nvmf_transport_ops nvme_tcp_transport = {
static int __init nvme_tcp_init_module(void)
{
- unsigned int wq_flags = WQ_MEM_RECLAIM | WQ_HIGHPRI | WQ_SYSFS;
int cpu;
BUILD_BUG_ON(sizeof(struct nvme_tcp_hdr) != 8);
@@ -2960,13 +2971,6 @@ static int __init nvme_tcp_init_module(void)
BUILD_BUG_ON(sizeof(struct nvme_tcp_icresp_pdu) != 128);
BUILD_BUG_ON(sizeof(struct nvme_tcp_term_pdu) != 24);
- if (wq_unbound)
- wq_flags |= WQ_UNBOUND;
-
- nvme_tcp_wq = alloc_workqueue("nvme_tcp_wq", wq_flags, 0);
- if (!nvme_tcp_wq)
- return -ENOMEM;
-
for_each_possible_cpu(cpu)
atomic_set(&nvme_tcp_cpu_queues[cpu], 0);
@@ -2985,8 +2989,6 @@ static void __exit nvme_tcp_cleanup_module(void)
nvme_delete_ctrl(&ctrl->ctrl);
mutex_unlock(&nvme_tcp_ctrl_mutex);
flush_workqueue(nvme_delete_wq);
-
- destroy_workqueue(nvme_tcp_wq);
}
module_init(nvme_tcp_init_module);
--
2.35.3
More information about the Linux-nvme
mailing list