Skip to content

Commit f0635b8

Browse files
committed
bfq: calculate shallow depths at init time
It doesn't change, so don't put it in the per-IO hot path. Acked-by: Paolo Valente <paolo.valente@linaro.org> Reviewed-by: Omar Sandoval <osandov@fb.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 5514136 commit f0635b8

File tree

1 file changed

+50
-47
lines changed

1 file changed

+50
-47
lines changed

block/bfq-iosched.c

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -486,46 +486,6 @@ static struct request *bfq_choose_req(struct bfq_data *bfqd,
486486
}
487487
}
488488

489-
/*
490-
* See the comments on bfq_limit_depth for the purpose of
491-
* the depths set in the function.
492-
*/
493-
static void bfq_update_depths(struct bfq_data *bfqd, struct sbitmap_queue *bt)
494-
{
495-
bfqd->sb_shift = bt->sb.shift;
496-
497-
/*
498-
* In-word depths if no bfq_queue is being weight-raised:
499-
* leaving 25% of tags only for sync reads.
500-
*
501-
* In next formulas, right-shift the value
502-
* (1U<<bfqd->sb_shift), instead of computing directly
503-
* (1U<<(bfqd->sb_shift - something)), to be robust against
504-
* any possible value of bfqd->sb_shift, without having to
505-
* limit 'something'.
506-
*/
507-
/* no more than 50% of tags for async I/O */
508-
bfqd->word_depths[0][0] = max((1U<<bfqd->sb_shift)>>1, 1U);
509-
/*
510-
* no more than 75% of tags for sync writes (25% extra tags
511-
* w.r.t. async I/O, to prevent async I/O from starving sync
512-
* writes)
513-
*/
514-
bfqd->word_depths[0][1] = max(((1U<<bfqd->sb_shift) * 3)>>2, 1U);
515-
516-
/*
517-
* In-word depths in case some bfq_queue is being weight-
518-
* raised: leaving ~63% of tags for sync reads. This is the
519-
* highest percentage for which, in our tests, application
520-
* start-up times didn't suffer from any regression due to tag
521-
* shortage.
522-
*/
523-
/* no more than ~18% of tags for async I/O */
524-
bfqd->word_depths[1][0] = max(((1U<<bfqd->sb_shift) * 3)>>4, 1U);
525-
/* no more than ~37% of tags for sync writes (~20% extra tags) */
526-
bfqd->word_depths[1][1] = max(((1U<<bfqd->sb_shift) * 6)>>4, 1U);
527-
}
528-
529489
/*
530490
* Async I/O can easily starve sync I/O (both sync reads and sync
531491
* writes), by consuming all tags. Similarly, storms of sync writes,
@@ -535,18 +495,11 @@ static void bfq_update_depths(struct bfq_data *bfqd, struct sbitmap_queue *bt)
535495
*/
536496
static void bfq_limit_depth(unsigned int op, struct blk_mq_alloc_data *data)
537497
{
538-
struct blk_mq_tags *tags = blk_mq_tags_from_data(data);
539498
struct bfq_data *bfqd = data->q->elevator->elevator_data;
540-
struct sbitmap_queue *bt;
541499

542500
if (op_is_sync(op) && !op_is_write(op))
543501
return;
544502

545-
bt = &tags->bitmap_tags;
546-
547-
if (unlikely(bfqd->sb_shift != bt->sb.shift))
548-
bfq_update_depths(bfqd, bt);
549-
550503
data->shallow_depth =
551504
bfqd->word_depths[!!bfqd->wr_busy_queues][op_is_sync(op)];
552505

@@ -5126,6 +5079,55 @@ void bfq_put_async_queues(struct bfq_data *bfqd, struct bfq_group *bfqg)
51265079
__bfq_put_async_bfqq(bfqd, &bfqg->async_idle_bfqq);
51275080
}
51285081

5082+
/*
5083+
* See the comments on bfq_limit_depth for the purpose of
5084+
* the depths set in the function.
5085+
*/
5086+
static void bfq_update_depths(struct bfq_data *bfqd, struct sbitmap_queue *bt)
5087+
{
5088+
bfqd->sb_shift = bt->sb.shift;
5089+
5090+
/*
5091+
* In-word depths if no bfq_queue is being weight-raised:
5092+
* leaving 25% of tags only for sync reads.
5093+
*
5094+
* In next formulas, right-shift the value
5095+
* (1U<<bfqd->sb_shift), instead of computing directly
5096+
* (1U<<(bfqd->sb_shift - something)), to be robust against
5097+
* any possible value of bfqd->sb_shift, without having to
5098+
* limit 'something'.
5099+
*/
5100+
/* no more than 50% of tags for async I/O */
5101+
bfqd->word_depths[0][0] = max((1U<<bfqd->sb_shift)>>1, 1U);
5102+
/*
5103+
* no more than 75% of tags for sync writes (25% extra tags
5104+
* w.r.t. async I/O, to prevent async I/O from starving sync
5105+
* writes)
5106+
*/
5107+
bfqd->word_depths[0][1] = max(((1U<<bfqd->sb_shift) * 3)>>2, 1U);
5108+
5109+
/*
5110+
* In-word depths in case some bfq_queue is being weight-
5111+
* raised: leaving ~63% of tags for sync reads. This is the
5112+
* highest percentage for which, in our tests, application
5113+
* start-up times didn't suffer from any regression due to tag
5114+
* shortage.
5115+
*/
5116+
/* no more than ~18% of tags for async I/O */
5117+
bfqd->word_depths[1][0] = max(((1U<<bfqd->sb_shift) * 3)>>4, 1U);
5118+
/* no more than ~37% of tags for sync writes (~20% extra tags) */
5119+
bfqd->word_depths[1][1] = max(((1U<<bfqd->sb_shift) * 6)>>4, 1U);
5120+
}
5121+
5122+
static int bfq_init_hctx(struct blk_mq_hw_ctx *hctx, unsigned int index)
5123+
{
5124+
struct bfq_data *bfqd = hctx->queue->elevator->elevator_data;
5125+
struct blk_mq_tags *tags = hctx->sched_tags;
5126+
5127+
bfq_update_depths(bfqd, &tags->bitmap_tags);
5128+
return 0;
5129+
}
5130+
51295131
static void bfq_exit_queue(struct elevator_queue *e)
51305132
{
51315133
struct bfq_data *bfqd = e->elevator_data;
@@ -5547,6 +5549,7 @@ static struct elevator_type iosched_bfq_mq = {
55475549
.requests_merged = bfq_requests_merged,
55485550
.request_merged = bfq_request_merged,
55495551
.has_work = bfq_has_work,
5552+
.init_hctx = bfq_init_hctx,
55505553
.init_sched = bfq_init_queue,
55515554
.exit_sched = bfq_exit_queue,
55525555
},

0 commit comments

Comments
 (0)