All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V2 0/2] sd fixes and cleanup
@ 2017-09-01  1:07 Damien Le Moal
  2017-09-01  1:07 ` [PATCH V2 1/2] scsi: sd: Fix sd_config_write_same() Damien Le Moal
  2017-09-01  1:07 ` [PATCH V2 2/2] scsi: sd: Use sectors_to_logical() Damien Le Moal
  0 siblings, 2 replies; 6+ messages in thread
From: Damien Le Moal @ 2017-09-01  1:07 UTC (permalink / raw)
  To: linux-scsi, Martin K . Petersen
  Cc: Jens Axboe, Christoph Hellwig, Bart Van Assche

A couple of patches in this small series.

The first patch addresses a problem with large write same (or zeroout) block
layer calls being split into commands that are not aligned on the device
physical block size. This will work on regular disks but is not optimal.
The commands will however fail with host-managed zoned block device if the
commands target sequential write required zones. The patch simply makes sure
that the maximum write same sectors is aligned to physical block sizes.
This solution can be implemented here in sd_config_write_same() or in the block
layer (__blkdev_issue_write_same() and __blkdev_issue_write_zeroes()). Please
let me know if you prefer a block layer solution.

The second patch does not introduce functional changes.

As always, comments are welcome !

changes from V1:
* Removed useless addition of blank line an indentaion change in first patch.

Damien Le Moal (2):
  scsi: sd: Fix sd_config_write_same()
  scsi: sd: Use sectors_to_logical()

 drivers/scsi/sd.c | 37 +++++++++++++++++++++++++++++--------
 1 file changed, 29 insertions(+), 8 deletions(-)

-- 
2.13.5

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

* [PATCH V2 1/2] scsi: sd: Fix sd_config_write_same()
  2017-09-01  1:07 [PATCH V2 0/2] sd fixes and cleanup Damien Le Moal
@ 2017-09-01  1:07 ` Damien Le Moal
  2017-09-01  3:36   ` Martin K. Petersen
  2017-09-01  1:07 ` [PATCH V2 2/2] scsi: sd: Use sectors_to_logical() Damien Le Moal
  1 sibling, 1 reply; 6+ messages in thread
From: Damien Le Moal @ 2017-09-01  1:07 UTC (permalink / raw)
  To: linux-scsi, Martin K . Petersen
  Cc: Jens Axboe, Christoph Hellwig, Bart Van Assche

Reporting a maximum number of blocks that is not aligned on the device
physical size would cause a large write same request to be split into
physically unaligned chunks by __blkdev_issue_write_zeroes() and
__blkdev_issue_write_same(), even if the caller of these functions took
care to align its request to physical sectors.

So make sure the maximum reported is aligned to the device physical
block size. This is only an optional optimization for regular disks,
but this is mandatory to avoid failure of large write same requests
directed at sequential write required zones of host-managed ZBC disks.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 drivers/scsi/sd.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 6549e5ce09ca..e7d1eed4afa7 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -898,6 +898,27 @@ static void sd_config_write_same(struct scsi_disk *sdkp)
 	else
 		sdkp->zeroing_mode = SD_ZERO_WRITE;
 
+	if (sdkp->max_ws_blocks &&
+	    sdkp->physical_block_size > logical_block_size) {
+		/*
+		 * Reporting a maximum number of blocks that is not aligned
+		 * on the device physical size would cause a large write same
+		 * request to be split into physically unaligned chunks by
+		 * __blkdev_issue_write_zeroes() and __blkdev_issue_write_same()
+		 * even if the caller of these functions took care to align the
+		 * large request. So make sure the maximum reported is aligned
+		 * to the device physical block size. This is only an optional
+		 * optimization for regular disks, but this is mandatory to
+		 * avoid failure of large write same requests directed at
+		 * sequential write required zones of host-managed ZBC disks.
+		 */
+		sector_t phys_mask =
+			bytes_to_logical(sdkp->device,
+					 sdkp->physical_block_size) - 1;
+
+		sdkp->max_ws_blocks &= ~phys_mask;
+	}
+
 out:
 	blk_queue_max_write_same_sectors(q, sdkp->max_ws_blocks *
 					 (logical_block_size >> 9));
-- 
2.13.5

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

* [PATCH V2 2/2] scsi: sd: Use sectors_to_logical()
  2017-09-01  1:07 [PATCH V2 0/2] sd fixes and cleanup Damien Le Moal
  2017-09-01  1:07 ` [PATCH V2 1/2] scsi: sd: Fix sd_config_write_same() Damien Le Moal
@ 2017-09-01  1:07 ` Damien Le Moal
  2017-09-01  3:24   ` Martin K. Petersen
  1 sibling, 1 reply; 6+ messages in thread
From: Damien Le Moal @ 2017-09-01  1:07 UTC (permalink / raw)
  To: linux-scsi, Martin K . Petersen
  Cc: Jens Axboe, Christoph Hellwig, Bart Van Assche

Replace open coded conversions.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 drivers/scsi/sd.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index e7d1eed4afa7..84fab90fe2cb 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -738,8 +738,8 @@ static int sd_setup_unmap_cmnd(struct scsi_cmnd *cmd)
 {
 	struct scsi_device *sdp = cmd->device;
 	struct request *rq = cmd->request;
-	u64 sector = blk_rq_pos(rq) >> (ilog2(sdp->sector_size) - 9);
-	u32 nr_sectors = blk_rq_sectors(rq) >> (ilog2(sdp->sector_size) - 9);
+	u64 sector = sectors_to_logical(sdp, blk_rq_pos(rq));
+	u32 nr_sectors = sectors_to_logical(sdp, blk_rq_sectors(rq));
 	unsigned int data_len = 24;
 	char *buf;
 
@@ -772,8 +772,8 @@ static int sd_setup_write_same16_cmnd(struct scsi_cmnd *cmd, bool unmap)
 {
 	struct scsi_device *sdp = cmd->device;
 	struct request *rq = cmd->request;
-	u64 sector = blk_rq_pos(rq) >> (ilog2(sdp->sector_size) - 9);
-	u32 nr_sectors = blk_rq_sectors(rq) >> (ilog2(sdp->sector_size) - 9);
+	u64 sector = sectors_to_logical(sdp, blk_rq_pos(rq));
+	u32 nr_sectors = sectors_to_logical(sdp, blk_rq_sectors(rq));
 	u32 data_len = sdp->sector_size;
 
 	rq->special_vec.bv_page = alloc_page(GFP_ATOMIC | __GFP_ZERO);
@@ -802,8 +802,8 @@ static int sd_setup_write_same10_cmnd(struct scsi_cmnd *cmd, bool unmap)
 {
 	struct scsi_device *sdp = cmd->device;
 	struct request *rq = cmd->request;
-	u64 sector = blk_rq_pos(rq) >> (ilog2(sdp->sector_size) - 9);
-	u32 nr_sectors = blk_rq_sectors(rq) >> (ilog2(sdp->sector_size) - 9);
+	u64 sector = sectors_to_logical(sdp, blk_rq_pos(rq));
+	u32 nr_sectors = sectors_to_logical(sdp, blk_rq_sectors(rq));
 	u32 data_len = sdp->sector_size;
 
 	rq->special_vec.bv_page = alloc_page(GFP_ATOMIC | __GFP_ZERO);
@@ -833,8 +833,8 @@ static int sd_setup_write_zeroes_cmnd(struct scsi_cmnd *cmd)
 	struct request *rq = cmd->request;
 	struct scsi_device *sdp = cmd->device;
 	struct scsi_disk *sdkp = scsi_disk(rq->rq_disk);
-	u64 sector = blk_rq_pos(rq) >> (ilog2(sdp->sector_size) - 9);
-	u32 nr_sectors = blk_rq_sectors(rq) >> (ilog2(sdp->sector_size) - 9);
+	u64 sector = sectors_to_logical(sdp, blk_rq_pos(rq));
+	u32 nr_sectors = sectors_to_logical(sdp, blk_rq_sectors(rq));
 	int ret;
 
 	if (!(rq->cmd_flags & REQ_NOUNMAP)) {
-- 
2.13.5

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

* Re: [PATCH V2 2/2] scsi: sd: Use sectors_to_logical()
  2017-09-01  1:07 ` [PATCH V2 2/2] scsi: sd: Use sectors_to_logical() Damien Le Moal
@ 2017-09-01  3:24   ` Martin K. Petersen
  0 siblings, 0 replies; 6+ messages in thread
From: Martin K. Petersen @ 2017-09-01  3:24 UTC (permalink / raw)
  To: Damien Le Moal
  Cc: linux-scsi, Martin K . Petersen, Jens Axboe, Christoph Hellwig,
	Bart Van Assche


Damien,

> Replace open coded conversions.

I have a pending sd.c cleanup that already does this. I may slip your
patch in and rework my series on top of it. We'll see.

-- 
Martin K. Petersen	Oracle Linux Engineering

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

* Re: [PATCH V2 1/2] scsi: sd: Fix sd_config_write_same()
  2017-09-01  1:07 ` [PATCH V2 1/2] scsi: sd: Fix sd_config_write_same() Damien Le Moal
@ 2017-09-01  3:36   ` Martin K. Petersen
  2017-09-01  8:45     ` Damien Le Moal
  0 siblings, 1 reply; 6+ messages in thread
From: Martin K. Petersen @ 2017-09-01  3:36 UTC (permalink / raw)
  To: Damien Le Moal
  Cc: linux-scsi, Martin K . Petersen, Jens Axboe, Christoph Hellwig,
	Bart Van Assche


Damien,

> +	if (sdkp->max_ws_blocks &&
> +	    sdkp->physical_block_size > logical_block_size) {
> +		/*
> +		 * Reporting a maximum number of blocks that is not aligned
> +		 * on the device physical size would cause a large write same
> +		 * request to be split into physically unaligned chunks by
> +		 * __blkdev_issue_write_zeroes() and __blkdev_issue_write_same()
> +		 * even if the caller of these functions took care to align the
> +		 * large request. So make sure the maximum reported is aligned
> +		 * to the device physical block size. This is only an optional
> +		 * optimization for regular disks, but this is mandatory to
> +		 * avoid failure of large write same requests directed at
> +		 * sequential write required zones of host-managed ZBC disks.
> +		 */
> +		sector_t phys_mask =
> +			bytes_to_logical(sdkp->device,
> +					 sdkp->physical_block_size) - 1;
> +
> +		sdkp->max_ws_blocks &= ~phys_mask;
> +	}
> +
>  out:
>  	blk_queue_max_write_same_sectors(q, sdkp->max_ws_blocks *
>  					 (logical_block_size >> 9));

ALIGN_DOWN(sdkp->max_ws_blocks, sdkp->physical_block_size)?

-- 
Martin K. Petersen	Oracle Linux Engineering

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

* Re: [PATCH V2 1/2] scsi: sd: Fix sd_config_write_same()
  2017-09-01  3:36   ` Martin K. Petersen
@ 2017-09-01  8:45     ` Damien Le Moal
  0 siblings, 0 replies; 6+ messages in thread
From: Damien Le Moal @ 2017-09-01  8:45 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: linux-scsi, Jens Axboe, Christoph Hellwig, Bart Van Assche

Martin,

On 9/1/17 12:36, Martin K. Petersen wrote:
> 
> Damien,
> 
>> +	if (sdkp->max_ws_blocks &&
>> +	    sdkp->physical_block_size > logical_block_size) {
>> +		/*
>> +		 * Reporting a maximum number of blocks that is not aligned
>> +		 * on the device physical size would cause a large write same
>> +		 * request to be split into physically unaligned chunks by
>> +		 * __blkdev_issue_write_zeroes() and __blkdev_issue_write_same()
>> +		 * even if the caller of these functions took care to align the
>> +		 * large request. So make sure the maximum reported is aligned
>> +		 * to the device physical block size. This is only an optional
>> +		 * optimization for regular disks, but this is mandatory to
>> +		 * avoid failure of large write same requests directed at
>> +		 * sequential write required zones of host-managed ZBC disks.
>> +		 */
>> +		sector_t phys_mask =
>> +			bytes_to_logical(sdkp->device,
>> +					 sdkp->physical_block_size) - 1;
>> +
>> +		sdkp->max_ws_blocks &= ~phys_mask;
>> +	}
>> +
>>  out:
>>  	blk_queue_max_write_same_sectors(q, sdkp->max_ws_blocks *
>>  					 (logical_block_size >> 9));
> 
> ALIGN_DOWN(sdkp->max_ws_blocks, sdkp->physical_block_size)?

Sure. But let's use the same unit then :)

sdkp->max_ws_blocks =
	ALIGN_DOWN(sdkp->max_ws_blocks,
	   bytes_to_logical(sdkp->device, sdkp->physical_block_size));

Isn't it ?

Do you want me to resend ?

Thank you.

-- 
Damien Le Moal,
Western Digital

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

end of thread, other threads:[~2017-09-01  8:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-01  1:07 [PATCH V2 0/2] sd fixes and cleanup Damien Le Moal
2017-09-01  1:07 ` [PATCH V2 1/2] scsi: sd: Fix sd_config_write_same() Damien Le Moal
2017-09-01  3:36   ` Martin K. Petersen
2017-09-01  8:45     ` Damien Le Moal
2017-09-01  1:07 ` [PATCH V2 2/2] scsi: sd: Use sectors_to_logical() Damien Le Moal
2017-09-01  3:24   ` Martin K. Petersen

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.