Skip to content

Commit 9e78ac8

Browse files
martinkpetersengregkh
authored andcommitted
scsi: sd: Do not override max_sectors_kb sysfs setting
commit 77082ca503bed061f7fbda7cfd7c93beda967a41 upstream. A user may lower the max_sectors_kb setting in sysfs to accommodate certain workloads. Previously we would always set the max I/O size to either the block layer default or the optional preferred I/O size reported by the device. Keep the current heuristics for the initial setting of max_sectors_kb. For subsequent invocations, only update the current queue limit if it exceeds the capabilities of the hardware. Reported-by: Don Brace <don.brace@microsemi.com> Reviewed-by: Martin Wilck <mwilck@suse.com> Tested-by: Don Brace <don.brace@microsemi.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent fc29713 commit 9e78ac8

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

drivers/scsi/sd.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2878,8 +2878,6 @@ static int sd_revalidate_disk(struct gendisk *disk)
28782878
sd_read_write_same(sdkp, buffer);
28792879
}
28802880

2881-
sdkp->first_scan = 0;
2882-
28832881
/*
28842882
* We now have all cache related info, determine how we deal
28852883
* with flush requests.
@@ -2894,7 +2892,7 @@ static int sd_revalidate_disk(struct gendisk *disk)
28942892
q->limits.max_dev_sectors = logical_to_sectors(sdp, dev_max);
28952893

28962894
/*
2897-
* Use the device's preferred I/O size for reads and writes
2895+
* Determine the device's preferred I/O size for reads and writes
28982896
* unless the reported value is unreasonably small, large, or
28992897
* garbage.
29002898
*/
@@ -2908,8 +2906,19 @@ static int sd_revalidate_disk(struct gendisk *disk)
29082906
rw_max = min_not_zero(logical_to_sectors(sdp, dev_max),
29092907
(sector_t)BLK_DEF_MAX_SECTORS);
29102908

2911-
/* Combine with controller limits */
2912-
q->limits.max_sectors = min(rw_max, queue_max_hw_sectors(q));
2909+
/* Do not exceed controller limit */
2910+
rw_max = min(rw_max, queue_max_hw_sectors(q));
2911+
2912+
/*
2913+
* Only update max_sectors if previously unset or if the current value
2914+
* exceeds the capabilities of the hardware.
2915+
*/
2916+
if (sdkp->first_scan ||
2917+
q->limits.max_sectors > q->limits.max_dev_sectors ||
2918+
q->limits.max_sectors > q->limits.max_hw_sectors)
2919+
q->limits.max_sectors = rw_max;
2920+
2921+
sdkp->first_scan = 0;
29132922

29142923
set_capacity(disk, logical_to_sectors(sdp, sdkp->capacity));
29152924
sd_config_write_same(sdkp);

0 commit comments

Comments
 (0)