Skip to content

Commit 919b513

Browse files
Li Lingfengaxboe
authored andcommitted
block: flush all throttled bios when deleting the cgroup
When a process migrates to another cgroup and the original cgroup is deleted, the restrictions of throttled bios cannot be removed. If the restrictions are set too low, it will take a long time to complete these bios. Refer to the process of deleting a disk to remove the restrictions and issue bios when deleting the cgroup. This makes difference on the behavior of throttled bios: Before: the limit of the throttled bios can't be changed and the bios will complete under this limit; Now: the limit will be canceled and the throttled bios will be flushed immediately. References: [1] https://lore.kernel.org/r/[email protected] [2] https://lore.kernel.org/all/[email protected]/ Signed-off-by: Li Lingfeng <[email protected]> Acked-by: Tejun Heo <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 96a9fe6 commit 919b513

File tree

1 file changed

+44
-24
lines changed

1 file changed

+44
-24
lines changed

block/blk-throttle.c

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,13 +1526,50 @@ static void throtl_shutdown_wq(struct request_queue *q)
15261526
cancel_work_sync(&td->dispatch_work);
15271527
}
15281528

1529+
static void tg_flush_bios(struct throtl_grp *tg)
1530+
{
1531+
struct throtl_service_queue *sq = &tg->service_queue;
1532+
1533+
if (tg->flags & THROTL_TG_CANCELING)
1534+
return;
1535+
/*
1536+
* Set the flag to make sure throtl_pending_timer_fn() won't
1537+
* stop until all throttled bios are dispatched.
1538+
*/
1539+
tg->flags |= THROTL_TG_CANCELING;
1540+
1541+
/*
1542+
* Do not dispatch cgroup without THROTL_TG_PENDING or cgroup
1543+
* will be inserted to service queue without THROTL_TG_PENDING
1544+
* set in tg_update_disptime below. Then IO dispatched from
1545+
* child in tg_dispatch_one_bio will trigger double insertion
1546+
* and corrupt the tree.
1547+
*/
1548+
if (!(tg->flags & THROTL_TG_PENDING))
1549+
return;
1550+
1551+
/*
1552+
* Update disptime after setting the above flag to make sure
1553+
* throtl_select_dispatch() won't exit without dispatching.
1554+
*/
1555+
tg_update_disptime(tg);
1556+
1557+
throtl_schedule_pending_timer(sq, jiffies + 1);
1558+
}
1559+
1560+
static void throtl_pd_offline(struct blkg_policy_data *pd)
1561+
{
1562+
tg_flush_bios(pd_to_tg(pd));
1563+
}
1564+
15291565
struct blkcg_policy blkcg_policy_throtl = {
15301566
.dfl_cftypes = throtl_files,
15311567
.legacy_cftypes = throtl_legacy_files,
15321568

15331569
.pd_alloc_fn = throtl_pd_alloc,
15341570
.pd_init_fn = throtl_pd_init,
15351571
.pd_online_fn = throtl_pd_online,
1572+
.pd_offline_fn = throtl_pd_offline,
15361573
.pd_free_fn = throtl_pd_free,
15371574
};
15381575

@@ -1553,32 +1590,15 @@ void blk_throtl_cancel_bios(struct gendisk *disk)
15531590
*/
15541591
rcu_read_lock();
15551592
blkg_for_each_descendant_post(blkg, pos_css, q->root_blkg) {
1556-
struct throtl_grp *tg = blkg_to_tg(blkg);
1557-
struct throtl_service_queue *sq = &tg->service_queue;
1558-
1559-
/*
1560-
* Set the flag to make sure throtl_pending_timer_fn() won't
1561-
* stop until all throttled bios are dispatched.
1562-
*/
1563-
tg->flags |= THROTL_TG_CANCELING;
1564-
15651593
/*
1566-
* Do not dispatch cgroup without THROTL_TG_PENDING or cgroup
1567-
* will be inserted to service queue without THROTL_TG_PENDING
1568-
* set in tg_update_disptime below. Then IO dispatched from
1569-
* child in tg_dispatch_one_bio will trigger double insertion
1570-
* and corrupt the tree.
1594+
* disk_release will call pd_offline_fn to cancel bios.
1595+
* However, disk_release can't be called if someone get
1596+
* the refcount of device and issued bios which are
1597+
* inflight after del_gendisk.
1598+
* Cancel bios here to ensure no bios are inflight after
1599+
* del_gendisk.
15711600
*/
1572-
if (!(tg->flags & THROTL_TG_PENDING))
1573-
continue;
1574-
1575-
/*
1576-
* Update disptime after setting the above flag to make sure
1577-
* throtl_select_dispatch() won't exit without dispatching.
1578-
*/
1579-
tg_update_disptime(tg);
1580-
1581-
throtl_schedule_pending_timer(sq, jiffies + 1);
1601+
tg_flush_bios(blkg_to_tg(blkg));
15821602
}
15831603
rcu_read_unlock();
15841604
spin_unlock_irq(&q->queue_lock);

0 commit comments

Comments
 (0)