Skip to content

Commit

Permalink
bfq: update internal depth state when queue depth changes
Browse files Browse the repository at this point in the history
commit 77f1e0a52d26242b6c2dba019f6ebebfb9ff701e upstream

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.

Signed-off-by: Eric Wheeler <[email protected]>
Tested-by: Kai Krakow <[email protected]>
Reported-by: Paolo Valente <[email protected]>
Fixes: f0635b8 ("bfq: calculate shallow depths at init time")
Signed-off-by: Jens Axboe <[email protected]>
Cc: [email protected]
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
axboe authored and gregkh committed May 16, 2019
1 parent 3351e9d commit 824c212
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
8 changes: 7 additions & 1 deletion block/bfq-iosched.c
Original file line number Diff line number Diff line change
Expand Up @@ -5226,14 +5226,19 @@ static unsigned int bfq_update_depths(struct bfq_data *bfqd,
return min_shallow;
}

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

min_shallow = bfq_update_depths(bfqd, &tags->bitmap_tags);
sbitmap_queue_min_shallow_depth(&tags->bitmap_tags, min_shallow);
}

static int bfq_init_hctx(struct blk_mq_hw_ctx *hctx, unsigned int index)
{
bfq_depth_updated(hctx);
return 0;
}

Expand Down Expand Up @@ -5656,6 +5661,7 @@ static struct elevator_type iosched_bfq_mq = {
.requests_merged = bfq_requests_merged,
.request_merged = bfq_request_merged,
.has_work = bfq_has_work,
.depth_updated = bfq_depth_updated,
.init_hctx = bfq_init_hctx,
.init_sched = bfq_init_queue,
.exit_sched = bfq_exit_queue,
Expand Down
2 changes: 2 additions & 0 deletions block/blk-mq.c
Original file line number Diff line number Diff line change
Expand Up @@ -2887,6 +2887,8 @@ int blk_mq_update_nr_requests(struct request_queue *q, unsigned int nr)
}
if (ret)
break;
if (q->elevator && q->elevator->type->ops.mq.depth_updated)
q->elevator->type->ops.mq.depth_updated(hctx);
}

if (!ret)
Expand Down
1 change: 1 addition & 0 deletions include/linux/elevator.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ struct elevator_mq_ops {
void (*exit_sched)(struct elevator_queue *);
int (*init_hctx)(struct blk_mq_hw_ctx *, unsigned int);
void (*exit_hctx)(struct blk_mq_hw_ctx *, unsigned int);
void (*depth_updated)(struct blk_mq_hw_ctx *);

bool (*allow_merge)(struct request_queue *, struct request *, struct bio *);
bool (*bio_merge)(struct blk_mq_hw_ctx *, struct bio *);
Expand Down

0 comments on commit 824c212

Please sign in to comment.