Skip to content

Commit 414a4c9

Browse files
author
Christoph Hellwig
committed
nvme-pci: derive and better document max segments limits
Redefine the max segments and max integrity limits based on the limiting factors. This keeps exactly the same values for 4k PAGE_SIZE systems, but increases the number of segments for larger page size as it properly derives the scatterlist allocation based limit for them instead of assuming a 4k PAGE_SIZE. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Keith Busch <[email protected]>
1 parent de65e64 commit 414a4c9

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

drivers/nvme/host/pci.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
#define SQ_SIZE(q) ((q)->q_depth << (q)->sqes)
3636
#define CQ_SIZE(q) ((q)->q_depth * sizeof(struct nvme_completion))
3737

38-
#define SGES_PER_PAGE (NVME_CTRL_PAGE_SIZE / sizeof(struct nvme_sgl_desc))
39-
4038
/* Optimisation for I/Os between 4k and 128k */
4139
#define NVME_SMALL_POOL_SIZE 256
4240

@@ -45,10 +43,24 @@
4543
* require an sg allocation that needs more than a page of data.
4644
*/
4745
#define NVME_MAX_KB_SZ 8192
48-
#define NVME_MAX_SEGS 128
49-
#define NVME_MAX_META_SEGS 15
5046
#define NVME_MAX_NR_DESCRIPTORS 5
5147

48+
/*
49+
* For data SGLs we support a single descriptors worth of SGL entries, but for
50+
* now we also limit it to avoid an allocation larger than PAGE_SIZE for the
51+
* scatterlist.
52+
*/
53+
#define NVME_MAX_SEGS \
54+
min(NVME_CTRL_PAGE_SIZE / sizeof(struct nvme_sgl_desc), \
55+
(PAGE_SIZE / sizeof(struct scatterlist)))
56+
57+
/*
58+
* For metadata SGLs, only the small descriptor is supported, and the first
59+
* entry is the segment descriptor, which for the data pointer sits in the SQE.
60+
*/
61+
#define NVME_MAX_META_SEGS \
62+
((NVME_SMALL_POOL_SIZE / sizeof(struct nvme_sgl_desc)) - 1)
63+
5264
static int use_threaded_interrupts;
5365
module_param(use_threaded_interrupts, int, 0444);
5466

@@ -3829,8 +3841,6 @@ static int __init nvme_init(void)
38293841
BUILD_BUG_ON(sizeof(struct nvme_create_sq) != 64);
38303842
BUILD_BUG_ON(sizeof(struct nvme_delete_queue) != 64);
38313843
BUILD_BUG_ON(IRQ_AFFINITY_MAX_SETS < 2);
3832-
BUILD_BUG_ON(NVME_MAX_SEGS > SGES_PER_PAGE);
3833-
BUILD_BUG_ON(sizeof(struct scatterlist) * NVME_MAX_SEGS > PAGE_SIZE);
38343844
BUILD_BUG_ON(nvme_pci_npages_prp() > NVME_MAX_NR_DESCRIPTORS);
38353845

38363846
return pci_register_driver(&nvme_driver);

0 commit comments

Comments
 (0)