public inbox for linux-nvme@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH 1/2] nvmet-rdma: Use kvcalloc for commands and responses arrays
@ 2025-11-24  6:49 Israel Rukshin
  2025-11-24  6:49 ` [PATCH 2/2] nvmet-tcp: Use kvcalloc for commands array Israel Rukshin
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Israel Rukshin @ 2025-11-24  6:49 UTC (permalink / raw)
  To: Linux-nvme, Sagi Grimberg, Christoph Hellwig, Keith Busch,
	Jens Axboe
  Cc: Israel Rukshin, Nitzan Carmi, Max Gurtovoy

Replace kcalloc with kvcalloc for allocation of the commands and
responses arrays. Each command structure is 272 bytes and each
response structure is 672 bytes. These arrays typically exceed a
single page, and grow much larger with high queue depths
(e.g., commands >2MB, responses >170KB)

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>
---
 drivers/nvme/target/rdma.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/nvme/target/rdma.c b/drivers/nvme/target/rdma.c
index 0485e25ab797..9c12b2361a6d 100644
--- a/drivers/nvme/target/rdma.c
+++ b/drivers/nvme/target/rdma.c
@@ -367,7 +367,7 @@ nvmet_rdma_alloc_cmds(struct nvmet_rdma_device *ndev,
 	struct nvmet_rdma_cmd *cmds;
 	int ret = -EINVAL, i;
 
-	cmds = kcalloc(nr_cmds, sizeof(struct nvmet_rdma_cmd), GFP_KERNEL);
+	cmds = kvcalloc(nr_cmds, sizeof(struct nvmet_rdma_cmd), GFP_KERNEL);
 	if (!cmds)
 		goto out;
 
@@ -382,7 +382,7 @@ nvmet_rdma_alloc_cmds(struct nvmet_rdma_device *ndev,
 out_free:
 	while (--i >= 0)
 		nvmet_rdma_free_cmd(ndev, cmds + i, admin);
-	kfree(cmds);
+	kvfree(cmds);
 out:
 	return ERR_PTR(ret);
 }
@@ -394,7 +394,7 @@ static void nvmet_rdma_free_cmds(struct nvmet_rdma_device *ndev,
 
 	for (i = 0; i < nr_cmds; i++)
 		nvmet_rdma_free_cmd(ndev, cmds + i, admin);
-	kfree(cmds);
+	kvfree(cmds);
 }
 
 static int nvmet_rdma_alloc_rsp(struct nvmet_rdma_device *ndev,
@@ -455,7 +455,7 @@ nvmet_rdma_alloc_rsps(struct nvmet_rdma_queue *queue)
 			NUMA_NO_NODE, false, true))
 		goto out;
 
-	queue->rsps = kcalloc(nr_rsps, sizeof(struct nvmet_rdma_rsp),
+	queue->rsps = kvcalloc(nr_rsps, sizeof(struct nvmet_rdma_rsp),
 			GFP_KERNEL);
 	if (!queue->rsps)
 		goto out_free_sbitmap;
@@ -473,7 +473,7 @@ nvmet_rdma_alloc_rsps(struct nvmet_rdma_queue *queue)
 out_free:
 	while (--i >= 0)
 		nvmet_rdma_free_rsp(ndev, &queue->rsps[i]);
-	kfree(queue->rsps);
+	kvfree(queue->rsps);
 out_free_sbitmap:
 	sbitmap_free(&queue->rsp_tags);
 out:
@@ -487,7 +487,7 @@ static void nvmet_rdma_free_rsps(struct nvmet_rdma_queue *queue)
 
 	for (i = 0; i < nr_rsps; i++)
 		nvmet_rdma_free_rsp(ndev, &queue->rsps[i]);
-	kfree(queue->rsps);
+	kvfree(queue->rsps);
 	sbitmap_free(&queue->rsp_tags);
 }
 
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] nvmet-tcp: Use kvcalloc for commands array
  2025-11-24  6:49 [PATCH 1/2] nvmet-rdma: Use kvcalloc for commands and responses arrays Israel Rukshin
@ 2025-11-24  6:49 ` Israel Rukshin
  2025-11-24 14:25   ` Christoph Hellwig
  2025-11-30 22:52   ` Sagi Grimberg
  2025-11-24 14:24 ` [PATCH 1/2] nvmet-rdma: Use kvcalloc for commands and responses arrays Christoph Hellwig
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 7+ messages in thread
From: Israel Rukshin @ 2025-11-24  6:49 UTC (permalink / raw)
  To: Linux-nvme, Sagi Grimberg, Christoph Hellwig, Keith Busch,
	Jens Axboe
  Cc: Israel Rukshin, Nitzan Carmi, Max Gurtovoy

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>
---
 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 470bf37e5a63..23623a95d2b9 100644
--- a/drivers/nvme/target/tcp.c
+++ b/drivers/nvme/target/tcp.c
@@ -1484,7 +1484,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 = kvcalloc(nr_cmds, sizeof(struct nvmet_tcp_cmd), GFP_KERNEL);
 	if (!cmds)
 		goto out;
 
@@ -1500,7 +1500,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);
+	kvfree(cmds);
 out:
 	return ret;
 }
@@ -1514,7 +1514,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);
+	kvfree(cmds);
 }
 
 static void nvmet_tcp_restore_socket_callbacks(struct nvmet_tcp_queue *queue)
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] nvmet-rdma: Use kvcalloc for commands and responses arrays
  2025-11-24  6:49 [PATCH 1/2] nvmet-rdma: Use kvcalloc for commands and responses arrays Israel Rukshin
  2025-11-24  6:49 ` [PATCH 2/2] nvmet-tcp: Use kvcalloc for commands array Israel Rukshin
@ 2025-11-24 14:24 ` Christoph Hellwig
  2025-11-24 19:35 ` Keith Busch
  2025-11-30 22:52 ` Sagi Grimberg
  3 siblings, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2025-11-24 14:24 UTC (permalink / raw)
  To: Israel Rukshin
  Cc: Linux-nvme, Sagi Grimberg, Christoph Hellwig, Keith Busch,
	Jens Axboe, Nitzan Carmi, Max Gurtovoy

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] nvmet-tcp: Use kvcalloc for commands array
  2025-11-24  6:49 ` [PATCH 2/2] nvmet-tcp: Use kvcalloc for commands array Israel Rukshin
@ 2025-11-24 14:25   ` Christoph Hellwig
  2025-11-30 22:52   ` Sagi Grimberg
  1 sibling, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2025-11-24 14:25 UTC (permalink / raw)
  To: Israel Rukshin
  Cc: Linux-nvme, Sagi Grimberg, Christoph Hellwig, Keith Busch,
	Jens Axboe, Nitzan Carmi, Max Gurtovoy

On Mon, Nov 24, 2025 at 08:49:21AM +0200, Israel Rukshin wrote:
> 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.

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] nvmet-rdma: Use kvcalloc for commands and responses arrays
  2025-11-24  6:49 [PATCH 1/2] nvmet-rdma: Use kvcalloc for commands and responses arrays Israel Rukshin
  2025-11-24  6:49 ` [PATCH 2/2] nvmet-tcp: Use kvcalloc for commands array Israel Rukshin
  2025-11-24 14:24 ` [PATCH 1/2] nvmet-rdma: Use kvcalloc for commands and responses arrays Christoph Hellwig
@ 2025-11-24 19:35 ` Keith Busch
  2025-11-30 22:52 ` Sagi Grimberg
  3 siblings, 0 replies; 7+ messages in thread
From: Keith Busch @ 2025-11-24 19:35 UTC (permalink / raw)
  To: Israel Rukshin
  Cc: Linux-nvme, Sagi Grimberg, Christoph Hellwig, Jens Axboe,
	Nitzan Carmi, Max Gurtovoy

On Mon, Nov 24, 2025 at 08:49:20AM +0200, Israel Rukshin wrote:
> Replace kcalloc with kvcalloc for allocation of the commands and
> responses arrays. Each command structure is 272 bytes and each
> response structure is 672 bytes. These arrays typically exceed a
> single page, and grow much larger with high queue depths
> (e.g., commands >2MB, responses >170KB)
> 
> 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.

Thanks, applied to nvme-6.19.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] nvmet-rdma: Use kvcalloc for commands and responses arrays
  2025-11-24  6:49 [PATCH 1/2] nvmet-rdma: Use kvcalloc for commands and responses arrays Israel Rukshin
                   ` (2 preceding siblings ...)
  2025-11-24 19:35 ` Keith Busch
@ 2025-11-30 22:52 ` Sagi Grimberg
  3 siblings, 0 replies; 7+ messages in thread
From: Sagi Grimberg @ 2025-11-30 22:52 UTC (permalink / raw)
  To: Israel Rukshin, Linux-nvme, Christoph Hellwig, Keith Busch,
	Jens Axboe
  Cc: Nitzan Carmi, Max Gurtovoy

Reviewed-by: Sagi Grimberg <sagi@grimberg.me>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] nvmet-tcp: Use kvcalloc for commands array
  2025-11-24  6:49 ` [PATCH 2/2] nvmet-tcp: Use kvcalloc for commands array Israel Rukshin
  2025-11-24 14:25   ` Christoph Hellwig
@ 2025-11-30 22:52   ` Sagi Grimberg
  1 sibling, 0 replies; 7+ messages in thread
From: Sagi Grimberg @ 2025-11-30 22:52 UTC (permalink / raw)
  To: Israel Rukshin, Linux-nvme, Christoph Hellwig, Keith Busch,
	Jens Axboe
  Cc: Nitzan Carmi, Max Gurtovoy

Reviewed-by: Sagi Grimberg <sagi@grimberg.me>


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-11-30 22:52 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-24  6:49 [PATCH 1/2] nvmet-rdma: Use kvcalloc for commands and responses arrays Israel Rukshin
2025-11-24  6:49 ` [PATCH 2/2] nvmet-tcp: Use kvcalloc for commands array Israel Rukshin
2025-11-24 14:25   ` Christoph Hellwig
2025-11-30 22:52   ` Sagi Grimberg
2025-11-24 14:24 ` [PATCH 1/2] nvmet-rdma: Use kvcalloc for commands and responses arrays Christoph Hellwig
2025-11-24 19:35 ` Keith Busch
2025-11-30 22:52 ` Sagi Grimberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox