Skip to content

Commit 77082ca

Browse files
scsi: sd: Do not override max_sectors_kb sysfs setting
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. Cc: <stable@vger.kernel.org> 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>
1 parent 28a0bc4 commit 77082ca

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
@@ -3107,8 +3107,6 @@ static int sd_revalidate_disk(struct gendisk *disk)
31073107
sd_read_security(sdkp, buffer);
31083108
}
31093109

3110-
sdkp->first_scan = 0;
3111-
31123110
/*
31133111
* We now have all cache related info, determine how we deal
31143112
* with flush requests.
@@ -3123,7 +3121,7 @@ static int sd_revalidate_disk(struct gendisk *disk)
31233121
q->limits.max_dev_sectors = logical_to_sectors(sdp, dev_max);
31243122

31253123
/*
3126-
* Use the device's preferred I/O size for reads and writes
3124+
* Determine the device's preferred I/O size for reads and writes
31273125
* unless the reported value is unreasonably small, large, or
31283126
* garbage.
31293127
*/
@@ -3137,8 +3135,19 @@ static int sd_revalidate_disk(struct gendisk *disk)
31373135
rw_max = min_not_zero(logical_to_sectors(sdp, dev_max),
31383136
(sector_t)BLK_DEF_MAX_SECTORS);
31393137

3140-
/* Combine with controller limits */
3141-
q->limits.max_sectors = min(rw_max, queue_max_hw_sectors(q));
3138+
/* Do not exceed controller limit */
3139+
rw_max = min(rw_max, queue_max_hw_sectors(q));
3140+
3141+
/*
3142+
* Only update max_sectors if previously unset or if the current value
3143+
* exceeds the capabilities of the hardware.
3144+
*/
3145+
if (sdkp->first_scan ||
3146+
q->limits.max_sectors > q->limits.max_dev_sectors ||
3147+
q->limits.max_sectors > q->limits.max_hw_sectors)
3148+
q->limits.max_sectors = rw_max;
3149+
3150+
sdkp->first_scan = 0;
31423151

31433152
set_capacity(disk, logical_to_sectors(sdp, sdkp->capacity));
31443153
sd_config_write_same(sdkp);

0 commit comments

Comments
 (0)