Skip to content

Commit 9e660ac

Browse files
committed
blk-throttle: make blk_throtl_bio() ready for hierarchy
Currently, blk_throtl_bio() issues the passed in bio directly if it's within limits of its associated tg (throtl_grp). This behavior becomes incorrect with hierarchy support as the bio should be accounted to and throttled by the ancestor throtl_grps too. This patch makes the direct issue path of blk_throtl_bio() to loop until it reaches the top-level service_queue or gets throttled. If the former, the bio can be issued directly; otherwise, it gets queued at the first layer it was above limits. As tg->parent_sq is always the top-level service queue currently, this patch in itself doesn't make any behavior differences. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Vivek Goyal <vgoyal@redhat.com>
1 parent 2a12f0d commit 9e660ac

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

‎block/blk-throttle.c‎

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,12 +1239,16 @@ bool blk_throtl_bio(struct request_queue *q, struct bio *bio)
12391239

12401240
sq = &tg->service_queue;
12411241

1242-
/* throtl is FIFO - if other bios are already queued, should queue */
1243-
if (sq->nr_queued[rw])
1244-
goto queue_bio;
1242+
while (true) {
1243+
/* throtl is FIFO - if bios are already queued, should queue */
1244+
if (sq->nr_queued[rw])
1245+
break;
12451246

1246-
/* Bio is with-in rate limit of group */
1247-
if (tg_may_dispatch(tg, bio, NULL)) {
1247+
/* if above limits, break to queue */
1248+
if (!tg_may_dispatch(tg, bio, NULL))
1249+
break;
1250+
1251+
/* within limits, let's charge and dispatch directly */
12481252
throtl_charge_bio(tg, bio);
12491253

12501254
/*
@@ -1259,10 +1263,19 @@ bool blk_throtl_bio(struct request_queue *q, struct bio *bio)
12591263
* So keep on trimming slice even if bio is not queued.
12601264
*/
12611265
throtl_trim_slice(tg, rw);
1262-
goto out_unlock;
1266+
1267+
/*
1268+
* @bio passed through this layer without being throttled.
1269+
* Climb up the ladder. If we''re already at the top, it
1270+
* can be executed directly.
1271+
*/
1272+
sq = sq->parent_sq;
1273+
tg = sq_to_tg(sq);
1274+
if (!tg)
1275+
goto out_unlock;
12631276
}
12641277

1265-
queue_bio:
1278+
/* out-of-limit, queue to @tg */
12661279
throtl_log(sq, "[%c] bio. bdisp=%llu sz=%u bps=%llu iodisp=%u iops=%u queued=%d/%d",
12671280
rw == READ ? 'R' : 'W',
12681281
tg->bytes_disp[rw], bio->bi_size, tg->bps[rw],

0 commit comments

Comments
 (0)