[PATCH] nvmet-tcp: get rid of a high-order allocation

Sagi Grimberg sagi at grimberg.me
Mon Aug 26 05:03:33 PDT 2024


Allocating the queue commands array leads to a high order
allocation.

The current size of nvmet_tcp_cmd is 704 bytes. Allocating
128 of those (default queue depth) means that we are allocating
an array of 90K bytes. There is no reason why this will be
a single contiguous allocation. Change the allocation to be
kvcalloc instead.

Signed-off-by: Sagi Grimberg <sagi at grimberg.me>
---
Hannes, I did not test tls (I wish there were blktests for it)
Can you please double check that nothing breaks? Given that now
cmd->recv_cbuf is coming from a virtually contiguous allocation
(which shouldn't be a problem as far as I can tell...)

 drivers/nvme/target/tcp.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c
index 5bff0d5464d1..ba50474c8afc 100644
--- a/drivers/nvme/target/tcp.c
+++ b/drivers/nvme/target/tcp.c
@@ -1516,7 +1516,7 @@ static int nvmet_tcp_alloc_cmds(struct nvmet_tcp_queue *queue)
 	struct nvmet_tcp_cmd *cmds;
 	int i, ret = -EINVAL, nr_cmds = queue->nr_cmds;
 
-	cmds = kcalloc(nr_cmds, sizeof(struct nvmet_tcp_cmd), GFP_KERNEL);
+	cmds = vcalloc(nr_cmds, sizeof(struct nvmet_tcp_cmd));
 	if (!cmds)
 		goto out;
 
@@ -1532,7 +1532,7 @@ static int nvmet_tcp_alloc_cmds(struct nvmet_tcp_queue *queue)
 out_free:
 	while (--i >= 0)
 		nvmet_tcp_free_cmd(cmds + i);
-	kfree(cmds);
+	vfree(cmds);
 out:
 	return ret;
 }
@@ -1546,7 +1546,7 @@ static void nvmet_tcp_free_cmds(struct nvmet_tcp_queue *queue)
 		nvmet_tcp_free_cmd(cmds + i);
 
 	nvmet_tcp_free_cmd(&queue->connect);
-	kfree(cmds);
+	vfree(cmds);
 }
 
 static void nvmet_tcp_restore_socket_callbacks(struct nvmet_tcp_queue *queue)
-- 
2.43.0




More information about the Linux-nvme mailing list