* [PATCH V2] block: Disable write plugging for zoned block devices
@ 2019-07-10 15:54 Damien Le Moal
2019-07-10 15:57 ` Jens Axboe
0 siblings, 1 reply; 3+ messages in thread
From: Damien Le Moal @ 2019-07-10 15:54 UTC (permalink / raw)
To: linux-block, Jens Axboe; +Cc: Bart Van Assche
Simultaneously writing to a sequential zone of a zoned block device
from multiple contexts requires mutual exclusion for BIO issuing to
ensure that writes happen sequentially. However, even for a well
behaved user correctly implementing such synchronization, BIO plugging
may interfere and result in BIOs from the different contextx to be
reordered if plugging is done outside of the mutual exclusion section,
e.g. the plug was started by a function higher in the call chain than
the function issuing BIOs.
Context A Context B
| blk_start_plug()
| ...
| seq_write_zone()
| mutex_lock(zone)
| bio-0->bi_iter.bi_sector = zone->wp
| zone->wp += bio_sectors(bio-0)
| submit_bio(bio-0)
| bio-1->bi_iter.bi_sector = zone->wp
| zone->wp += bio_sectors(bio-1)
| submit_bio(bio-1)
| mutex_unlock(zone)
| return
| -----------------------> | seq_write_zone()
| mutex_lock(zone)
| bio-2->bi_iter.bi_sector = zone->wp
| zone->wp += bio_sectors(bio-2)
| submit_bio(bio-2)
| mutex_unlock(zone)
| <------------------------- |
| blk_finish_plug()
In the above example, despite the mutex synchronization ensuring the
correct BIO issuing order 0, 1, 2, context A BIOs 0 and 1 end up being
issued after BIO 2 of context B, when the plug is released with
blk_finish_plug().
While this problem can be addressed using the blk_flush_plug_list()
function (in the above example, the call must be inserted before the
zone mutex lock is released), a simple generic solution in the block
layer avoid this additional code in all zoned block device user code.
The simple generic solution implemented with this patch is to introduce
the internal helper function blk_mq_plug() to access the current
context plug on BIO submission. This helper returns the current plug
only if the target device is not a zoned block device or if the BIO to
be plugged is not a write operation. Otherwise, the caller context plug
is ignored and NULL returned, resulting is all writes to zoned block
device to never be plugged.
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
block/blk-core.c | 2 +-
block/blk-mq.c | 2 +-
block/blk-mq.h | 10 ++++++++++
3 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/block/blk-core.c b/block/blk-core.c
index 8340f69670d8..3957ea6811c3 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -645,7 +645,7 @@ bool blk_attempt_plug_merge(struct request_queue *q, struct bio *bio,
struct request *rq;
struct list_head *plug_list;
- plug = current->plug;
+ plug = blk_mq_plug(q, bio);
if (!plug)
return false;
diff --git a/block/blk-mq.c b/block/blk-mq.c
index ce0f5f4ede70..90be5bb6fa1b 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1969,7 +1969,7 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
cookie = request_to_qc_t(data.hctx, rq);
- plug = current->plug;
+ plug = blk_mq_plug(q, bio);
if (unlikely(is_flush_fua)) {
blk_mq_put_ctx(data.ctx);
blk_mq_bio_to_request(rq, bio);
diff --git a/block/blk-mq.h b/block/blk-mq.h
index 633a5a77ee8b..c9195a2cd670 100644
--- a/block/blk-mq.h
+++ b/block/blk-mq.h
@@ -238,4 +238,14 @@ static inline void blk_mq_clear_mq_map(struct blk_mq_queue_map *qmap)
qmap->mq_map[cpu] = 0;
}
+static inline struct blk_plug *blk_mq_plug(struct request_queue *q,
+ struct bio *bio)
+{
+ if (!blk_queue_is_zoned(q) || !op_is_write(bio_op(bio)))
+ return current->plug;
+
+ /* Zoned block device write case: do not plug the BIO */
+ return NULL;
+}
+
#endif
--
2.21.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH V2] block: Disable write plugging for zoned block devices
2019-07-10 15:54 [PATCH V2] block: Disable write plugging for zoned block devices Damien Le Moal
@ 2019-07-10 15:57 ` Jens Axboe
2019-07-10 16:37 ` Christoph Hellwig
0 siblings, 1 reply; 3+ messages in thread
From: Jens Axboe @ 2019-07-10 15:57 UTC (permalink / raw)
To: Damien Le Moal, linux-block; +Cc: Bart Van Assche
On 7/10/19 9:54 AM, Damien Le Moal wrote:
> diff --git a/block/blk-mq.h b/block/blk-mq.h
> index 633a5a77ee8b..c9195a2cd670 100644
> --- a/block/blk-mq.h
> +++ b/block/blk-mq.h
> @@ -238,4 +238,14 @@ static inline void blk_mq_clear_mq_map(struct blk_mq_queue_map *qmap)
> qmap->mq_map[cpu] = 0;
> }
>
> +static inline struct blk_plug *blk_mq_plug(struct request_queue *q,
> + struct bio *bio)
> +{
> + if (!blk_queue_is_zoned(q) || !op_is_write(bio_op(bio)))
> + return current->plug;
> +
> + /* Zoned block device write case: do not plug the BIO */
> + return NULL;
> +}
> +
> #endif
Folks are going to look at that and be puzzled, I think that function
deserves a comment.
--
Jens Axboe
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH V2] block: Disable write plugging for zoned block devices
2019-07-10 15:57 ` Jens Axboe
@ 2019-07-10 16:37 ` Christoph Hellwig
0 siblings, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2019-07-10 16:37 UTC (permalink / raw)
To: Jens Axboe; +Cc: Damien Le Moal, linux-block, Bart Van Assche
On Wed, Jul 10, 2019 at 09:57:05AM -0600, Jens Axboe wrote:
> On 7/10/19 9:54 AM, Damien Le Moal wrote:
> > diff --git a/block/blk-mq.h b/block/blk-mq.h
> > index 633a5a77ee8b..c9195a2cd670 100644
> > --- a/block/blk-mq.h
> > +++ b/block/blk-mq.h
> > @@ -238,4 +238,14 @@ static inline void blk_mq_clear_mq_map(struct blk_mq_queue_map *qmap)
> > qmap->mq_map[cpu] = 0;
> > }
> >
> > +static inline struct blk_plug *blk_mq_plug(struct request_queue *q,
> > + struct bio *bio)
> > +{
> > + if (!blk_queue_is_zoned(q) || !op_is_write(bio_op(bio)))
> > + return current->plug;
> > +
> > + /* Zoned block device write case: do not plug the BIO */
> > + return NULL;
> > +}
> > +
> > #endif
>
> Folks are going to look at that and be puzzled, I think that function
> deserves a comment.
Agreed. Also I'd reformat the conditionals to make the default
case more obvious:
if (blk_queue_is_zoned(q) && op_is_write(bio_op(bio)))
return NULL;
return current->plug;
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-07-10 16:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-10 15:54 [PATCH V2] block: Disable write plugging for zoned block devices Damien Le Moal
2019-07-10 15:57 ` Jens Axboe
2019-07-10 16:37 ` Christoph Hellwig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).