Skip to content

Commit fbd3681

Browse files
SergeyGorenkojgunthorpe
authored andcommitted
IB/srp: Use the IB_DEVICE_SG_GAPS_REG HCA feature if supported
If a HCA supports the SG_GAPS_REG feature then fewer memory regions are required per command. This patch reduces the number of memory regions that is allocated per SRP session. Signed-off-by: Sergey Gorenko <[email protected]> Reviewed-by: Max Gurtovoy <[email protected]> Tested-by: Laurence Oberman <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]> Acked-by: Bart Van Assche <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 4190443 commit fbd3681

File tree

1 file changed

+36
-20
lines changed

1 file changed

+36
-20
lines changed

drivers/infiniband/ulp/srp/ib_srp.c

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ static struct srp_fr_pool *srp_create_fr_pool(struct ib_device *device,
431431
struct srp_fr_desc *d;
432432
struct ib_mr *mr;
433433
int i, ret = -EINVAL;
434+
enum ib_mr_type mr_type;
434435

435436
if (pool_size <= 0)
436437
goto err;
@@ -444,9 +445,13 @@ static struct srp_fr_pool *srp_create_fr_pool(struct ib_device *device,
444445
spin_lock_init(&pool->lock);
445446
INIT_LIST_HEAD(&pool->free_list);
446447

448+
if (device->attrs.device_cap_flags & IB_DEVICE_SG_GAPS_REG)
449+
mr_type = IB_MR_TYPE_SG_GAPS;
450+
else
451+
mr_type = IB_MR_TYPE_MEM_REG;
452+
447453
for (i = 0, d = &pool->desc[0]; i < pool->size; i++, d++) {
448-
mr = ib_alloc_mr(pd, IB_MR_TYPE_MEM_REG,
449-
max_page_list_len);
454+
mr = ib_alloc_mr(pd, mr_type, max_page_list_len);
450455
if (IS_ERR(mr)) {
451456
ret = PTR_ERR(mr);
452457
if (ret == -ENOMEM)
@@ -2996,8 +3001,9 @@ static int srp_slave_alloc(struct scsi_device *sdev)
29963001
struct Scsi_Host *shost = sdev->host;
29973002
struct srp_target_port *target = host_to_target(shost);
29983003
struct srp_device *srp_dev = target->srp_host->srp_dev;
3004+
struct ib_device *ibdev = srp_dev->dev;
29993005

3000-
if (true)
3006+
if (!(ibdev->attrs.device_cap_flags & IB_DEVICE_SG_GAPS_REG))
30013007
blk_queue_virt_boundary(sdev->request_queue,
30023008
~srp_dev->mr_page_mask);
30033009

@@ -3775,26 +3781,36 @@ static ssize_t srp_create_target(struct device *dev,
37753781
}
37763782

37773783
if (srp_dev->use_fast_reg || srp_dev->use_fmr) {
3778-
/*
3779-
* FR and FMR can only map one HCA page per entry. If the
3780-
* start address is not aligned on a HCA page boundary two
3781-
* entries will be used for the head and the tail although
3782-
* these two entries combined contain at most one HCA page of
3783-
* data. Hence the "+ 1" in the calculation below.
3784-
*
3785-
* The indirect data buffer descriptor is contiguous so the
3786-
* memory for that buffer will only be registered if
3787-
* register_always is true. Hence add one to mr_per_cmd if
3788-
* register_always has been set.
3789-
*/
3784+
bool gaps_reg = (ibdev->attrs.device_cap_flags &
3785+
IB_DEVICE_SG_GAPS_REG);
3786+
37903787
max_sectors_per_mr = srp_dev->max_pages_per_mr <<
37913788
(ilog2(srp_dev->mr_page_size) - 9);
3792-
mr_per_cmd = register_always +
3793-
(target->scsi_host->max_sectors + 1 +
3794-
max_sectors_per_mr - 1) / max_sectors_per_mr;
3789+
if (!gaps_reg) {
3790+
/*
3791+
* FR and FMR can only map one HCA page per entry. If
3792+
* the start address is not aligned on a HCA page
3793+
* boundary two entries will be used for the head and
3794+
* the tail although these two entries combined
3795+
* contain at most one HCA page of data. Hence the "+
3796+
* 1" in the calculation below.
3797+
*
3798+
* The indirect data buffer descriptor is contiguous
3799+
* so the memory for that buffer will only be
3800+
* registered if register_always is true. Hence add
3801+
* one to mr_per_cmd if register_always has been set.
3802+
*/
3803+
mr_per_cmd = register_always +
3804+
(target->scsi_host->max_sectors + 1 +
3805+
max_sectors_per_mr - 1) / max_sectors_per_mr;
3806+
} else {
3807+
mr_per_cmd = register_always +
3808+
(target->sg_tablesize +
3809+
srp_dev->max_pages_per_mr - 1) /
3810+
srp_dev->max_pages_per_mr;
3811+
}
37953812
pr_debug("max_sectors = %u; max_pages_per_mr = %u; mr_page_size = %u; max_sectors_per_mr = %u; mr_per_cmd = %u\n",
3796-
target->scsi_host->max_sectors,
3797-
srp_dev->max_pages_per_mr, srp_dev->mr_page_size,
3813+
target->scsi_host->max_sectors, srp_dev->max_pages_per_mr, srp_dev->mr_page_size,
37983814
max_sectors_per_mr, mr_per_cmd);
37993815
}
38003816

0 commit comments

Comments
 (0)