Skip to content

Commit 8cc7f93

Browse files
YuKuai-huaweikawasaki
authored andcommitted
elevator: factor elevator lock out of dispatch_request method
Currently, both mq-deadline and bfq have global spin lock that will be grabbed inside elevator methods like dispatch_request, insert_requests, and bio_merge. And the global lock is the main reason mq-deadline and bfq can't scale very well. For dispatch_request method, current behavior is dispatching one request at a time. In the case of multiple dispatching contexts, this behavior will cause huge lock contention and messing up the requests dispatching order. And folloiwng patches will support requests batch dispatching to fix thoses problems. While dispatching request, blk_mq_get_disatpch_budget() and blk_mq_get_driver_tag() must be called, and they are not ready to be called inside elevator methods, hence introduce a new method like dispatch_requests is not possible. In conclusion, this patch factor the global lock out of dispatch_request method, and following patches will support request batch dispatch by calling the methods multiple time while holding the lock. Signed-off-by: Yu Kuai <[email protected]>
1 parent 81f19c2 commit 8cc7f93

3 files changed

Lines changed: 7 additions & 7 deletions

File tree

block/bfq-iosched.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5307,8 +5307,6 @@ static struct request *bfq_dispatch_request(struct blk_mq_hw_ctx *hctx)
53075307
struct bfq_queue *in_serv_queue;
53085308
bool waiting_rq, idle_timer_disabled = false;
53095309

5310-
spin_lock_irq(bfqd->lock);
5311-
53125310
in_serv_queue = bfqd->in_service_queue;
53135311
waiting_rq = in_serv_queue && bfq_bfqq_wait_request(in_serv_queue);
53145312

@@ -5318,7 +5316,6 @@ static struct request *bfq_dispatch_request(struct blk_mq_hw_ctx *hctx)
53185316
waiting_rq && !bfq_bfqq_wait_request(in_serv_queue);
53195317
}
53205318

5321-
spin_unlock_irq(bfqd->lock);
53225319
bfq_update_dispatch_stats(hctx->queue, rq,
53235320
idle_timer_disabled ? in_serv_queue : NULL,
53245321
idle_timer_disabled);

block/blk-mq-sched.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ static int __blk_mq_do_dispatch_sched(struct blk_mq_hw_ctx *hctx)
9898
max_dispatch = hctx->queue->nr_requests;
9999

100100
do {
101+
bool sq_sched = blk_queue_sq_sched(q);
101102
struct request *rq;
102103
int budget_token;
103104

@@ -113,7 +114,12 @@ static int __blk_mq_do_dispatch_sched(struct blk_mq_hw_ctx *hctx)
113114
if (budget_token < 0)
114115
break;
115116

117+
if (sq_sched)
118+
spin_lock_irq(&e->lock);
116119
rq = e->type->ops.dispatch_request(hctx);
120+
if (sq_sched)
121+
spin_unlock_irq(&e->lock);
122+
117123
if (!rq) {
118124
blk_mq_put_dispatch_budget(q, budget_token);
119125
/*

block/mq-deadline.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,9 @@ static struct request *dd_dispatch_request(struct blk_mq_hw_ctx *hctx)
466466
struct request *rq;
467467
enum dd_prio prio;
468468

469-
spin_lock(dd->lock);
470469
rq = dd_dispatch_prio_aged_requests(dd, now);
471470
if (rq)
472-
goto unlock;
471+
return rq;
473472

474473
/*
475474
* Next, dispatch requests in priority order. Ignore lower priority
@@ -481,8 +480,6 @@ static struct request *dd_dispatch_request(struct blk_mq_hw_ctx *hctx)
481480
break;
482481
}
483482

484-
unlock:
485-
spin_unlock(dd->lock);
486483
return rq;
487484
}
488485

0 commit comments

Comments
 (0)