Skip to content

Commit 5690554

Browse files
YuKuai-huaweikawasaki
authored andcommitted
blk-mq-sched: introduce high level elevator lock
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. 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. Hence introduce a new high level elevator lock, currently it is protecting dispatch_request only. Following patches will convert mq-deadline and bfq to use this lock and finally support request batch dispatching by calling the method multiple time while holding the lock. Signed-off-by: Yu Kuai <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]>
1 parent 0fb21b4 commit 5690554

3 files changed

Lines changed: 9 additions & 2 deletions

File tree

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(&e->lock);
116119
rq = e->type->ops.dispatch_request(hctx);
120+
if (sq_sched)
121+
spin_unlock(&e->lock);
122+
117123
if (!rq) {
118124
blk_mq_put_dispatch_budget(q, budget_token);
119125
/*

block/elevator.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ struct elevator_queue *elevator_alloc(struct request_queue *q,
146146
eq->type = e;
147147
kobject_init(&eq->kobj, &elv_ktype);
148148
mutex_init(&eq->sysfs_lock);
149+
spin_lock_init(&eq->lock);
149150
hash_init(eq->hash);
150151
eq->et = et;
151152

block/elevator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ struct request *elv_rqhash_find(struct request_queue *q, sector_t offset);
119119
/*
120120
* each queue has an elevator_queue associated with it
121121
*/
122-
struct elevator_queue
123-
{
122+
struct elevator_queue {
124123
struct elevator_type *type;
125124
struct elevator_tags *et;
126125
void *elevator_data;
127126
struct kobject kobj;
128127
struct mutex sysfs_lock;
128+
spinlock_t lock;
129129
unsigned long flags;
130130
DECLARE_HASHTABLE(hash, ELV_HASH_BITS);
131131
};

0 commit comments

Comments
 (0)