blkcg: implement per-queue policy activation
All blkcg policies were assumed to be enabled on all request_queues.
Due to various implementation obstacles, during the recent blkcg core
updates, this was temporarily implemented as shooting down all !root
blkgs on elevator switch and policy [de]registration combined with
half-broken in-place root blkg updates. In addition to being buggy
and racy, this meant losing all blkcg configurations across those
events.
Now that blkcg is cleaned up enough, this patch replaces the temporary
implementation with proper per-queue policy activation. Each blkcg
policy should call the new blkcg_[de]activate_policy() to enable and
disable the policy on a specific queue. blkcg_activate_policy()
allocates and installs policy data for the policy for all existing
blkgs. blkcg_deactivate_policy() does the reverse. If a policy is
not enabled for a given queue, blkg printing / config functions skip
the respective blkg for the queue.
blkcg_activate_policy() also takes care of root blkg creation, and
cfq_init_queue() and blk_throtl_init() are updated accordingly.
This replaces blkcg_bypass_{start|end}() and update_root_blkg_pd()
unnecessary. Dropped.
v2: cfq_init_queue() was returning uninitialized @ret on root_group
alloc failure if !CONFIG_CFQ_GROUP_IOSCHED. Fixed.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Vivek Goyal <vgoyal@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index 8c520fa..2fc964e 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -995,35 +995,31 @@
struct blkio_cgroup *blkcg = cgroup_to_blkio_cgroup(cgrp);
struct blkg_conf_ctx ctx;
struct throtl_grp *tg;
+ struct throtl_data *td;
int ret;
ret = blkg_conf_prep(blkcg, &blkio_policy_throtl, buf, &ctx);
if (ret)
return ret;
- ret = -EINVAL;
tg = blkg_to_tg(ctx.blkg);
- if (tg) {
- struct throtl_data *td = ctx.blkg->q->td;
+ td = ctx.blkg->q->td;
- if (!ctx.v)
- ctx.v = -1;
+ if (!ctx.v)
+ ctx.v = -1;
- if (is_u64)
- *(u64 *)((void *)tg + cft->private) = ctx.v;
- else
- *(unsigned int *)((void *)tg + cft->private) = ctx.v;
+ if (is_u64)
+ *(u64 *)((void *)tg + cft->private) = ctx.v;
+ else
+ *(unsigned int *)((void *)tg + cft->private) = ctx.v;
- /* XXX: we don't need the following deferred processing */
- xchg(&tg->limits_changed, true);
- xchg(&td->limits_changed, true);
- throtl_schedule_delayed_work(td, 0);
-
- ret = 0;
- }
+ /* XXX: we don't need the following deferred processing */
+ xchg(&tg->limits_changed, true);
+ xchg(&td->limits_changed, true);
+ throtl_schedule_delayed_work(td, 0);
blkg_conf_finish(&ctx);
- return ret;
+ return 0;
}
static int tg_set_conf_u64(struct cgroup *cgrp, struct cftype *cft,
@@ -1230,7 +1226,7 @@
int blk_throtl_init(struct request_queue *q)
{
struct throtl_data *td;
- struct blkio_group *blkg;
+ int ret;
td = kzalloc_node(sizeof(*td), GFP_KERNEL, q->node);
if (!td)
@@ -1243,28 +1239,18 @@
q->td = td;
td->queue = q;
- /* alloc and init root group. */
- rcu_read_lock();
- spin_lock_irq(q->queue_lock);
-
- blkg = blkg_lookup_create(&blkio_root_cgroup, q, true);
- if (!IS_ERR(blkg))
- q->root_blkg = blkg;
-
- spin_unlock_irq(q->queue_lock);
- rcu_read_unlock();
-
- if (!q->root_blkg) {
+ /* activate policy */
+ ret = blkcg_activate_policy(q, &blkio_policy_throtl);
+ if (ret)
kfree(td);
- return -ENOMEM;
- }
- return 0;
+ return ret;
}
void blk_throtl_exit(struct request_queue *q)
{
BUG_ON(!q->td);
throtl_shutdown_wq(q);
+ blkcg_deactivate_policy(q, &blkio_policy_throtl);
kfree(q->td);
}