Skip to content

Commit 5c8d134

Browse files
israelrukeithbusch
authored andcommitted
nvmet-tcp: use kvcalloc for commands array
Replace kcalloc with kvcalloc for allocation of the commands array. Each command structure is 712 bytes. The array typically exceeds a single page, and grows much larger with high queue depths (e.g., commands >182KB). kvcalloc automatically falls back to vmalloc for large or fragmented allocations, improving reliability. In our case, this memory is not aimed for DMA operations and could be safely allocated by kvcalloc. Using virtually contiguous memory helps to avoid allocation failures and out-of-memory conditions common with kcalloc on large pools. Signed-off-by: Israel Rukshin <israelr@nvidia.com> Reviewed-by: Max Gurtovoy <mgurtovoy@nvidia.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Keith Busch <kbusch@kernel.org>
1 parent ce234d8 commit 5c8d134

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

drivers/nvme/target/tcp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,7 @@ static int nvmet_tcp_alloc_cmds(struct nvmet_tcp_queue *queue)
14841484
struct nvmet_tcp_cmd *cmds;
14851485
int i, ret = -EINVAL, nr_cmds = queue->nr_cmds;
14861486

1487-
cmds = kcalloc(nr_cmds, sizeof(struct nvmet_tcp_cmd), GFP_KERNEL);
1487+
cmds = kvcalloc(nr_cmds, sizeof(struct nvmet_tcp_cmd), GFP_KERNEL);
14881488
if (!cmds)
14891489
goto out;
14901490

@@ -1500,7 +1500,7 @@ static int nvmet_tcp_alloc_cmds(struct nvmet_tcp_queue *queue)
15001500
out_free:
15011501
while (--i >= 0)
15021502
nvmet_tcp_free_cmd(cmds + i);
1503-
kfree(cmds);
1503+
kvfree(cmds);
15041504
out:
15051505
return ret;
15061506
}
@@ -1514,7 +1514,7 @@ static void nvmet_tcp_free_cmds(struct nvmet_tcp_queue *queue)
15141514
nvmet_tcp_free_cmd(cmds + i);
15151515

15161516
nvmet_tcp_free_cmd(&queue->connect);
1517-
kfree(cmds);
1517+
kvfree(cmds);
15181518
}
15191519

15201520
static void nvmet_tcp_restore_socket_callbacks(struct nvmet_tcp_queue *queue)

0 commit comments

Comments
 (0)