Skip to content

Commit ce93ed0

Browse files
bvanasschekawasaki
authored andcommitted
blk-mq: Restore the zone write order when requeuing
Zoned writes may be requeued. This happens if a block driver returns BLK_STS_RESOURCE, to handle SCSI unit attentions or by the SCSI error handler after error handling has finished. A later patch enables write pipelining and increases the number of pending writes per zone. If multiple writes are pending per zone, write requests may be requeued in another order than submitted. Restore the request order if requests are requeued. Add RQF_DONTPREP to RQF_NOMERGE_FLAGS because this patch may cause RQF_DONTPREP requests to be sent to the code that checks whether a request can be merged. RQF_DONTPREP requests must not be merged. Cc: Damien Le Moal <[email protected]> Cc: Christoph Hellwig <[email protected]> Signed-off-by: Bart Van Assche <[email protected]>
1 parent d277348 commit ce93ed0

6 files changed

Lines changed: 32 additions & 3 deletions

File tree

block/bfq-iosched.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6276,6 +6276,8 @@ static void bfq_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
62766276

62776277
if (flags & BLK_MQ_INSERT_AT_HEAD) {
62786278
list_add(&rq->queuelist, &bfqd->dispatch);
6279+
} else if (flags & BLK_MQ_INSERT_ORDERED) {
6280+
blk_mq_insert_ordered(rq, &bfqd->dispatch);
62796281
} else if (!bfqq) {
62806282
list_add_tail(&rq->queuelist, &bfqd->dispatch);
62816283
} else {

block/blk-mq.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1580,7 +1580,9 @@ static void blk_mq_requeue_work(struct work_struct *work)
15801580
* already. Insert it into the hctx dispatch list to avoid
15811581
* block layer merges for the request.
15821582
*/
1583-
if (rq->rq_flags & RQF_DONTPREP)
1583+
if (blk_mq_preserve_order(rq))
1584+
blk_mq_insert_request(rq, BLK_MQ_INSERT_ORDERED);
1585+
else if (rq->rq_flags & RQF_DONTPREP)
15841586
blk_mq_request_bypass_insert(rq, 0);
15851587
else
15861588
blk_mq_insert_request(rq, BLK_MQ_INSERT_AT_HEAD);
@@ -2614,6 +2616,20 @@ static void blk_mq_insert_requests(struct blk_mq_hw_ctx *hctx,
26142616
blk_mq_run_hw_queue(hctx, run_queue_async);
26152617
}
26162618

2619+
void blk_mq_insert_ordered(struct request *rq, struct list_head *list)
2620+
{
2621+
struct request_queue *q = rq->q;
2622+
struct request *rq2;
2623+
2624+
list_for_each_entry(rq2, list, queuelist)
2625+
if (rq2->q == q && blk_rq_pos(rq2) > blk_rq_pos(rq))
2626+
break;
2627+
2628+
/* Insert rq before rq2. If rq2 is the list head, append at the end. */
2629+
list_add_tail(&rq->queuelist, &rq2->queuelist);
2630+
}
2631+
EXPORT_SYMBOL_GPL(blk_mq_insert_ordered);
2632+
26172633
static void blk_mq_insert_request(struct request *rq, blk_insert_t flags)
26182634
{
26192635
struct request_queue *q = rq->q;
@@ -2668,6 +2684,8 @@ static void blk_mq_insert_request(struct request *rq, blk_insert_t flags)
26682684
spin_lock(&ctx->lock);
26692685
if (flags & BLK_MQ_INSERT_AT_HEAD)
26702686
list_add(&rq->queuelist, &ctx->rq_lists[hctx->type]);
2687+
else if (flags & BLK_MQ_INSERT_ORDERED)
2688+
blk_mq_insert_ordered(rq, &ctx->rq_lists[hctx->type]);
26712689
else
26722690
list_add_tail(&rq->queuelist,
26732691
&ctx->rq_lists[hctx->type]);

block/blk-mq.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ enum {
4040

4141
typedef unsigned int __bitwise blk_insert_t;
4242
#define BLK_MQ_INSERT_AT_HEAD ((__force blk_insert_t)0x01)
43+
#define BLK_MQ_INSERT_ORDERED ((__force blk_insert_t)0x02)
4344

4445
void blk_mq_submit_bio(struct bio *bio);
46+
void blk_mq_insert_ordered(struct request *rq, struct list_head *list);
4547
int blk_mq_poll(struct request_queue *q, blk_qc_t cookie, struct io_comp_batch *iob,
4648
unsigned int flags);
4749
void blk_mq_exit_queue(struct request_queue *q);

block/kyber-iosched.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,8 @@ static void kyber_insert_requests(struct blk_mq_hw_ctx *hctx,
603603
trace_block_rq_insert(rq);
604604
if (flags & BLK_MQ_INSERT_AT_HEAD)
605605
list_move(&rq->queuelist, head);
606+
else if (flags & BLK_MQ_INSERT_ORDERED)
607+
blk_mq_insert_ordered(rq, head);
606608
else
607609
list_move_tail(&rq->queuelist, head);
608610
sbitmap_set_bit(&khd->kcq_map[sched_domain],

block/mq-deadline.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,12 @@ static void dd_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq,
710710
* set expire time and add to fifo list
711711
*/
712712
rq->fifo_time = jiffies + dd->fifo_expire[data_dir];
713-
list_add_tail(&rq->queuelist, &per_prio->fifo_list[data_dir]);
713+
if (flags & BLK_MQ_INSERT_ORDERED)
714+
blk_mq_insert_ordered(rq,
715+
&per_prio->fifo_list[data_dir]);
716+
else
717+
list_add_tail(&rq->queuelist,
718+
&per_prio->fifo_list[data_dir]);
714719
}
715720
}
716721

include/linux/blk-mq.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ enum rqf_flags {
8686

8787
/* flags that prevent us from merging requests: */
8888
#define RQF_NOMERGE_FLAGS \
89-
(RQF_STARTED | RQF_FLUSH_SEQ | RQF_SPECIAL_PAYLOAD)
89+
(RQF_STARTED | RQF_FLUSH_SEQ | RQF_DONTPREP | RQF_SPECIAL_PAYLOAD)
9090

9191
enum mq_rq_state {
9292
MQ_RQ_IDLE = 0,

0 commit comments

Comments
 (0)