Skip to content

Commit 0bca799

Browse files
Ming Leiaxboe
authored andcommitted
blk-mq: order getting budget and driver tag
This patch orders getting budget and driver tag by making sure to acquire driver tag after budget is got, this way can help to avoid the following race: 1) before dispatch request from scheduler queue, get one budget first, then dequeue a request, call it request A. 2) in another IO path for dispatching request B which is from hctx->dispatch, driver tag is got, then try to get budget in blk_mq_dispatch_rq_list(), unfortunately the budget is held by request A. 3) meantime blk_mq_dispatch_rq_list() is called for dispatching request A, and try to get driver tag first, unfortunately no driver tag is available because the driver tag is held by request B 4) both two IO pathes can't move on, and IO stall is caused. This issue can be observed when running dbench on USB storage. This patch fixes this issue by always getting budget before getting driver tag. Cc: stable@vger.kernel.org Fixes: de14829 ("blk-mq: introduce .get_budget and .put_budget in blk_mq_ops") Cc: Christoph Hellwig <hch@lst.de> Cc: Bart Van Assche <bart.vanassche@wdc.com> Cc: Omar Sandoval <osandov@fb.com> Signed-off-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 052c220 commit 0bca799

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

block/blk-mq.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,12 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list,
11801180
struct blk_mq_queue_data bd;
11811181

11821182
rq = list_first_entry(list, struct request, queuelist);
1183-
if (!blk_mq_get_driver_tag(rq, &hctx, false)) {
1183+
1184+
hctx = blk_mq_map_queue(rq->q, rq->mq_ctx->cpu);
1185+
if (!got_budget && !blk_mq_get_dispatch_budget(hctx))
1186+
break;
1187+
1188+
if (!blk_mq_get_driver_tag(rq, NULL, false)) {
11841189
/*
11851190
* The initial allocation attempt failed, so we need to
11861191
* rerun the hardware queue when a tag is freed. The
@@ -1189,8 +1194,7 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list,
11891194
* we'll re-run it below.
11901195
*/
11911196
if (!blk_mq_mark_tag_wait(&hctx, rq)) {
1192-
if (got_budget)
1193-
blk_mq_put_dispatch_budget(hctx);
1197+
blk_mq_put_dispatch_budget(hctx);
11941198
/*
11951199
* For non-shared tags, the RESTART check
11961200
* will suffice.
@@ -1201,11 +1205,6 @@ bool blk_mq_dispatch_rq_list(struct request_queue *q, struct list_head *list,
12011205
}
12021206
}
12031207

1204-
if (!got_budget && !blk_mq_get_dispatch_budget(hctx)) {
1205-
blk_mq_put_driver_tag(rq);
1206-
break;
1207-
}
1208-
12091208
list_del_init(&rq->queuelist);
12101209

12111210
bd.rq = rq;
@@ -1804,11 +1803,11 @@ static blk_status_t __blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx,
18041803
if (q->elevator && !bypass_insert)
18051804
goto insert;
18061805

1807-
if (!blk_mq_get_driver_tag(rq, NULL, false))
1806+
if (!blk_mq_get_dispatch_budget(hctx))
18081807
goto insert;
18091808

1810-
if (!blk_mq_get_dispatch_budget(hctx)) {
1811-
blk_mq_put_driver_tag(rq);
1809+
if (!blk_mq_get_driver_tag(rq, NULL, false)) {
1810+
blk_mq_put_dispatch_budget(hctx);
18121811
goto insert;
18131812
}
18141813

0 commit comments

Comments
 (0)