Skip to content

Commit b13c639

Browse files
ChaitanayaKulkarniChristoph Hellwig
authored andcommitted
nvme-pci: use max of PRP or SGL for iod size
>From the initial implementation of NVMe SGL kernel support commit a7a7cbe ("nvme-pci: add SGL support") with addition of the commit 943e942 ("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 <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent 6c3c05b commit b13c639

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

drivers/nvme/host/pci.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,9 @@ static bool nvme_dbbuf_update_and_check_event(u16 value, u32 *dbbuf_db,
346346
* as it only leads to a small amount of wasted memory for the lifetime of
347347
* the I/O.
348348
*/
349-
static int nvme_npages(unsigned size, struct nvme_dev *dev)
349+
static int nvme_pci_npages_prp(void)
350350
{
351-
unsigned nprps = DIV_ROUND_UP(size + NVME_CTRL_PAGE_SIZE,
351+
unsigned nprps = DIV_ROUND_UP(NVME_MAX_KB_SZ + NVME_CTRL_PAGE_SIZE,
352352
NVME_CTRL_PAGE_SIZE);
353353
return DIV_ROUND_UP(8 * nprps, PAGE_SIZE - 8);
354354
}
@@ -357,22 +357,18 @@ static int nvme_npages(unsigned size, struct nvme_dev *dev)
357357
* Calculates the number of pages needed for the SGL segments. For example a 4k
358358
* page can accommodate 256 SGL descriptors.
359359
*/
360-
static int nvme_pci_npages_sgl(unsigned int num_seg)
360+
static int nvme_pci_npages_sgl(void)
361361
{
362-
return DIV_ROUND_UP(num_seg * sizeof(struct nvme_sgl_desc), PAGE_SIZE);
362+
return DIV_ROUND_UP(NVME_MAX_SEGS * sizeof(struct nvme_sgl_desc),
363+
PAGE_SIZE);
363364
}
364365

365-
static size_t nvme_pci_iod_alloc_size(struct nvme_dev *dev,
366-
unsigned int size, unsigned int nseg, bool use_sgl)
366+
static size_t nvme_pci_iod_alloc_size(void)
367367
{
368-
size_t alloc_size;
369-
370-
if (use_sgl)
371-
alloc_size = sizeof(__le64 *) * nvme_pci_npages_sgl(nseg);
372-
else
373-
alloc_size = sizeof(__le64 *) * nvme_npages(size, dev);
368+
size_t npages = max(nvme_pci_npages_prp(), nvme_pci_npages_sgl());
374369

375-
return alloc_size + sizeof(struct scatterlist) * nseg;
370+
return sizeof(__le64 *) * npages +
371+
sizeof(struct scatterlist) * NVME_MAX_SEGS;
376372
}
377373

378374
static int nvme_admin_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
@@ -2811,8 +2807,7 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
28112807
* Double check that our mempool alloc size will cover the biggest
28122808
* command we support.
28132809
*/
2814-
alloc_size = nvme_pci_iod_alloc_size(dev, NVME_MAX_KB_SZ,
2815-
NVME_MAX_SEGS, true);
2810+
alloc_size = nvme_pci_iod_alloc_size();
28162811
WARN_ON_ONCE(alloc_size > PAGE_SIZE);
28172812

28182813
dev->iod_mempool = mempool_create_node(1, mempool_kmalloc,

0 commit comments

Comments
 (0)