aboutsummaryrefslogtreecommitdiffstats
path: root/block/blk-throttle.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2012-03-05 16:15:00 -0500
committerJens Axboe <axboe@kernel.dk>2012-03-06 15:27:22 -0500
commit72e06c255181537d0b3e1f657a9ed81655d745b1 (patch)
treeeb656df2ad23a7709b4e9fe58f1dabdc32be9ae9 /block/blk-throttle.c
parent6ecf23afab13c39d3bb0e2d826d0984b0dd53733 (diff)
blkcg: shoot down blkio_groups on elevator switch
Elevator switch may involve changes to blkcg policies. Implement shoot down of blkio_groups. Combined with the previous bypass updates, the end goal is updating blkcg core such that it can ensure that blkcg's being affected become quiescent and don't have any per-blkg data hanging around before commencing any policy updates. Until queues are made aware of the policies that applies to them, as an interim step, all per-policy blkg data will be shot down. * blk-throtl doesn't need this change as it can't be disabled for a live queue; however, update it anyway as the scheduled blkg unification requires this behavior change. This means that blk-throtl configuration will be unnecessarily lost over elevator switch. This oddity will be removed after blkcg learns to associate individual policies with request_queues. * blk-throtl dosen't shoot down root_tg. This is to ease transition. Unified blkg will always have persistent root group and not shooting down root_tg for now eases transition to that point by avoiding having to update td->root_tg and is safe as blk-throtl can never be disabled -v2: Vivek pointed out that group list is not guaranteed to be empty on return from clear function if it raced cgroup removal and lost. Fix it by waiting a bit and retrying. This kludge will soon be removed once locking is updated such that blkg is never in limbo state between blkcg and request_queue locks. blk-throtl no longer shoots down root_tg to avoid breaking td->root_tg. Also, Nest queue_lock inside blkio_list_lock not the other way around to avoid introduce possible deadlock via blkcg lock. -v3: blkcg_clear_queue() repositioned and renamed to blkg_destroy_all() to increase consistency with later changes. cfq_clear_queue() updated to check q->elevator before dereferencing it to avoid NULL dereference on not fully initialized queues (used by later change). Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Vivek Goyal <vgoyal@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block/blk-throttle.c')
-rw-r--r--block/blk-throttle.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index 702c0e64e09f..3699ab40d494 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -989,12 +989,17 @@ throtl_destroy_tg(struct throtl_data *td, struct throtl_grp *tg)
989 td->nr_undestroyed_grps--; 989 td->nr_undestroyed_grps--;
990} 990}
991 991
992static void throtl_release_tgs(struct throtl_data *td) 992static bool throtl_release_tgs(struct throtl_data *td, bool release_root)
993{ 993{
994 struct hlist_node *pos, *n; 994 struct hlist_node *pos, *n;
995 struct throtl_grp *tg; 995 struct throtl_grp *tg;
996 bool empty = true;
996 997
997 hlist_for_each_entry_safe(tg, pos, n, &td->tg_list, tg_node) { 998 hlist_for_each_entry_safe(tg, pos, n, &td->tg_list, tg_node) {
999 /* skip root? */
1000 if (!release_root && tg == td->root_tg)
1001 continue;
1002
998 /* 1003 /*
999 * If cgroup removal path got to blk_group first and removed 1004 * If cgroup removal path got to blk_group first and removed
1000 * it from cgroup list, then it will take care of destroying 1005 * it from cgroup list, then it will take care of destroying
@@ -1002,7 +1007,10 @@ static void throtl_release_tgs(struct throtl_data *td)
1002 */ 1007 */
1003 if (!blkiocg_del_blkio_group(&tg->blkg)) 1008 if (!blkiocg_del_blkio_group(&tg->blkg))
1004 throtl_destroy_tg(td, tg); 1009 throtl_destroy_tg(td, tg);
1010 else
1011 empty = false;
1005 } 1012 }
1013 return empty;
1006} 1014}
1007 1015
1008/* 1016/*
@@ -1029,6 +1037,20 @@ void throtl_unlink_blkio_group(void *key, struct blkio_group *blkg)
1029 spin_unlock_irqrestore(td->queue->queue_lock, flags); 1037 spin_unlock_irqrestore(td->queue->queue_lock, flags);
1030} 1038}
1031 1039
1040static bool throtl_clear_queue(struct request_queue *q)
1041{
1042 lockdep_assert_held(q->queue_lock);
1043
1044 /*
1045 * Clear tgs but leave the root one alone. This is necessary
1046 * because root_tg is expected to be persistent and safe because
1047 * blk-throtl can never be disabled while @q is alive. This is a
1048 * kludge to prepare for unified blkg. This whole function will be
1049 * removed soon.
1050 */
1051 return throtl_release_tgs(q->td, false);
1052}
1053
1032static void throtl_update_blkio_group_common(struct throtl_data *td, 1054static void throtl_update_blkio_group_common(struct throtl_data *td,
1033 struct throtl_grp *tg) 1055 struct throtl_grp *tg)
1034{ 1056{
@@ -1097,6 +1119,7 @@ static void throtl_shutdown_wq(struct request_queue *q)
1097static struct blkio_policy_type blkio_policy_throtl = { 1119static struct blkio_policy_type blkio_policy_throtl = {
1098 .ops = { 1120 .ops = {
1099 .blkio_unlink_group_fn = throtl_unlink_blkio_group, 1121 .blkio_unlink_group_fn = throtl_unlink_blkio_group,
1122 .blkio_clear_queue_fn = throtl_clear_queue,
1100 .blkio_update_group_read_bps_fn = 1123 .blkio_update_group_read_bps_fn =
1101 throtl_update_blkio_group_read_bps, 1124 throtl_update_blkio_group_read_bps,
1102 .blkio_update_group_write_bps_fn = 1125 .blkio_update_group_write_bps_fn =
@@ -1282,7 +1305,7 @@ void blk_throtl_exit(struct request_queue *q)
1282 throtl_shutdown_wq(q); 1305 throtl_shutdown_wq(q);
1283 1306
1284 spin_lock_irq(q->queue_lock); 1307 spin_lock_irq(q->queue_lock);
1285 throtl_release_tgs(td); 1308 throtl_release_tgs(td, true);
1286 1309
1287 /* If there are other groups */ 1310 /* If there are other groups */
1288 if (td->nr_undestroyed_grps > 0) 1311 if (td->nr_undestroyed_grps > 0)