Skip to content

Commit ce234d8

Browse files
israelrukeithbusch
authored andcommitted
nvmet-rdma: use kvcalloc for commands and responses arrays
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> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Keith Busch <kbusch@kernel.org>
1 parent b645d5a commit ce234d8

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

drivers/nvme/target/rdma.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ nvmet_rdma_alloc_cmds(struct nvmet_rdma_device *ndev,
367367
struct nvmet_rdma_cmd *cmds;
368368
int ret = -EINVAL, i;
369369

370-
cmds = kcalloc(nr_cmds, sizeof(struct nvmet_rdma_cmd), GFP_KERNEL);
370+
cmds = kvcalloc(nr_cmds, sizeof(struct nvmet_rdma_cmd), GFP_KERNEL);
371371
if (!cmds)
372372
goto out;
373373

@@ -382,7 +382,7 @@ nvmet_rdma_alloc_cmds(struct nvmet_rdma_device *ndev,
382382
out_free:
383383
while (--i >= 0)
384384
nvmet_rdma_free_cmd(ndev, cmds + i, admin);
385-
kfree(cmds);
385+
kvfree(cmds);
386386
out:
387387
return ERR_PTR(ret);
388388
}
@@ -394,7 +394,7 @@ static void nvmet_rdma_free_cmds(struct nvmet_rdma_device *ndev,
394394

395395
for (i = 0; i < nr_cmds; i++)
396396
nvmet_rdma_free_cmd(ndev, cmds + i, admin);
397-
kfree(cmds);
397+
kvfree(cmds);
398398
}
399399

400400
static int nvmet_rdma_alloc_rsp(struct nvmet_rdma_device *ndev,
@@ -455,7 +455,7 @@ nvmet_rdma_alloc_rsps(struct nvmet_rdma_queue *queue)
455455
NUMA_NO_NODE, false, true))
456456
goto out;
457457

458-
queue->rsps = kcalloc(nr_rsps, sizeof(struct nvmet_rdma_rsp),
458+
queue->rsps = kvcalloc(nr_rsps, sizeof(struct nvmet_rdma_rsp),
459459
GFP_KERNEL);
460460
if (!queue->rsps)
461461
goto out_free_sbitmap;
@@ -473,7 +473,7 @@ nvmet_rdma_alloc_rsps(struct nvmet_rdma_queue *queue)
473473
out_free:
474474
while (--i >= 0)
475475
nvmet_rdma_free_rsp(ndev, &queue->rsps[i]);
476-
kfree(queue->rsps);
476+
kvfree(queue->rsps);
477477
out_free_sbitmap:
478478
sbitmap_free(&queue->rsp_tags);
479479
out:
@@ -487,7 +487,7 @@ static void nvmet_rdma_free_rsps(struct nvmet_rdma_queue *queue)
487487

488488
for (i = 0; i < nr_rsps; i++)
489489
nvmet_rdma_free_rsp(ndev, &queue->rsps[i]);
490-
kfree(queue->rsps);
490+
kvfree(queue->rsps);
491491
sbitmap_free(&queue->rsp_tags);
492492
}
493493

0 commit comments

Comments
 (0)