Skip to content

Commit 2a12f0d

Browse files
committed
blk-throttle: make blk_throtl_drain() ready for hierarchy
The current blk_throtl_drain() assumes that all active throtl_grps are queued on throtl_data->service_queue, which won't be true once hierarchy support is implemented. This patch makes blk_throtl_drain() perform post-order walk of the blkg hierarchy draining each associated throtl_grp, which guarantees that all bios will eventually be pushed to the top-level service_queue in throtl_data. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Vivek Goyal <vgoyal@redhat.com>
1 parent 6e1a570 commit 2a12f0d

1 file changed

Lines changed: 40 additions & 11 deletions

File tree

‎block/blk-throttle.c‎

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,28 @@ bool blk_throtl_bio(struct request_queue *q, struct bio *bio)
12991299
return throttled;
13001300
}
13011301

1302+
/*
1303+
* Dispatch all bios from all children tg's queued on @parent_sq. On
1304+
* return, @parent_sq is guaranteed to not have any active children tg's
1305+
* and all bios from previously active tg's are on @parent_sq->bio_lists[].
1306+
*/
1307+
static void tg_drain_bios(struct throtl_service_queue *parent_sq)
1308+
{
1309+
struct throtl_grp *tg;
1310+
1311+
while ((tg = throtl_rb_first(parent_sq))) {
1312+
struct throtl_service_queue *sq = &tg->service_queue;
1313+
struct bio *bio;
1314+
1315+
throtl_dequeue_tg(tg);
1316+
1317+
while ((bio = bio_list_peek(&sq->bio_lists[READ])))
1318+
tg_dispatch_one_bio(tg, bio_data_dir(bio));
1319+
while ((bio = bio_list_peek(&sq->bio_lists[WRITE])))
1320+
tg_dispatch_one_bio(tg, bio_data_dir(bio));
1321+
}
1322+
}
1323+
13021324
/**
13031325
* blk_throtl_drain - drain throttled bios
13041326
* @q: request_queue to drain throttled bios for
@@ -1309,27 +1331,34 @@ void blk_throtl_drain(struct request_queue *q)
13091331
__releases(q->queue_lock) __acquires(q->queue_lock)
13101332
{
13111333
struct throtl_data *td = q->td;
1312-
struct throtl_service_queue *parent_sq = &td->service_queue;
1313-
struct throtl_grp *tg;
1334+
struct blkcg_gq *blkg;
1335+
struct cgroup *pos_cgrp;
13141336
struct bio *bio;
13151337
int rw;
13161338

13171339
queue_lockdep_assert_held(q);
1340+
rcu_read_lock();
13181341

1319-
while ((tg = throtl_rb_first(parent_sq))) {
1320-
struct throtl_service_queue *sq = &tg->service_queue;
1342+
/*
1343+
* Drain each tg while doing post-order walk on the blkg tree, so
1344+
* that all bios are propagated to td->service_queue. It'd be
1345+
* better to walk service_queue tree directly but blkg walk is
1346+
* easier.
1347+
*/
1348+
blkg_for_each_descendant_post(blkg, pos_cgrp, td->queue->root_blkg)
1349+
tg_drain_bios(&blkg_to_tg(blkg)->service_queue);
13211350

1322-
throtl_dequeue_tg(tg);
1351+
tg_drain_bios(&td_root_tg(td)->service_queue);
13231352

1324-
while ((bio = bio_list_peek(&sq->bio_lists[READ])))
1325-
tg_dispatch_one_bio(tg, bio_data_dir(bio));
1326-
while ((bio = bio_list_peek(&sq->bio_lists[WRITE])))
1327-
tg_dispatch_one_bio(tg, bio_data_dir(bio));
1328-
}
1353+
/* finally, transfer bios from top-level tg's into the td */
1354+
tg_drain_bios(&td->service_queue);
1355+
1356+
rcu_read_unlock();
13291357
spin_unlock_irq(q->queue_lock);
13301358

1359+
/* all bios now should be in td->service_queue, issue them */
13311360
for (rw = READ; rw <= WRITE; rw++)
1332-
while ((bio = bio_list_pop(&parent_sq->bio_lists[rw])))
1361+
while ((bio = bio_list_pop(&td->service_queue.bio_lists[rw])))
13331362
generic_make_request(bio);
13341363

13351364
spin_lock_irq(q->queue_lock);

0 commit comments

Comments
 (0)