Skip to content

Commit d38d351

Browse files
osandovaxboe
authored andcommitted
blk-mq-sched: separate mark hctx and queue restart operations
In blk_mq_sched_dispatch_requests(), we call blk_mq_sched_mark_restart() after we dispatch requests left over on our hardware queue dispatch list. This is so we'll go back and dispatch requests from the scheduler. In this case, it's only necessary to restart the hardware queue that we are running; there's no reason to run other hardware queues just because we are using shared tags. So, split out blk_mq_sched_mark_restart() into two operations, one for just the hardware queue and one for the whole request queue. The core code only needs the hctx variant, but I/O schedulers will want to use both. This also requires adjusting blk_mq_sched_restart_queues() to always check the queue restart flag, not just when using shared tags. Signed-off-by: Omar Sandoval <osandov@fb.com> Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent da55f2c commit d38d351

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

block/blk-mq-sched.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ void blk_mq_sched_dispatch_requests(struct blk_mq_hw_ctx *hctx)
205205
* needing a restart in that case.
206206
*/
207207
if (!list_empty(&rq_list)) {
208-
blk_mq_sched_mark_restart(hctx);
208+
blk_mq_sched_mark_restart_hctx(hctx);
209209
did_work = blk_mq_dispatch_rq_list(hctx, &rq_list);
210210
} else if (!has_sched_dispatch) {
211211
blk_mq_flush_busy_ctxs(hctx, &rq_list);
@@ -331,20 +331,16 @@ static void blk_mq_sched_restart_hctx(struct blk_mq_hw_ctx *hctx)
331331

332332
void blk_mq_sched_restart_queues(struct blk_mq_hw_ctx *hctx)
333333
{
334+
struct request_queue *q = hctx->queue;
334335
unsigned int i;
335336

336-
if (!(hctx->flags & BLK_MQ_F_TAG_SHARED))
337+
if (test_bit(QUEUE_FLAG_RESTART, &q->queue_flags)) {
338+
if (test_and_clear_bit(QUEUE_FLAG_RESTART, &q->queue_flags)) {
339+
queue_for_each_hw_ctx(q, hctx, i)
340+
blk_mq_sched_restart_hctx(hctx);
341+
}
342+
} else {
337343
blk_mq_sched_restart_hctx(hctx);
338-
else {
339-
struct request_queue *q = hctx->queue;
340-
341-
if (!test_bit(QUEUE_FLAG_RESTART, &q->queue_flags))
342-
return;
343-
344-
clear_bit(QUEUE_FLAG_RESTART, &q->queue_flags);
345-
346-
queue_for_each_hw_ctx(q, hctx, i)
347-
blk_mq_sched_restart_hctx(hctx);
348344
}
349345
}
350346

block/blk-mq-sched.h

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,27 @@ static inline bool blk_mq_sched_has_work(struct blk_mq_hw_ctx *hctx)
122122
return false;
123123
}
124124

125-
static inline void blk_mq_sched_mark_restart(struct blk_mq_hw_ctx *hctx)
125+
/*
126+
* Mark a hardware queue as needing a restart.
127+
*/
128+
static inline void blk_mq_sched_mark_restart_hctx(struct blk_mq_hw_ctx *hctx)
126129
{
127-
if (!test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state)) {
130+
if (!test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
128131
set_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);
129-
if (hctx->flags & BLK_MQ_F_TAG_SHARED) {
130-
struct request_queue *q = hctx->queue;
132+
}
133+
134+
/*
135+
* Mark a hardware queue and the request queue it belongs to as needing a
136+
* restart.
137+
*/
138+
static inline void blk_mq_sched_mark_restart_queue(struct blk_mq_hw_ctx *hctx)
139+
{
140+
struct request_queue *q = hctx->queue;
131141

132-
if (!test_bit(QUEUE_FLAG_RESTART, &q->queue_flags))
133-
set_bit(QUEUE_FLAG_RESTART, &q->queue_flags);
134-
}
135-
}
142+
if (!test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
143+
set_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);
144+
if (!test_bit(QUEUE_FLAG_RESTART, &q->queue_flags))
145+
set_bit(QUEUE_FLAG_RESTART, &q->queue_flags);
136146
}
137147

138148
static inline bool blk_mq_sched_needs_restart(struct blk_mq_hw_ctx *hctx)

0 commit comments

Comments
 (0)