All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] scsi_debug: Increase the reported optimal transfer length
@ 2015-12-16 22:53 Martin K. Petersen
  2015-12-16 22:53 ` [PATCH 2/3] sd: Reject optimal transfer length smaller than page size Martin K. Petersen
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Martin K. Petersen @ 2015-12-16 22:53 UTC (permalink / raw)
  To: linux-scsi, linux-block; +Cc: Martin K. Petersen

The OPTIMAL TRANSFER LENGTH reported by scsi_debug is 64 blocks which
translates to 32KB with the default logical block size. That's much
lower than what real storage devices typically report (256KB to 1MB).

Bump the optimal transfer length to 1024 blocks.

Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
---
 drivers/scsi/scsi_debug.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index d09d60293c27..b80b037f2982 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -129,7 +129,7 @@ static const char *scsi_debug_version_date = "20141022";
 #define DEF_NO_LUN_0   0
 #define DEF_NUM_PARTS   0
 #define DEF_OPTS   0
-#define DEF_OPT_BLKS 64
+#define DEF_OPT_BLKS 1024
 #define DEF_PHYSBLK_EXP 0
 #define DEF_PTYPE   0
 #define DEF_REMOVABLE false
@@ -4140,7 +4140,7 @@ MODULE_PARM_DESC(no_lun_0, "no LU number 0 (def=0 -> have lun 0)");
 MODULE_PARM_DESC(no_uld, "stop ULD (e.g. sd driver) attaching (def=0))");
 MODULE_PARM_DESC(num_parts, "number of partitions(def=0)");
 MODULE_PARM_DESC(num_tgts, "number of targets per host to simulate(def=1)");
-MODULE_PARM_DESC(opt_blks, "optimal transfer length in block (def=64)");
+MODULE_PARM_DESC(opt_blks, "optimal transfer length in blocks (def=1024)");
 MODULE_PARM_DESC(opts, "1->noise, 2->medium_err, 4->timeout, 8->recovered_err... (def=0)");
 MODULE_PARM_DESC(physblk_exp, "physical block exponent (def=0)");
 MODULE_PARM_DESC(ptype, "SCSI peripheral type(def=0[disk])");
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/3] sd: Reject optimal transfer length smaller than page size
  2015-12-16 22:53 [PATCH 1/3] scsi_debug: Increase the reported optimal transfer length Martin K. Petersen
@ 2015-12-16 22:53 ` Martin K. Petersen
  2015-12-17  0:55   ` Douglas Gilbert
  2015-12-17 13:19   ` Ewan Milne
  2015-12-16 22:53 ` [PATCH 3/3] block: Export max_dev_sectors_kb in sysfs Martin K. Petersen
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 9+ messages in thread
From: Martin K. Petersen @ 2015-12-16 22:53 UTC (permalink / raw)
  To: linux-scsi, linux-block; +Cc: Martin K. Petersen

Eryu Guan reported that loading scsi_debug would fail. This turned out
to be caused by scsi_debug reporting an optimal I/O size of 32KB which
is smaller than the 64KB page size on the PowerPC system in question.

Add a check to ensure that we only use the device-reported OPTIMAL
TRANSFER LENGTH if it is bigger than or equal to the page cache size.

Reported-by: Eryu Guan <guaneryu@gmail.com>
Reported-by: Ming Lei <tom.leiming@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
---
 drivers/scsi/sd.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 3d22fc3e3c1a..4e08d1cd704d 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -2885,10 +2885,13 @@ static int sd_revalidate_disk(struct gendisk *disk)
 
 	/*
 	 * Use the device's preferred I/O size for reads and writes
-	 * unless the reported value is unreasonably large (or garbage).
+	 * unless the reported value is unreasonably small, large, or
+	 * garbage.
 	 */
-	if (sdkp->opt_xfer_blocks && sdkp->opt_xfer_blocks <= dev_max &&
-	    sdkp->opt_xfer_blocks <= SD_DEF_XFER_BLOCKS)
+	if (sdkp->opt_xfer_blocks &&
+	    sdkp->opt_xfer_blocks <= dev_max &&
+	    sdkp->opt_xfer_blocks <= SD_DEF_XFER_BLOCKS &&
+	    sdkp->opt_xfer_blocks * sdp->sector_size >= PAGE_CACHE_SIZE)
 		rw_max = q->limits.io_opt =
 			logical_to_sectors(sdp, sdkp->opt_xfer_blocks);
 	else
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/3] block: Export max_dev_sectors_kb in sysfs
  2015-12-16 22:53 [PATCH 1/3] scsi_debug: Increase the reported optimal transfer length Martin K. Petersen
  2015-12-16 22:53 ` [PATCH 2/3] sd: Reject optimal transfer length smaller than page size Martin K. Petersen
@ 2015-12-16 22:53 ` Martin K. Petersen
  2015-12-17  4:03   ` Elliott, Robert (Persistent Memory)
  2015-12-17 13:27   ` Ewan Milne
  2015-12-16 23:14 ` [PATCH 1/3] scsi_debug: Increase the reported optimal transfer length Douglas Gilbert
  2015-12-17 13:18 ` Ewan Milne
  3 siblings, 2 replies; 9+ messages in thread
From: Martin K. Petersen @ 2015-12-16 22:53 UTC (permalink / raw)
  To: linux-scsi, linux-block; +Cc: Martin K. Petersen

Some storage devices report a maximum transfer length which indicates
the maximum size of an I/O request that the device can process. This
limit is enforced in combination with the controller's max_hw_sectors
and DMA constraints to ensure that we do not issue a command too big for
the device.

Export the max_dev_sectors_kb queue limit in sysfs and update the
documentation accordingly.

Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
---
 Documentation/ABI/testing/sysfs-block |  9 +++++++++
 Documentation/block/queue-sysfs.txt   | 11 +++++++++--
 block/blk-settings.c                  |  4 +++-
 block/blk-sysfs.c                     | 13 +++++++++++++
 4 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-block b/Documentation/ABI/testing/sysfs-block
index 71d184dbb70d..4f284d38c085 100644
--- a/Documentation/ABI/testing/sysfs-block
+++ b/Documentation/ABI/testing/sysfs-block
@@ -235,3 +235,12 @@ Description:
 		write_same_max_bytes is 0, write same is not supported
 		by the device.
 
+What:		/sys/block/<disk>/queue/max_dev_sectors_kb
+Date:		December 2015
+Contact:	Martin K. Petersen <martin.petersen@oracle.com>
+Description:
+		Some storage devices report the maximum size that the
+		device can process in a single READ or WRITE
+		request. This limit is used in combination with
+		constraints set by the controller driver to limit the
+		size of filesystem requests.
diff --git a/Documentation/block/queue-sysfs.txt b/Documentation/block/queue-sysfs.txt
index e5d914845be6..a078995f3eae 100644
--- a/Documentation/block/queue-sysfs.txt
+++ b/Documentation/block/queue-sysfs.txt
@@ -55,9 +55,15 @@ logical_block_size (RO)
 -----------------------
 This is the logcal block size of the device, in bytes.
 
+max_dev_sectors_kb (R)
+----------------------
+This is the maximum number of kilobytes supported by the storage device
+for a READ or WRITE request.
+
 max_hw_sectors_kb (RO)
 ----------------------
-This is the maximum number of kilobytes supported in a single data transfer.
+This is the maximum number of kilobytes supported by the storage
+controller in a single data transfer.
 
 max_integrity_segments (RO)
 ---------------------------
@@ -68,7 +74,8 @@ max_sectors_kb (RW)
 -------------------
 This is the maximum number of kilobytes that the block layer will allow
 for a filesystem request. Must be smaller than or equal to the maximum
-size allowed by the hardware.
+size allowed by the storage controller (max_hw_sectors_kb) and the
+maximum size allowed by the storage device (max_dev_sectors_kb).
 
 max_segments (RO)
 -----------------
diff --git a/block/blk-settings.c b/block/blk-settings.c
index dd4973583978..362b0179c86a 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -232,7 +232,9 @@ EXPORT_SYMBOL(blk_queue_bounce_limit);
  *    max_sectors is a soft limit imposed by the block layer for
  *    filesystem type requests.  This value can be overridden on a
  *    per-device basis in /sys/block/<device>/queue/max_sectors_kb.
- *    The soft limit can not exceed max_hw_sectors.
+ *
+ *    The soft limit's lower bound is the page cache size and it can not
+ *    exceed neither max_hw_sectors, nor max_dev_sectors.
  **/
 void blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_hw_sectors)
 {
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index e140cc487ce1..c289f9f6dcd9 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -225,6 +225,13 @@ static ssize_t queue_max_hw_sectors_show(struct request_queue *q, char *page)
 	return queue_var_show(max_hw_sectors_kb, (page));
 }
 
+static ssize_t queue_max_dev_sectors_show(struct request_queue *q, char *page)
+{
+	int max_dev_sectors_kb = q->limits.max_dev_sectors >> 1;
+
+	return queue_var_show(max_dev_sectors_kb, (page));
+}
+
 #define QUEUE_SYSFS_BIT_FNS(name, flag, neg)				\
 static ssize_t								\
 queue_show_##name(struct request_queue *q, char *page)			\
@@ -371,6 +378,11 @@ static struct queue_sysfs_entry queue_max_hw_sectors_entry = {
 	.show = queue_max_hw_sectors_show,
 };
 
+static struct queue_sysfs_entry queue_max_dev_sectors_entry = {
+	.attr = {.name = "max_dev_sectors_kb", .mode = S_IRUGO },
+	.show = queue_max_dev_sectors_show,
+};
+
 static struct queue_sysfs_entry queue_max_segments_entry = {
 	.attr = {.name = "max_segments", .mode = S_IRUGO },
 	.show = queue_max_segments_show,
@@ -483,6 +495,7 @@ static struct attribute *default_attrs[] = {
 	&queue_requests_entry.attr,
 	&queue_ra_entry.attr,
 	&queue_max_hw_sectors_entry.attr,
+	&queue_max_dev_sectors_entry.attr,
 	&queue_max_sectors_entry.attr,
 	&queue_max_segments_entry.attr,
 	&queue_max_integrity_segments_entry.attr,
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] scsi_debug: Increase the reported optimal transfer length
  2015-12-16 22:53 [PATCH 1/3] scsi_debug: Increase the reported optimal transfer length Martin K. Petersen
  2015-12-16 22:53 ` [PATCH 2/3] sd: Reject optimal transfer length smaller than page size Martin K. Petersen
  2015-12-16 22:53 ` [PATCH 3/3] block: Export max_dev_sectors_kb in sysfs Martin K. Petersen
@ 2015-12-16 23:14 ` Douglas Gilbert
  2015-12-17 13:18 ` Ewan Milne
  3 siblings, 0 replies; 9+ messages in thread
From: Douglas Gilbert @ 2015-12-16 23:14 UTC (permalink / raw)
  To: Martin K. Petersen, linux-scsi, linux-block

On 15-12-16 05:53 PM, Martin K. Petersen wrote:
> The OPTIMAL TRANSFER LENGTH reported by scsi_debug is 64 blocks which
> translates to 32KB with the default logical block size. That's much
> lower than what real storage devices typically report (256KB to 1MB).
>
> Bump the optimal transfer length to 1024 blocks.
>
> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

Acked-by: Douglas Gilbert <dgilbert@interlog.com>

> ---
>   drivers/scsi/scsi_debug.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
> index d09d60293c27..b80b037f2982 100644
> --- a/drivers/scsi/scsi_debug.c
> +++ b/drivers/scsi/scsi_debug.c
> @@ -129,7 +129,7 @@ static const char *scsi_debug_version_date = "20141022";
>   #define DEF_NO_LUN_0   0
>   #define DEF_NUM_PARTS   0
>   #define DEF_OPTS   0
> -#define DEF_OPT_BLKS 64
> +#define DEF_OPT_BLKS 1024
>   #define DEF_PHYSBLK_EXP 0
>   #define DEF_PTYPE   0
>   #define DEF_REMOVABLE false
> @@ -4140,7 +4140,7 @@ MODULE_PARM_DESC(no_lun_0, "no LU number 0 (def=0 -> have lun 0)");
>   MODULE_PARM_DESC(no_uld, "stop ULD (e.g. sd driver) attaching (def=0))");
>   MODULE_PARM_DESC(num_parts, "number of partitions(def=0)");
>   MODULE_PARM_DESC(num_tgts, "number of targets per host to simulate(def=1)");
> -MODULE_PARM_DESC(opt_blks, "optimal transfer length in block (def=64)");
> +MODULE_PARM_DESC(opt_blks, "optimal transfer length in blocks (def=1024)");
>   MODULE_PARM_DESC(opts, "1->noise, 2->medium_err, 4->timeout, 8->recovered_err... (def=0)");
>   MODULE_PARM_DESC(physblk_exp, "physical block exponent (def=0)");
>   MODULE_PARM_DESC(ptype, "SCSI peripheral type(def=0[disk])");
>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] sd: Reject optimal transfer length smaller than page size
  2015-12-16 22:53 ` [PATCH 2/3] sd: Reject optimal transfer length smaller than page size Martin K. Petersen
@ 2015-12-17  0:55   ` Douglas Gilbert
  2015-12-17 13:19   ` Ewan Milne
  1 sibling, 0 replies; 9+ messages in thread
From: Douglas Gilbert @ 2015-12-17  0:55 UTC (permalink / raw)
  To: Martin K. Petersen, linux-scsi, linux-block

On 15-12-16 05:53 PM, Martin K. Petersen wrote:
> Eryu Guan reported that loading scsi_debug would fail. This turned out
> to be caused by scsi_debug reporting an optimal I/O size of 32KB which
> is smaller than the 64KB page size on the PowerPC system in question.
>
> Add a check to ensure that we only use the device-reported OPTIMAL
> TRANSFER LENGTH if it is bigger than or equal to the page cache size.
>
> Reported-by: Eryu Guan <guaneryu@gmail.com>
> Reported-by: Ming Lei <tom.leiming@gmail.com>
> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
> ---
>   drivers/scsi/sd.c | 9 ++++++---
>   1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index 3d22fc3e3c1a..4e08d1cd704d 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
> @@ -2885,10 +2885,13 @@ static int sd_revalidate_disk(struct gendisk *disk)
>
>   	/*
>   	 * Use the device's preferred I/O size for reads and writes
> -	 * unless the reported value is unreasonably large (or garbage).
> +	 * unless the reported value is unreasonably small, large, or
> +	 * garbage.
>   	 */
> -	if (sdkp->opt_xfer_blocks && sdkp->opt_xfer_blocks <= dev_max &&
> -	    sdkp->opt_xfer_blocks <= SD_DEF_XFER_BLOCKS)
> +	if (sdkp->opt_xfer_blocks &&
> +	    sdkp->opt_xfer_blocks <= dev_max &&
> +	    sdkp->opt_xfer_blocks <= SD_DEF_XFER_BLOCKS &&
> +	    sdkp->opt_xfer_blocks * sdp->sector_size >= PAGE_CACHE_SIZE)
>   		rw_max = q->limits.io_opt =
>   			logical_to_sectors(sdp, sdkp->opt_xfer_blocks);
>   	else
>
and following that 'else' is:
                 rw_max = BLK_DEF_MAX_SECTORS;

and blkdev.h says:

enum blk_default_limits {
         BLK_MAX_SEGMENTS        = 128,
         BLK_SAFE_MAX_SECTORS    = 255,
         BLK_DEF_MAX_SECTORS     = 2560,
         BLK_MAX_SEGMENT_SIZE    = 65536,
         BLK_SEG_BOUNDARY_MASK   = 0xFFFFFFFFUL,
};


Reviewed-by: Douglas Gilbert <dgilbert@interlog.com>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [PATCH 3/3] block: Export max_dev_sectors_kb in sysfs
  2015-12-16 22:53 ` [PATCH 3/3] block: Export max_dev_sectors_kb in sysfs Martin K. Petersen
@ 2015-12-17  4:03   ` Elliott, Robert (Persistent Memory)
  2015-12-17 13:27   ` Ewan Milne
  1 sibling, 0 replies; 9+ messages in thread
From: Elliott, Robert (Persistent Memory) @ 2015-12-17  4:03 UTC (permalink / raw)
  To: Martin K. Petersen, linux-scsi, linux-block



> -----Original Message-----
> From: linux-block-owner@vger.kernel.org [mailto:linux-block-
> owner@vger.kernel.org] On Behalf Of Martin K. Petersen
> Sent: Wednesday, December 16, 2015 4:54 PM
> To: linux-scsi@vger.kernel.org; linux-block@vger.kernel.org
> Cc: Martin K. Petersen <martin.petersen@oracle.com>
> Subject: [PATCH 3/3] block: Export max_dev_sectors_kb in sysfs
> 
...
> diff --git a/Documentation/block/queue-sysfs.txt
...
> @@ -55,9 +55,15 @@ logical_block_size (RO)
>  -----------------------
>  This is the logcal block size of the device, in bytes.

Since you're in the vicinity, consider adding an i to logcal.
> 
> +max_dev_sectors_kb (R)
> +----------------------

The others use (RO) rather than just (R).

> +This is the maximum number of kilobytes supported by the storage
> +device for a READ or WRITE request.
> +
>  max_hw_sectors_kb (RO)
>  ----------------------
> -This is the maximum number of kilobytes supported in a single data transfer.
> +This is the maximum number of kilobytes supported by the storage
> +controller in a single data transfer.
...
> @@ -68,7 +74,8 @@ max_sectors_kb (RW)
>  -------------------
>  This is the maximum number of kilobytes that the block layer will allow
>  for a filesystem request. Must be smaller than or equal to the maximum
> -size allowed by the hardware.
> +size allowed by the storage controller (max_hw_sectors_kb) and the
> +maximum size allowed by the storage device (max_dev_sectors_kb).

Each one uses a different phrase:
* for a READ or WRITE request
* in a single data transfer
* for a filesystem request

Is some subtle difference being implied?


Since there are existing sysfs file with similar names, you're
stuck using _kb for the new one.  However, I suggest that the
Documentation at least mention these are really KiB, not kilobyte,
units.

---
Robert Elliott, HPE Persistent Memory



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] scsi_debug: Increase the reported optimal transfer length
  2015-12-16 22:53 [PATCH 1/3] scsi_debug: Increase the reported optimal transfer length Martin K. Petersen
                   ` (2 preceding siblings ...)
  2015-12-16 23:14 ` [PATCH 1/3] scsi_debug: Increase the reported optimal transfer length Douglas Gilbert
@ 2015-12-17 13:18 ` Ewan Milne
  3 siblings, 0 replies; 9+ messages in thread
From: Ewan Milne @ 2015-12-17 13:18 UTC (permalink / raw)
  To: Martin K. Petersen; +Cc: linux-scsi, linux-block

On Wed, 2015-12-16 at 17:53 -0500, Martin K. Petersen wrote:
> The OPTIMAL TRANSFER LENGTH reported by scsi_debug is 64 blocks which
> translates to 32KB with the default logical block size. That's much
> lower than what real storage devices typically report (256KB to 1MB).
> 
> Bump the optimal transfer length to 1024 blocks.
> 
> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
> ---
>  drivers/scsi/scsi_debug.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
> index d09d60293c27..b80b037f2982 100644
> --- a/drivers/scsi/scsi_debug.c
> +++ b/drivers/scsi/scsi_debug.c
> @@ -129,7 +129,7 @@ static const char *scsi_debug_version_date = "20141022";
>  #define DEF_NO_LUN_0   0
>  #define DEF_NUM_PARTS   0
>  #define DEF_OPTS   0
> -#define DEF_OPT_BLKS 64
> +#define DEF_OPT_BLKS 1024
>  #define DEF_PHYSBLK_EXP 0
>  #define DEF_PTYPE   0
>  #define DEF_REMOVABLE false
> @@ -4140,7 +4140,7 @@ MODULE_PARM_DESC(no_lun_0, "no LU number 0 (def=0 -> have lun 0)");
>  MODULE_PARM_DESC(no_uld, "stop ULD (e.g. sd driver) attaching (def=0))");
>  MODULE_PARM_DESC(num_parts, "number of partitions(def=0)");
>  MODULE_PARM_DESC(num_tgts, "number of targets per host to simulate(def=1)");
> -MODULE_PARM_DESC(opt_blks, "optimal transfer length in block (def=64)");
> +MODULE_PARM_DESC(opt_blks, "optimal transfer length in blocks (def=1024)");
>  MODULE_PARM_DESC(opts, "1->noise, 2->medium_err, 4->timeout, 8->recovered_err... (def=0)");
>  MODULE_PARM_DESC(physblk_exp, "physical block exponent (def=0)");
>  MODULE_PARM_DESC(ptype, "SCSI peripheral type(def=0[disk])");

Reviewed-by: Ewan D. Milne <emilne@redhat.com>



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] sd: Reject optimal transfer length smaller than page size
  2015-12-16 22:53 ` [PATCH 2/3] sd: Reject optimal transfer length smaller than page size Martin K. Petersen
  2015-12-17  0:55   ` Douglas Gilbert
@ 2015-12-17 13:19   ` Ewan Milne
  1 sibling, 0 replies; 9+ messages in thread
From: Ewan Milne @ 2015-12-17 13:19 UTC (permalink / raw)
  To: Martin K. Petersen; +Cc: linux-scsi, linux-block

On Wed, 2015-12-16 at 17:53 -0500, Martin K. Petersen wrote:
> Eryu Guan reported that loading scsi_debug would fail. This turned out
> to be caused by scsi_debug reporting an optimal I/O size of 32KB which
> is smaller than the 64KB page size on the PowerPC system in question.
> 
> Add a check to ensure that we only use the device-reported OPTIMAL
> TRANSFER LENGTH if it is bigger than or equal to the page cache size.
> 
> Reported-by: Eryu Guan <guaneryu@gmail.com>
> Reported-by: Ming Lei <tom.leiming@gmail.com>
> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
> ---
>  drivers/scsi/sd.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index 3d22fc3e3c1a..4e08d1cd704d 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
> @@ -2885,10 +2885,13 @@ static int sd_revalidate_disk(struct gendisk *disk)
>  
>  	/*
>  	 * Use the device's preferred I/O size for reads and writes
> -	 * unless the reported value is unreasonably large (or garbage).
> +	 * unless the reported value is unreasonably small, large, or
> +	 * garbage.
>  	 */
> -	if (sdkp->opt_xfer_blocks && sdkp->opt_xfer_blocks <= dev_max &&
> -	    sdkp->opt_xfer_blocks <= SD_DEF_XFER_BLOCKS)
> +	if (sdkp->opt_xfer_blocks &&
> +	    sdkp->opt_xfer_blocks <= dev_max &&
> +	    sdkp->opt_xfer_blocks <= SD_DEF_XFER_BLOCKS &&
> +	    sdkp->opt_xfer_blocks * sdp->sector_size >= PAGE_CACHE_SIZE)
>  		rw_max = q->limits.io_opt =
>  			logical_to_sectors(sdp, sdkp->opt_xfer_blocks);
>  	else

Reviewed-by: Ewan D. Milne <emilne@redhat.com>



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] block: Export max_dev_sectors_kb in sysfs
  2015-12-16 22:53 ` [PATCH 3/3] block: Export max_dev_sectors_kb in sysfs Martin K. Petersen
  2015-12-17  4:03   ` Elliott, Robert (Persistent Memory)
@ 2015-12-17 13:27   ` Ewan Milne
  1 sibling, 0 replies; 9+ messages in thread
From: Ewan Milne @ 2015-12-17 13:27 UTC (permalink / raw)
  To: Martin K. Petersen; +Cc: linux-scsi, linux-block

On Wed, 2015-12-16 at 17:53 -0500, Martin K. Petersen wrote:
> Some storage devices report a maximum transfer length which indicates
> the maximum size of an I/O request that the device can process. This
> limit is enforced in combination with the controller's max_hw_sectors
> and DMA constraints to ensure that we do not issue a command too big for
> the device.
> 
> Export the max_dev_sectors_kb queue limit in sysfs and update the
> documentation accordingly.
> 
> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
> ---
>  Documentation/ABI/testing/sysfs-block |  9 +++++++++
>  Documentation/block/queue-sysfs.txt   | 11 +++++++++--
>  block/blk-settings.c                  |  4 +++-
>  block/blk-sysfs.c                     | 13 +++++++++++++
>  4 files changed, 34 insertions(+), 3 deletions(-)
> 
> diff --git a/Documentation/ABI/testing/sysfs-block b/Documentation/ABI/testing/sysfs-block
> index 71d184dbb70d..4f284d38c085 100644
> --- a/Documentation/ABI/testing/sysfs-block
> +++ b/Documentation/ABI/testing/sysfs-block
> @@ -235,3 +235,12 @@ Description:
>  		write_same_max_bytes is 0, write same is not supported
>  		by the device.
>  
> +What:		/sys/block/<disk>/queue/max_dev_sectors_kb
> +Date:		December 2015
> +Contact:	Martin K. Petersen <martin.petersen@oracle.com>
> +Description:
> +		Some storage devices report the maximum size that the
> +		device can process in a single READ or WRITE
> +		request. This limit is used in combination with
> +		constraints set by the controller driver to limit the
> +		size of filesystem requests.
> diff --git a/Documentation/block/queue-sysfs.txt b/Documentation/block/queue-sysfs.txt
> index e5d914845be6..a078995f3eae 100644
> --- a/Documentation/block/queue-sysfs.txt
> +++ b/Documentation/block/queue-sysfs.txt
> @@ -55,9 +55,15 @@ logical_block_size (RO)
>  -----------------------
>  This is the logcal block size of the device, in bytes.
>  
> +max_dev_sectors_kb (R)
> +----------------------
> +This is the maximum number of kilobytes supported by the storage device
> +for a READ or WRITE request.
> +
>  max_hw_sectors_kb (RO)
>  ----------------------
> -This is the maximum number of kilobytes supported in a single data transfer.
> +This is the maximum number of kilobytes supported by the storage
> +controller in a single data transfer.
>  
>  max_integrity_segments (RO)
>  ---------------------------
> @@ -68,7 +74,8 @@ max_sectors_kb (RW)
>  -------------------
>  This is the maximum number of kilobytes that the block layer will allow
>  for a filesystem request. Must be smaller than or equal to the maximum
> -size allowed by the hardware.
> +size allowed by the storage controller (max_hw_sectors_kb) and the
> +maximum size allowed by the storage device (max_dev_sectors_kb).
>  
>  max_segments (RO)
>  -----------------
> diff --git a/block/blk-settings.c b/block/blk-settings.c
> index dd4973583978..362b0179c86a 100644
> --- a/block/blk-settings.c
> +++ b/block/blk-settings.c
> @@ -232,7 +232,9 @@ EXPORT_SYMBOL(blk_queue_bounce_limit);
>   *    max_sectors is a soft limit imposed by the block layer for
>   *    filesystem type requests.  This value can be overridden on a
>   *    per-device basis in /sys/block/<device>/queue/max_sectors_kb.
> - *    The soft limit can not exceed max_hw_sectors.
> + *
> + *    The soft limit's lower bound is the page cache size and it can not
> + *    exceed neither max_hw_sectors, nor max_dev_sectors.
>   **/
>  void blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_hw_sectors)
>  {
> diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
> index e140cc487ce1..c289f9f6dcd9 100644
> --- a/block/blk-sysfs.c
> +++ b/block/blk-sysfs.c
> @@ -225,6 +225,13 @@ static ssize_t queue_max_hw_sectors_show(struct request_queue *q, char *page)
>  	return queue_var_show(max_hw_sectors_kb, (page));
>  }
>  
> +static ssize_t queue_max_dev_sectors_show(struct request_queue *q, char *page)
> +{
> +	int max_dev_sectors_kb = q->limits.max_dev_sectors >> 1;

Consider adding inline queue_max_dev_sectors() to blkdev.h and using it
in the line above?

> +
> +	return queue_var_show(max_dev_sectors_kb, (page));
> +}
> +
>  #define QUEUE_SYSFS_BIT_FNS(name, flag, neg)				\
>  static ssize_t								\
>  queue_show_##name(struct request_queue *q, char *page)			\
> @@ -371,6 +378,11 @@ static struct queue_sysfs_entry queue_max_hw_sectors_entry = {
>  	.show = queue_max_hw_sectors_show,
>  };
>  
> +static struct queue_sysfs_entry queue_max_dev_sectors_entry = {
> +	.attr = {.name = "max_dev_sectors_kb", .mode = S_IRUGO },
> +	.show = queue_max_dev_sectors_show,
> +};
> +
>  static struct queue_sysfs_entry queue_max_segments_entry = {
>  	.attr = {.name = "max_segments", .mode = S_IRUGO },
>  	.show = queue_max_segments_show,
> @@ -483,6 +495,7 @@ static struct attribute *default_attrs[] = {
>  	&queue_requests_entry.attr,
>  	&queue_ra_entry.attr,
>  	&queue_max_hw_sectors_entry.attr,
> +	&queue_max_dev_sectors_entry.attr,
>  	&queue_max_sectors_entry.attr,
>  	&queue_max_segments_entry.attr,
>  	&queue_max_integrity_segments_entry.attr,

Reviewed-by: Ewan D. Milne <emilne@redhat.com>


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-12-17 13:27 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-16 22:53 [PATCH 1/3] scsi_debug: Increase the reported optimal transfer length Martin K. Petersen
2015-12-16 22:53 ` [PATCH 2/3] sd: Reject optimal transfer length smaller than page size Martin K. Petersen
2015-12-17  0:55   ` Douglas Gilbert
2015-12-17 13:19   ` Ewan Milne
2015-12-16 22:53 ` [PATCH 3/3] block: Export max_dev_sectors_kb in sysfs Martin K. Petersen
2015-12-17  4:03   ` Elliott, Robert (Persistent Memory)
2015-12-17 13:27   ` Ewan Milne
2015-12-16 23:14 ` [PATCH 1/3] scsi_debug: Increase the reported optimal transfer length Douglas Gilbert
2015-12-17 13:18 ` Ewan Milne

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.