Skip to content

Commit 77f1e0a

Browse files
committed
bfq: update internal depth state when queue depth changes
A previous commit moved the shallow depth and BFQ depth map calculations to be done at init time, moving it outside of the hotter IO path. This potentially causes hangs if the users changes the depth of the scheduler map, by writing to the 'nr_requests' sysfs file for that device. Add a blk-mq-sched hook that allows blk-mq to inform the scheduler if the depth changes, so that the scheduler can update its internal state. Tested-by: Kai Krakow <kai@kaishome.de> Reported-by: Paolo Valente <paolo.valente@linaro.org> Fixes: f0635b8 ("bfq: calculate shallow depths at init time") Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 917257d commit 77f1e0a

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

block/bfq-iosched.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5396,14 +5396,19 @@ static unsigned int bfq_update_depths(struct bfq_data *bfqd,
53965396
return min_shallow;
53975397
}
53985398

5399-
static int bfq_init_hctx(struct blk_mq_hw_ctx *hctx, unsigned int index)
5399+
static void bfq_depth_updated(struct blk_mq_hw_ctx *hctx)
54005400
{
54015401
struct bfq_data *bfqd = hctx->queue->elevator->elevator_data;
54025402
struct blk_mq_tags *tags = hctx->sched_tags;
54035403
unsigned int min_shallow;
54045404

54055405
min_shallow = bfq_update_depths(bfqd, &tags->bitmap_tags);
54065406
sbitmap_queue_min_shallow_depth(&tags->bitmap_tags, min_shallow);
5407+
}
5408+
5409+
static int bfq_init_hctx(struct blk_mq_hw_ctx *hctx, unsigned int index)
5410+
{
5411+
bfq_depth_updated(hctx);
54075412
return 0;
54085413
}
54095414

@@ -5826,6 +5831,7 @@ static struct elevator_type iosched_bfq_mq = {
58265831
.requests_merged = bfq_requests_merged,
58275832
.request_merged = bfq_request_merged,
58285833
.has_work = bfq_has_work,
5834+
.depth_updated = bfq_depth_updated,
58295835
.init_hctx = bfq_init_hctx,
58305836
.init_sched = bfq_init_queue,
58315837
.exit_sched = bfq_exit_queue,

block/blk-mq.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3135,6 +3135,8 @@ int blk_mq_update_nr_requests(struct request_queue *q, unsigned int nr)
31353135
}
31363136
if (ret)
31373137
break;
3138+
if (q->elevator && q->elevator->type->ops.depth_updated)
3139+
q->elevator->type->ops.depth_updated(hctx);
31383140
}
31393141

31403142
if (!ret)

include/linux/elevator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct elevator_mq_ops {
3131
void (*exit_sched)(struct elevator_queue *);
3232
int (*init_hctx)(struct blk_mq_hw_ctx *, unsigned int);
3333
void (*exit_hctx)(struct blk_mq_hw_ctx *, unsigned int);
34+
void (*depth_updated)(struct blk_mq_hw_ctx *);
3435

3536
bool (*allow_merge)(struct request_queue *, struct request *, struct bio *);
3637
bool (*bio_merge)(struct blk_mq_hw_ctx *, struct bio *);

0 commit comments

Comments
 (0)