From: Seiji Nishikawa <snishika@redhat.com>
To: Keith Busch <kbusch@kernel.org>, Jens Axboe <axboe@kernel.dk>,
Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>
Cc: Hannes Reinecke <hare@suse.de>, Chris Leech <cleech@redhat.com>,
Seiji Nishikawa <snishika@redhat.com>,
linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2] nvme-tcp: limit the direct send path to poll queues
Date: Thu, 26 Nov 2026 15:32:55 +0900 [thread overview]
Message-ID: <20261126063255.3240292-1-snishika@redhat.com> (raw)
nvme_tcp_queue_request() sends the request directly from the submitting
context when it runs on the io_cpu of the queue, the queue is empty and
it can take send_mutex. Commit db5ad6b7f8cd ("nvme-tcp: try to send
request in queue_rq context") added this so that an idle queue can send
the request without waiting for io_work to run.
Since then this path has needed a series of fixes for races and
priority inversions between it and io_work. These are
commit 5c11f7d9f843 ("nvme-tcp: Fix possible race of io_work and direct
send"), commit a0fdd1418007 ("nvme-tcp: rerun io_work if req_list is
not empty"), commit 70f437fb4395 ("nvme-tcp: fix io_work priority
inversion"), commit 08acb54b063a ("nvme-tcp: defer TLS inline send to
io_work") and commit 5db358f3a7f9 ("nvme-tcp: fix io_work priority
inversion when send_mutex is held").
On a non-poll queue, the direct send path makes almost no difference to
the latency. fio with libaio and 4k random I/O at queue depth 1 over a
1Gb network, with and without the direct send path (average of 3 runs
of 60 seconds, latency in usec):
IOPS slat clat lat
randread with 4153 7.1 232.3 239.3
without 4154 4.7 234.7 239.4
randwrite with 2472 24.5 375.6 400.1
without 2460 14.3 387.6 402.0
lat is slat plus clat. It changes by 0.1 usec for randread and by 1.9
usec for randwrite.
On a poll queue, the latency becomes worse without the direct send path.
The submitting task polls for the completion without sleeping. When it
runs on io_cpu, where io_work also runs, the kworker that runs io_work
can send the request only after the task is switched out. This happens
once per request. fio with io_uring and --hipri at queue depth 1 over
the same network, on the io_cpu of a poll queue (ctx is the number of
context switches of fio in one run):
IOPS slat clat lat ctx
randread with 5017 4.72 193.95 198.67 553
without 4179 9.35 229.70 239.05 251,318
randwrite with 3619 5.60 269.94 275.54 542
without 3621 10.62 264.53 275.16 217,806
For randread, lat goes up by 40 usec (20%) without the direct send
path.
So remove the direct send path, except for poll queues. The other
queues always send from io_work, as TLS queues already do.
Add a queue flag, NVME_TCP_Q_POLLED, for this. nvme_tcp_alloc_queue()
sets the flag when the queue is a poll queue, and
nvme_tcp_queue_request() checks it.
Suggested-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Seiji Nishikawa <snishika@redhat.com>
---
Changes since RFC:
- Keep the direct send path for poll queues. Sashiko pointed out the
cost on poll queues, and the numbers in the RFC thread confirm it.
- Drop the patch that removed send_mutex. Poll queues still have 2
senders, so send_mutex is still needed.
RFC: https://lore.kernel.org/linux-nvme/20261122011826.1959697-1-snishika@redhat.com/
drivers/nvme/host/tcp.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
index 62a594b..3725cac 100644
--- a/drivers/nvme/host/tcp.c
+++ b/drivers/nvme/host/tcp.c
@@ -124,6 +124,7 @@ enum nvme_tcp_queue_flags {
NVME_TCP_Q_POLLING = 2,
NVME_TCP_Q_IO_CPU_SET = 3,
NVME_TCP_Q_TLS_RECORD = 4,
+ NVME_TCP_Q_POLLED = 5,
};
#define NVME_TCP_OPT_NR_QUEUES(opts) ((opts)->nr_io_queues + \
@@ -452,15 +453,18 @@ static inline void nvme_tcp_queue_request(struct nvme_tcp_request *req,
list_empty(&queue->send_list) && !queue->request;
/*
- * if we're the first on the send_list and we can try to send
- * directly, otherwise queue io_work. Also, only do that if we
- * are on the same cpu, so we don't introduce contention.
+ * On a poll queue, the submitting task keeps polling on its cpu
+ * instead of sleeping. If that cpu is io_cpu, sending from io_work
+ * would cause a context switch to the kworker for every request.
+ * So send the request directly here if the queue is empty and we
+ * are on io_cpu. Otherwise send from io_work.
*
* TLS kTLS send takes ctx->tx_lock while blk_mq holds set->srcu.
* lockdep reports circular locking via elevator_lock. Defer TLS
* sends to the io workqueue instead of inline from this path.
*/
- if (queue->io_cpu == raw_smp_processor_id() &&
+ if (test_bit(NVME_TCP_Q_POLLED, &queue->flags) &&
+ queue->io_cpu == raw_smp_processor_id() &&
!nvme_tcp_queue_tls(queue) &&
empty && mutex_trylock(&queue->send_mutex)) {
nvme_tcp_send_all(queue);
@@ -2190,6 +2194,8 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid,
queue->sock->sk->sk_allocation = GFP_ATOMIC;
queue->sock->sk->sk_use_task_frag = false;
queue->io_cpu = WORK_CPU_UNBOUND;
+ assign_bit(NVME_TCP_Q_POLLED, &queue->flags,
+ nvme_tcp_poll_queue(queue));
queue->request = NULL;
queue->data_remaining = 0;
queue->ddgst_remaining = 0;
--
2.56.1
next reply other threads:[~2026-11-26 6:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 6:32 Seiji Nishikawa [this message]
2026-11-26 8:53 ` Christoph Hellwig
2026-11-26 9:53 ` Hannes Reinecke
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261126063255.3240292-1-snishika@redhat.com \
--to=snishika@redhat.com \
--cc=axboe@kernel.dk \
--cc=cleech@redhat.com \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®