All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block: Fix front merge check
@ 2016-07-13  5:23 Damien Le Moal
  2016-07-13  5:42 ` Hannes Reinecke
  2016-07-13 16:19 ` Jens Axboe
  0 siblings, 2 replies; 5+ messages in thread
From: Damien Le Moal @ 2016-07-13  5:23 UTC (permalink / raw)
  To: linux-block, axboe, hch, hare; +Cc: Damien Le Moal

For a front merge, the maximum number of sectors of the
request must be checked against the front merge BIO sector,
not the current sector of the request.

Signed-off-by: Damien Le Moal <damien.lemoal@hgst.com>
---
 block/blk-merge.c      | 6 +++---
 include/linux/blkdev.h | 5 +++--
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/block/blk-merge.c b/block/blk-merge.c
index 2613531..b736569 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -500,7 +500,7 @@ int ll_back_merge_fn(struct request_queue *q, struct request *req,
 	    integrity_req_gap_back_merge(req, bio))
 		return 0;
 	if (blk_rq_sectors(req) + bio_sectors(bio) >
-	    blk_rq_get_max_sectors(req)) {
+	    blk_rq_get_max_sectors(req, blk_rq_pos(req))) {
 		req->cmd_flags |= REQ_NOMERGE;
 		if (req == q->last_merge)
 			q->last_merge = NULL;
@@ -524,7 +524,7 @@ int ll_front_merge_fn(struct request_queue *q, struct request *req,
 	    integrity_req_gap_front_merge(req, bio))
 		return 0;
 	if (blk_rq_sectors(req) + bio_sectors(bio) >
-	    blk_rq_get_max_sectors(req)) {
+	    blk_rq_get_max_sectors(req, bio->bi_iter.bi_sector)) {
 		req->cmd_flags |= REQ_NOMERGE;
 		if (req == q->last_merge)
 			q->last_merge = NULL;
@@ -570,7 +570,7 @@ static int ll_merge_requests_fn(struct request_queue *q, struct request *req,
 	 * Will it become too large?
 	 */
 	if ((blk_rq_sectors(req) + blk_rq_sectors(next)) >
-	    blk_rq_get_max_sectors(req))
+	    blk_rq_get_max_sectors(req, blk_rq_pos(req)))
 		return 0;
 
 	total_phys_segments = req->nr_phys_segments + next->nr_phys_segments;
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 3d9cf32..b99ef36 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -904,7 +904,8 @@ static inline unsigned int blk_max_size_offset(struct request_queue *q,
 			(offset & (q->limits.chunk_sectors - 1));
 }
 
-static inline unsigned int blk_rq_get_max_sectors(struct request *rq)
+static inline unsigned int blk_rq_get_max_sectors(struct request *rq,
+						  sector_t offset)
 {
 	struct request_queue *q = rq->q;
 
@@ -914,7 +915,7 @@ static inline unsigned int blk_rq_get_max_sectors(struct request *rq)
 	if (!q->limits.chunk_sectors || (rq->cmd_flags & REQ_DISCARD))
 		return blk_queue_get_max_sectors(q, rq->cmd_flags);
 
-	return min(blk_max_size_offset(q, blk_rq_pos(rq)),
+	return min(blk_max_size_offset(q, offset),
 			blk_queue_get_max_sectors(q, rq->cmd_flags));
 }
 
-- 
2.7.4

Western Digital Corporation (and its subsidiaries) E-mail Confidentiality Notice & Disclaimer:

This e-mail and any files transmitted with it may contain confidential or legally privileged information of WDC and/or its affiliates, and are intended solely for the use of the individual or entity to which they are addressed. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited. If you have received this e-mail in error, please notify the sender immediately and delete the e-mail in its entirety from your system.


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

* Re: [PATCH] block: Fix front merge check
  2016-07-13  5:23 [PATCH] block: Fix front merge check Damien Le Moal
@ 2016-07-13  5:42 ` Hannes Reinecke
  2016-07-13 16:19 ` Jens Axboe
  1 sibling, 0 replies; 5+ messages in thread
From: Hannes Reinecke @ 2016-07-13  5:42 UTC (permalink / raw)
  To: Damien Le Moal, linux-block, axboe, hch

On 07/13/2016 07:23 AM, Damien Le Moal wrote:
> For a front merge, the maximum number of sectors of the
> request must be checked against the front merge BIO sector,
> not the current sector of the request.
> 
> Signed-off-by: Damien Le Moal <damien.lemoal@hgst.com>
> ---
>  block/blk-merge.c      | 6 +++---
>  include/linux/blkdev.h | 5 +++--
>  2 files changed, 6 insertions(+), 5 deletions(-)
> 
Reviewed-by: Hannes Reinecke <hare@suse.com>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		   Teamlead Storage & Networking
hare@suse.de			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N�rnberg
GF: F. Imend�rffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG N�rnberg)

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

* Re: [PATCH] block: Fix front merge check
  2016-07-13  5:23 [PATCH] block: Fix front merge check Damien Le Moal
  2016-07-13  5:42 ` Hannes Reinecke
@ 2016-07-13 16:19 ` Jens Axboe
  2016-07-14  1:23   ` Damien Le Moal
  1 sibling, 1 reply; 5+ messages in thread
From: Jens Axboe @ 2016-07-13 16:19 UTC (permalink / raw)
  To: Damien Le Moal, linux-block, hch, hare

On 07/12/2016 10:23 PM, Damien Le Moal wrote:
> For a front merge, the maximum number of sectors of the
> request must be checked against the front merge BIO sector,
> not the current sector of the request.

Why does this matter? The merging should only happen before we start the 
request, hence rq pos and first bio should be one and the same.

-- 
Jens Axboe


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

* Re: [PATCH] block: Fix front merge check
  2016-07-13 16:19 ` Jens Axboe
@ 2016-07-14  1:23   ` Damien Le Moal
  2016-07-21  3:38     ` Jens Axboe
  0 siblings, 1 reply; 5+ messages in thread
From: Damien Le Moal @ 2016-07-14  1:23 UTC (permalink / raw)
  To: Jens Axboe, linux-block, hch, hare


Jens,

On 7/14/16 01:19, Jens Axboe wrote:
> On 07/12/2016 10:23 PM, Damien Le Moal wrote:
>> For a front merge, the maximum number of sectors of the
>> request must be checked against the front merge BIO sector,
>> not the current sector of the request.
>
> Why does this matter? The merging should only happen before we start the
> request, hence rq pos and first bio should be one and the same.

The block device of SMR drives is set up as chunked with the chunk size 
equal to the drive zone size. Since write requests directed to 
sequential zones cannot cross zone boundaries, both the front merge code 
and the back merge code must ensure that requests resulting from a merge 
do not cross chunk boundaries.

The back merge code does this well, but the front merge code fails to 
prevent merging when the BIO is the last write in a zone and the request 
is the first write in the following (empty) zone. The check against the 
request LBA does not prevent the merge as the request+bio size fit in 
the empty zone. The check must be against the BIO LBA to detect the 
chunk boundary crossing.

Best regards.

-- 
Damien Le Moal, Ph.D.
Sr. Manager, System Software Group, HGST Research,
HGST, a Western Digital brand
Damien.LeMoal@hgst.com
(+81) 0466-98-3593 (ext. 513593)
1 kirihara-cho, Fujisawa,
Kanagawa, 252-0888 Japan
www.hgst.com
Western Digital Corporation (and its subsidiaries) E-mail Confidentiality Notice & Disclaimer:

This e-mail and any files transmitted with it may contain confidential or legally privileged information of WDC and/or its affiliates, and are intended solely for the use of the individual or entity to which they are addressed. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted to be taken in reliance on it, is prohibited. If you have received this e-mail in error, please notify the sender immediately and delete the e-mail in its entirety from your system.


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

* Re: [PATCH] block: Fix front merge check
  2016-07-14  1:23   ` Damien Le Moal
@ 2016-07-21  3:38     ` Jens Axboe
  0 siblings, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2016-07-21  3:38 UTC (permalink / raw)
  To: Damien Le Moal, Jens Axboe, linux-block, hch, hare



On 07/13/2016 07:23 PM, Damien Le Moal wrote:
>
> Jens,
>
> On 7/14/16 01:19, Jens Axboe wrote:
>> On 07/12/2016 10:23 PM, Damien Le Moal wrote:
>>> For a front merge, the maximum number of sectors of the
>>> request must be checked against the front merge BIO sector,
>>> not the current sector of the request.
>>
>> Why does this matter? The merging should only happen before we start the
>> request, hence rq pos and first bio should be one and the same.
>
> The block device of SMR drives is set up as chunked with the chunk size
> equal to the drive zone size. Since write requests directed to
> sequential zones cannot cross zone boundaries, both the front merge code
> and the back merge code must ensure that requests resulting from a merge
> do not cross chunk boundaries.
>
> The back merge code does this well, but the front merge code fails to
> prevent merging when the BIO is the last write in a zone and the request
> is the first write in the following (empty) zone. The check against the
> request LBA does not prevent the merge as the request+bio size fit in
> the empty zone. The check must be against the BIO LBA to detect the
> chunk boundary crossing.

Ah that makes sense, it's on adding the new bio, not against the 
existing rq->bio. Applied for 4.8.

-- 
Jens Axboe

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

end of thread, other threads:[~2016-07-21  3:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-13  5:23 [PATCH] block: Fix front merge check Damien Le Moal
2016-07-13  5:42 ` Hannes Reinecke
2016-07-13 16:19 ` Jens Axboe
2016-07-14  1:23   ` Damien Le Moal
2016-07-21  3:38     ` Jens Axboe

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.