[PATCH V2 2/2] nvme-pci: use max of PRP or SGL for iod size
Christoph Hellwig
hch at lst.de
Mon Jul 13 03:42:55 EDT 2020
On Thu, Jul 09, 2020 at 04:40:25PM -0700, Chaitanya Kulkarni wrote:
> >From the initial implementation of NVMe SGL kernel support
> commit a7a7cbe353a5 ("nvme-pci: add SGL support") with addition of the
> commit 943e942e6266 ("nvme-pci: limit max IO size and segments to avoid
> high order allocations") now there is only caller left for
> nvme_pci_iod_alloc_size() which statically passes true for last
> parameter that calculates allocation size based on SGL since we need
> size of biggest command supported for mempool allocation.
>
> This patch modifies the helper functions nvme_pci_iod_alloc_size() such
> that it is now uses maximum of PRP and SGL size for iod allocation size
> calculation.
>
> Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>
> ---
> drivers/nvme/host/pci.c | 13 ++++++-------
> 1 file changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
> index 68f7c090cf51..8b6792005360 100644
> --- a/drivers/nvme/host/pci.c
> +++ b/drivers/nvme/host/pci.c
> @@ -363,14 +363,13 @@ static int nvme_pci_npages_sgl(unsigned int num_seg)
> }
>
> static size_t nvme_pci_iod_alloc_size(struct nvme_dev *dev,
> - unsigned int size, unsigned int nseg, bool use_sgl)
> + unsigned int size, unsigned int nseg)
> {
> - size_t alloc_size;
> + size_t npages_sgl = nvme_pci_npages_sgl(nseg);
> + size_t npages = nvme_npages(size, dev);
> + size_t alloc_size = sizeof(__le64 *);
>
> - if (use_sgl)
> - alloc_size = sizeof(__le64 *) * nvme_pci_npages_sgl(nseg);
> - else
> - alloc_size = sizeof(__le64 *) * nvme_npages(size, dev);
> + alloc_size *= max_t(size_t, npages_sgl, npages);
>
> return alloc_size + sizeof(struct scatterlist) * nseg;
> }
> @@ -2812,7 +2811,7 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> * command we support.
> */
> alloc_size = nvme_pci_iod_alloc_size(dev, NVME_MAX_KB_SZ,
> - NVME_MAX_SEGS, true);
> + NVME_MAX_SEGS);
I think we can just remove the size and nseg arguments and hard code them
in the function itself.
More information about the Linux-nvme
mailing list