[PATCH 07/19] nvmet-tcp: let the accept work come to an end
Keith Busch
kbusch at meta.com
Thu Oct 29 08:52:40 PDT 2026
From: Josef Bacik <josef at toxicpanda.com>
nvmet_tcp_accept_work() loops until there's nothing left to accept, and
anyone opening and closing connections fast enough keeps it running
indefinitely, since tearing down a dead connection takes long enough for
more to arrive. Whoever flushes nvmet_wq waits for it: removing any
other port of the target does in nvmet_port_release(), and so does
unloading the rdma and fc modules.
Accept a bounded number of connections per run and requeue the work. A
flush doesn't wait for work queued behind it.
Fixes: 872d26a391da ("nvmet-tcp: add NVMe over TCP target driver")
Cc: Christoph Hellwig <hch at lst.de>
Cc: Sagi Grimberg <sagi at grimberg.me>
Cc: Chaitanya Kulkarni <kch at nvidia.com>
Reviewed-by: Hannes Reinecke <hare at kernel.org>
Signed-off-by: Josef Bacik <josef at toxicpanda.com>
Signed-off-by: Jens Axboe <axboe at kernel.dk>
Signed-off-by: Keith Busch <kbusch at kernel.org>
---
drivers/nvme/target/tcp.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c
index 158e422851a4b..5105317cc61e3 100644
--- a/drivers/nvme/target/tcp.c
+++ b/drivers/nvme/target/tcp.c
@@ -102,6 +102,7 @@ MODULE_PARM_DESC(tls_handshake_timeout,
#define NVMET_TCP_RECV_BUDGET 8
#define NVMET_TCP_SEND_BUDGET 8
#define NVMET_TCP_IO_WORK_BUDGET 64
+#define NVMET_TCP_ACCEPT_BUDGET 16
enum nvmet_tcp_send_state {
NVMET_TCP_SEND_DATA_PDU,
@@ -2073,9 +2074,9 @@ static void nvmet_tcp_accept_work(struct work_struct *w)
struct nvmet_tcp_port *port =
container_of(w, struct nvmet_tcp_port, accept_work);
struct socket *newsock;
- int ret;
+ int ret, i;
- while (true) {
+ for (i = 0; i < NVMET_TCP_ACCEPT_BUDGET; i++) {
ret = kernel_accept(port->sock, &newsock, O_NONBLOCK);
if (ret < 0) {
if (ret != -EAGAIN)
@@ -2084,6 +2085,9 @@ static void nvmet_tcp_accept_work(struct work_struct *w)
}
nvmet_tcp_alloc_queue(port, newsock);
}
+
+ /* There may be more. Come to an end for those who flush nvmet_wq. */
+ queue_work(nvmet_wq, &port->accept_work);
}
static void nvmet_tcp_listen_data_ready(struct sock *sk)
--
2.52.0
More information about the Linux-nvme
mailing list