Improve I/O priority support in mq-deadline for zoned writes
v2 cover Improve I/O priority support in mq-deadline for zoned writes
Hi Jens,
This patch series prevents that the mq-deadline I/O scheduler submits zoned writes out of order if different writes for the same zone have different I/O priorities. Please consider these patches for the next merge window.
Thanks,
Bart.
Changes compared to v1:
- Changed the approach from ignoring the I/O priority of zoned writes to using the I/O priority of pending zoned writes.
- Included two unit tests.
Bart Van Assche (4):
block/mq-deadline: Rename dd_rq_ioclass() and change its return type block/mq-deadline: Introduce dd_bio_ioclass() block/mq-deadline: Introduce deadline_first_rq_past_pos() block/mq-deadline: Prevent zoned write reordering due to I/O
prioritization
block/Kconfig.iosched | 5 ++ block/mq-deadline.c | 135 +++++++++++++++++++++++------- block/mq-deadline_test.c | 175 +++++++++++++++++++++++++++++++++++++++ include/linux/blk-mq.h | 17 ++++ 4 files changed, 300 insertions(+), 32 deletions(-) create mode 100644 block/mq-deadline_test.c
PATCH v2 1/4 block/mq-deadline: Rename dd_rq_ioclass() and change its return type
All dd_rq_ioclass() callers convert the return value into type enum dd_prio. Move this conversion into dd_rq_ioclass() and rename this function. Move the definition of this function. Introduce an additional caller. No functionality is changed by this patch.
--- block/mq-deadline.c | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-)
block/mq-deadline.c +14 -21
@@ -119,15 +119,6 @@ deadline_rb_root(struct dd_per_prio *per_prio, struct request *rq)return &per_prio->sort_list[rq_data_dir (rq)]; } -/* -* Returns the I/O priority class (IOPRIO_CLASS_*) that has been assigned to a -* request. -*/ -static u8 dd_rq_ioclass (struct request *rq) -{ -return IOPRIO_PRIO_CLASS (req_get_ioprio (rq)); -} -/* * get the request before `rq' in sector-sorted order */
@@ -190,6 +181,15 @@ static inline struct request *deadline_from_pos(struct dd_per_prio *per_prio,return res; } +/* +* Returns the I/O priority class (IOPRIO_CLASS_*) that has been assigned to a +* request. +*/ +static enum dd_prio dd_rq_ioprio (struct request *rq) +{ +return ioprio_class_to_prio[IOPRIO_PRIO_CLASS (req_get_ioprio (rq))]; +} +static void deadline_add_rq_rb (struct dd_per_prio *per_prio,struct request *rq) {
@@ -228,8 +228,7 @@ static void dd_request_merged(struct request_queue *q, struct request *req, enum elv_merge type) {struct deadline_data *dd = q->elevator->elevator_data; -const u8 ioprio_class =dd_rq_ioclass (req); -const enum dd_prio prio = ioprio_class_to_prio[ioprio_class]; +const enum dd_prio prio =dd_rq_ioprio (req);struct dd_per_prio *per_prio = &dd->per_prio[prio];/*
@@ -248,8 +247,7 @@ static void dd_merged_requests(struct request_queue *q, struct request *req, struct request *next) {struct deadline_data *dd = q->elevator->elevator_data; -const u8 ioprio_class =dd_rq_ioclass (next); -const enum dd_prio prio = ioprio_class_to_prio[ioprio_class]; +const enum dd_prio prio =dd_rq_ioprio (next);lockdep_assert_held (&dd->lock);
@@ -447,7 +445,6 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd,struct request *rq, *next_rq;enum dd_data_dir data_dir;enum dd_prio prio; -u8 ioprio_class;lockdep_assert_held (&dd->lock);
@@ -545,8 +542,7 @@ static struct request *__dd_dispatch_request(struct deadline_data *dd, dd->batching++;deadline_move_request (dd, per_prio, rq); done: - ioprio_class =dd_rq_ioclass (rq); - prio = ioprio_class_to_prio[ioprio_class]; + prio =dd_rq_ioprio (rq); dd->per_prio[prio].latest_pos[data_dir] =blk_rq_pos (rq); dd->per_prio[prio].stats.dispatched++;/*
@@ -798,8 +794,6 @@ static void dd_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,struct request_queue *q = hctx->queue;struct deadline_data *dd = q->elevator->elevator_data;const enum dd_data_dir data_dir =rq_data_dir (rq); -u16 ioprio =req_get_ioprio (rq); -u8 ioprio_class =IOPRIO_PRIO_CLASS (ioprio);struct dd_per_prio *per_prio;enum dd_prio prio;
@@ -811,7 +805,7 @@ static void dd_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,*/ blk_req_zone_write_unlock (rq); - prio = ioprio_class_to_prio[ioprio_class]; + prio =dd_rq_ioprio (rq); per_prio = &dd->per_prio[prio];if (!rq->elv.priv[0 ]) { per_prio->stats.inserted++;
@@ -920,8 +914,7 @@ static void dd_finish_request(struct request *rq) {struct request_queue *q = rq->q;struct deadline_data *dd = q->elevator->elevator_data; -const u8 ioprio_class =dd_rq_ioclass (rq); -const enum dd_prio prio = ioprio_class_to_prio[ioprio_class]; +const enum dd_prio prio =dd_rq_ioprio (rq);struct dd_per_prio *per_prio = &dd->per_prio[prio];/*
PATCH v2 2/4 block/mq-deadline: Introduce dd_bio_ioclass()
In reply to Bart Van AsschePrepare for ignoring the I/O priority of certain requests.
--- block/mq-deadline.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
block/mq-deadline.c +6 -2
@@ -190,6 +190,11 @@ static enum dd_prio dd_rq_ioprio(struct request *rq)return ioprio_class_to_prio[IOPRIO_PRIO_CLASS (req_get_ioprio (rq))]; } +static enum dd_prio dd_bio_ioprio (struct bio *bio) +{ +return ioprio_class_to_prio[IOPRIO_PRIO_CLASS (bio->bi_ioprio)]; +} +static void deadline_add_rq_rb (struct dd_per_prio *per_prio,struct request *rq) {
@@ -740,8 +745,7 @@ static int dd_request_merge(struct request_queue *q, struct request **rq, struct bio *bio) {struct deadline_data *dd = q->elevator->elevator_data; -const u8 ioprio_class =IOPRIO_PRIO_CLASS (bio->bi_ioprio); -const enum dd_prio prio = ioprio_class_to_prio[ioprio_class]; +const enum dd_prio prio =dd_bio_ioprio (bio);struct dd_per_prio *per_prio = &dd->per_prio[prio];sector_t sector =bio_end_sector (bio);struct request *__rq;
PATCH v2 3/4 block/mq-deadline: Introduce deadline_first_rq_past_pos()
In reply to Bart Van AsschePrepare for introducing a second caller.
--- block/mq-deadline.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-)
block/mq-deadline.c +24 -11
@@ -147,6 +147,28 @@ deadline_latter_request(struct request *rq)return NULL ; } +/* +* Return the first request with the given priority, data direction and for +* which blk_rq_pos() >= @pos. +*/ +static struct request *deadline_first_rq_past_pos (struct dd_per_prio *per_prio, +enum dd_data_dir data_dir,sector_t pos) +{ +struct rb_node *node = per_prio->sort_list[data_dir].rb_node; +struct request *rq, *res =NULL ; + +while (node) { + rq =rb_entry_rq (node); +if (blk_rq_pos (rq) >= pos) { + res = rq; + node = node->rb_left; + }else { + node = node->rb_right; + } + } +return res; +} +/* * Return the first request for which blk_rq_pos() >= @pos. For zoned devices, * return the first request after the start of the zone containing @pos.
@@ -155,7 +177,7 @@ static inline struct request *deadline_from_pos(struct dd_per_prio *per_prio, enum dd_data_dir data_dir, sector_t pos) {struct rb_node *node = per_prio->sort_list[data_dir].rb_node; -struct request *rq, *res =NULL ; +struct request *rq;if (!node)return NULL ;
@@ -169,16 +191,7 @@ static inline struct request *deadline_from_pos(struct dd_per_prio *per_prio,if (blk_rq_is_seq_zoned_write (rq)) pos =round_down (pos, rq->q->limits.chunk_sectors); -while (node) { - rq =rb_entry_rq (node); -if (blk_rq_pos (rq) >= pos) { - res = rq; - node = node->rb_left; - }else { - node = node->rb_right; - } - } -return res; +return deadline_first_rq_past_pos (per_prio, data_dir, pos); }/*
PATCH v2 4/4 block/mq-deadline: Prevent zoned write reordering due to I/O prioritization
In reply to Bart Van AsscheAssigning I/O priorities with the ioprio cgroup policy may cause different I/O priorities to be assigned to write requests for the same zone. Prevent that this causes unaligned write errors by adding zoned writes for the same zone in the same priority queue as prior zoned writes.
--- block/Kconfig.iosched | 5 ++ block/mq-deadline.c | 81 +++++++++++++++--- block/mq-deadline_test.c | 175 +++++++++++++++++++++++++++++++++++++++ include/linux/blk-mq.h | 17 ++++ 4 files changed, 268 insertions(+), 10 deletions(-) create mode 100644 block/mq-deadline_test.c
block/Kconfig.iosched +5 -0
@@ -7,6 +7,11 @@ config MQ_IOSCHED_DEADLINE help MQ version of the deadline IO scheduler. +config MQ_IOSCHED_DEADLINE_TEST + tristate "MQ deadline unit tests" if !KUNIT_ALL_TESTS + depends on MQ_IOSCHED_DEADLINE && KUNIT + default KUNIT_ALL_TESTS + config MQ_IOSCHED_KYBER tristate "Kyber I/O scheduler" default y
block/mq-deadline.c +71 -10
149 lines not on this page · raw message
block/mq-deadline_test.c new file +175 -0
175 lines not on this page · raw message
include/linux/blk-mq.h +17 -0
@@ -1149,6 +1149,18 @@ static inline unsigned int blk_rq_zone_no(struct request *rq)return disk_zone_no (rq->q->disk,blk_rq_pos (rq)); } +/** +* blk_bio_is_seq_zoned_write() - Check if @bio requires write serialization. +* @bio: Bio to examine. +* +* Note: REQ_OP_ZONE_APPEND bios do not require serialization. +*/ +static inline bool blk_bio_is_seq_zoned_write (struct bio *bio) +{ +return disk_zone_is_seq (bio->bi_bdev->bd_disk, bio->bi_iter.bi_sector) && +op_needs_zoned_write_locking (bio_op (bio)); +} +static inline unsigned int blk_rq_zone_is_seq (struct request *rq) {return disk_zone_is_seq (rq->q->disk,blk_rq_pos (rq));
@@ -1196,6 +1208,11 @@ static inline bool blk_req_can_dispatch_to_zone(struct request *rq) return !blk_req_zone_is_write_locked(rq); }#else /* CONFIG_BLK_DEV_ZONED */ +static inline bool blk_bio_is_seq_zoned_write (struct bio *bio) +{ +return false; +} +static inline bool blk_rq_is_seq_zoned_write (struct request *rq) {return false;
Re: [PATCH v2 4/4] block/mq-deadline: Prevent zoned write reordering due to I/O prioritization
Quoted 5 lines · Bart Van Assche
Assigning I/O priorities with the ioprio cgroup policy may cause different I/O priorities to be assigned to write requests for the same zone. Prevent that this causes unaligned write errors by adding zoned writes for the same zone in the same priority queue as prior zoned writes.
I still think this is fundamentally the wrong thing to do. If you set different priorities, you want I/O to be reordered, so ignoring that is a bad thing.
Re: [PATCH v2 4/4] block/mq-deadline: Prevent zoned write reordering due to I/O prioritization
Quoted 10 lines · Christoph Hellwig
Quoted 5 lines · Bart Van Assche
Assigning I/O priorities with the ioprio cgroup policy may cause different I/O priorities to be assigned to write requests for the same zone. Prevent that this causes unaligned write errors by adding zoned writes for the same zone in the same priority queue as prior zoned writes.
I still think this is fundamentally the wrong thing to do. If you set different priorities, you want I/O to be reordered, so ignoring that is a bad thing.
Hi Christoph,
How about not setting the I/O priority of sequential zoned writes as in the (untested) patch below?
Thanks,
Bart.
[PATCH] block: Do not set the I/O priority for sequential zoned writes
--- block/blk-mq.c | 7 +++++++ include/linux/blk-mq.h | 17 +++++++++++++++++ 2 files changed, 24 insertions(+)
block/blk-mq.c +7 -0
@@ -2922,6 +2922,13 @@ static bool blk_mq_can_use_cached_rq(struct request *rq, struct blk_plug *plug,static void bio_set_ioprio (struct bio *bio) { +/* +* Do not set the I/O priority of sequential zoned write bios because +* this could lead to reordering and hence to unaligned write errors. +*/ +if (blk_bio_is_seq_zoned_write (bio)) +return ; +/* Nobody set ioprio so far? Initialize it based on task's nice value */ if (IOPRIO_PRIO_CLASS (bio->bi_ioprio) ==IOPRIO_CLASS_NONE ) bio->bi_ioprio =get_current_ioprio ();
include/linux/blk-mq.h +17 -0
@@ -1149,6 +1149,18 @@ static inline unsigned int blk_rq_zone_no(struct request *rq)return disk_zone_no (rq->q->disk,blk_rq_pos (rq)); } +/** +* blk_bio_is_seq_zoned_write() - Check if @bio requires write serialization. +* @bio: Bio to examine. +* +* Note: REQ_OP_ZONE_APPEND bios do not require serialization. +*/ +static inline bool blk_bio_is_seq_zoned_write (struct bio *bio) +{ +return disk_zone_is_seq (bio->bi_bdev->bd_disk, bio->bi_iter.bi_sector) && +op_needs_zoned_write_locking (bio_op (bio)); +} +static inline unsigned int blk_rq_zone_is_seq (struct request *rq) {return disk_zone_is_seq (rq->q->disk,blk_rq_pos (rq));
@@ -1196,6 +1208,11 @@ static inline bool blk_req_can_dispatch_to_zone(struct request *rq) return !blk_req_zone_is_write_locked(rq); }#else /* CONFIG_BLK_DEV_ZONED */ +static inline bool blk_bio_is_seq_zoned_write (struct bio *bio) +{ +return false; +} +static inline bool blk_rq_is_seq_zoned_write (struct request *rq) {return false;
Re: [PATCH v2 4/4] block/mq-deadline: Prevent zoned write reordering due to I/O prioritization
Quoted 34 lines · Bart Van Assche
Quoted 10 lines · Christoph Hellwig
Quoted 5 lines · Bart Van Assche
Assigning I/O priorities with the ioprio cgroup policy may cause different I/O priorities to be assigned to write requests for the same zone. Prevent that this causes unaligned write errors by adding zoned writes for the same zone in the same priority queue as prior zoned writes.
I still think this is fundamentally the wrong thing to do. If you set different priorities, you want I/O to be reordered, so ignoring that is a bad thing.
Hi Christoph,
How about not setting the I/O priority of sequential zoned writes as in the (untested) patch below?
Thanks,
Bart.
[PATCH] block: Do not set the I/O priority for sequential zoned writes
--- block/blk-mq.c | 7 +++++++ include/linux/blk-mq.h | 17 +++++++++++++++++ 2 files changed, 24 insertions(+)block/blk-mq.c +0
-0
block/blk-mq.c static bool blk_mq_can_use_cached_rq(struct request *rq, struct blk_plug *plug, · line 2930
Quoted 9 lines
block/blk-mq.c +6
-0@@ -2922,6 +2922,13 @@ static bool blk_mq_can_use_cached_rq(struct request *rq, struct blk_plug *plug,static void bio_set_ioprio (struct bio *bio) { +/* +* Do not set the I/O priority of sequential zoned write bios because +* this could lead to reordering and hence to unaligned write errors. +*/ +if (blk_bio_is_seq_zoned_write (bio)) +return ;
That is not acceptable as that will ignore priorities passed for async direct IOs through aio->aio_reqprio. That one is a perfectly acceptable use case and we should not ignore it.
Quoted 40 lines
block/blk-mq.c +1
-0+/* Nobody set ioprio so far? Initialize it based on task's nice value */ if (IOPRIO_PRIO_CLASS (bio->bi_ioprio) ==IOPRIO_CLASS_NONE ) bio->bi_ioprio =get_current_ioprio ();include/linux/blk-mq.h +17
-0@@ -1149,6 +1149,18 @@ static inline unsigned int blk_rq_zone_no(struct request *rq)return disk_zone_no (rq->q->disk,blk_rq_pos (rq)); } +/** +* blk_bio_is_seq_zoned_write() - Check if @bio requires write serialization. +* @bio: Bio to examine. +* +* Note: REQ_OP_ZONE_APPEND bios do not require serialization. +*/ +static inline bool blk_bio_is_seq_zoned_write (struct bio *bio) +{ +return disk_zone_is_seq (bio->bi_bdev->bd_disk, bio->bi_iter.bi_sector) && +op_needs_zoned_write_locking (bio_op (bio)); +} +static inline unsigned int blk_rq_zone_is_seq (struct request *rq) {return disk_zone_is_seq (rq->q->disk,blk_rq_pos (rq));@@ -1196,6 +1208,11 @@ static inline bool blk_req_can_dispatch_to_zone(struct request *rq) return !blk_req_zone_is_write_locked(rq); }#else /* CONFIG_BLK_DEV_ZONED */ +static inline bool blk_bio_is_seq_zoned_write (struct bio *bio) +{ +return false; +} +static inline bool blk_rq_is_seq_zoned_write (struct request *rq) {return false;
Signature · 2 lines
Damien Le Moal Western Digital Research
Re: [PATCH v2 4/4] block/mq-deadline: Prevent zoned write reordering due to I/O prioritization
Quoted 7 lines · Damien Le Moal
Quoted 6 lines · Bart Van Assche
block/blk-mq.c +0
-0@@ -2922,6 +2922,13 @@ static bool blk_mq_can_use_cached_rq(struct request *rq, struct blk_plug *plug,
Quoted 12 lines
block/blk-mq.c static bool blk_mq_can_use_cached_rq(struct request *rq, struct blk_plug *plug, · line 2930
Quoted 8 lines
block/blk-mq.c +6
-0static void bio_set_ioprio (struct bio *bio) { +/* +* Do not set the I/O priority of sequential zoned write bios because +* this could lead to reordering and hence to unaligned write errors. +*/ +if (blk_bio_is_seq_zoned_write (bio)) +return ;That is not acceptable as that will ignore priorities passed for async direct IOs through
aio->aio_reqprio. That one is a perfectly acceptable use case and we should not ignore it.
Hi Damien,
What you wrote is wrong. bio_set_ioprio() applies the I/O priority set by ionice or by the blk-ioprio cgroup policy. The above patch does not affect the priorities set via aio_reqprio. aio_reqprio is still copied in ki_ioprio and ki_ioprio is still copied into bi_ioprio by the direct I/O code.
Bart.
Re: [PATCH v2 4/4] block/mq-deadline: Prevent zoned write reordering due to I/O prioritization
Quoted 21 lines · Bart Van Assche
Quoted 7 lines · Damien Le Moal
Quoted 6 lines · Bart Van Assche
block/blk-mq.c +0
-0@@ -2922,6 +2922,13 @@ static bool blk_mq_can_use_cached_rq(struct request *rq, struct blk_plug *plug,Quoted 12 lines
block/blk-mq.c static bool blk_mq_can_use_cached_rq(struct request *rq, struct blk_plug *plug, · line 2930
Quoted 8 lines
block/blk-mq.c +6
-0static void bio_set_ioprio (struct bio *bio) { +/* +* Do not set the I/O priority of sequential zoned write bios because +* this could lead to reordering and hence to unaligned write errors. +*/ +if (blk_bio_is_seq_zoned_write (bio)) +return ;That is not acceptable as that will ignore priorities passed for async direct IOs through
aio->aio_reqprio. That one is a perfectly acceptable use case and we should not ignore it.
Quoted 7 lines
Hi Damien,
What you wrote is wrong.
bio_set_ioprio()applies the I/O priority set by ionice or by the blk-ioprio cgroup policy. The above patch does not affect the priorities set viaaio_reqprio.aio_reqpriois still copied inki_ioprioandki_iopriois still copied intobi_ioprioby the direct I/O code.
OK. But your patch will still endup with IO priorities being ignored for legitimate use cases that do not lead to mixed-priorities. E.g. applications using directly the raw device and doing writes to a zone without mixing priorities, either with AIO, ionice or cgroups.
The issue is when a user mixes different IO priorities for writes to the same zone, and as I said before, since doing that is nonsensical, getting the IOs to fail is fine by me. The user will then be aware that this should not be done.
f2fs has a problem with that though as that leads to write errors and FS going read-only (I guess). btrfs will not have this issue because it uses zone append. Need to check dm-zoned as their may be an issue there.
So what about what I proposed in an earlier email: introduce a bio flag "ignore ioprio" that causes bio_set_ioprio() to not set any IO priority and have f2fs set that flag for any zone write BIO it issues ? That will solve your f2fs issue without messing up good use cases.
Signature · 2 lines
Damien Le Moal Western Digital Research
Re: [PATCH v2 4/4] block/mq-deadline: Prevent zoned write reordering due to I/O prioritization
Quoted 11 lines · Damien Le Moal
zone, and as I said before, since doing that is nonsensical, getting the IOs to fail is fine by me. The user will then be aware that this should not be done.
f2fs has a problem with that though as that leads to write errors and FS going read-only (I guess). btrfs will not have this issue because it uses zone append. Need to check dm-zoned as their may be an issue there.
So what about what I proposed in an earlier email: introduce a bio flag "ignore ioprio" that causes
bio_set_ioprio()to not set any IO priority and have f2fs set that flag for any zone write BIO it issues ? That will solve your f2fs issue without messing up good use cases.
How can this even be a problem for f2f2 upsteam where f2fs must only have a single write per zone outstanding? I really don't want crap in the block layer to work around a known broken model (multiple outstanding WRITE commands per zone) that because it's so known broken isn't even merged upstream.
Re: [PATCH v2 4/4] block/mq-deadline: Prevent zoned write reordering due to I/O prioritization
Quoted 13 lines · Christoph Hellwig
Quoted 11 lines · Damien Le Moal
zone, and as I said before, since doing that is nonsensical, getting the IOs to fail is fine by me. The user will then be aware that this should not be done.
f2fs has a problem with that though as that leads to write errors and FS going read-only (I guess). btrfs will not have this issue because it uses zone append. Need to check dm-zoned as their may be an issue there.
So what about what I proposed in an earlier email: introduce a bio flag "ignore ioprio" that causes
bio_set_ioprio()to not set any IO priority and have f2fs set that flag for any zone write BIO it issues ? That will solve your f2fs issue without messing up good use cases.
Quoted 5 lines
How can this even be a problem for f2f2 upsteam where f2fs must only have a single write per zone outstanding? I really don't want crap in the block layer to work around a known broken model (multiple outstanding WRITE commands per zone) that because it's so known broken isn't even merged upstream.
The only constraint at the BIO level for writing to a zone is "issue the write BIOs sequentially". So multiple write BIOs *can* be issued to a zone. The "one write per zone in flight at any time" implemented with zone write locking happens at the request level in the block IO scheduler, so underneath the file system. So the issue can indeed happen.
But what you said could actually provide a solution: have the FS issue regular writes one at a time if the writes have priorities.
Signature · 2 lines
Damien Le Moal Western Digital Research