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

Nilay Shroff nilay at linux.ibm.com
Tue Aug 27 06:27:39 PDT 2024



On 8/26/24 17:33, Sagi Grimberg wrote:
> 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.

Though the description suggests using kvcalloc, the implementation 
uses vcalloc. Maybe a typo here or you want to use kvcalloc instead
of vcalloc? In fact, either of them (kvcalloc or vcalloc) would work
in this case. 
> 
> 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)

Thanks,
--Nilay



More information about the Linux-nvme mailing list