aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/cgroup.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-08-13 20:22:51 -0400
committerTejun Heo <tj@kernel.org>2013-08-13 20:22:51 -0400
commitedae0c3358947f8be5ca99f762d89e0c38e1f5d5 (patch)
treeb8eefc09b48fe05e7ad069e1136e1f5b4a514d5e /kernel/cgroup.c
parent09a503ea3a816b285b0b402b7f785eaec0c7a7e1 (diff)
cgroup: factor out kill_css()
Factor out css ref killing from cgroup_destroy_locked() into kill_css(). We're gonna add more to the path and the factored out function will eventually be called from other places too. While at it, replace open coded percpu_ref_get() with css_get() for consistency. This shouldn't cause any functional difference as the function is not used for root cgroups. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizefan@huawei.com>
Diffstat (limited to 'kernel/cgroup.c')
-rw-r--r--kernel/cgroup.c58
1 files changed, 35 insertions, 23 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 3c4c4b01ffe5..7b7575f3119c 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -4596,6 +4596,36 @@ static void css_killed_ref_fn(struct percpu_ref *ref)
4596} 4596}
4597 4597
4598/** 4598/**
4599 * kill_css - destroy a css
4600 * @css: css to destroy
4601 *
4602 * This function initiates destruction of @css by putting its base
4603 * reference. ->css_offline() will be invoked asynchronously once
4604 * css_tryget() is guaranteed to fail and when the reference count reaches
4605 * zero, @css will be released.
4606 */
4607static void kill_css(struct cgroup_subsys_state *css)
4608{
4609 /*
4610 * Killing would put the base ref, but we need to keep it alive
4611 * until after ->css_offline().
4612 */
4613 css_get(css);
4614
4615 /*
4616 * cgroup core guarantees that, by the time ->css_offline() is
4617 * invoked, no new css reference will be given out via
4618 * css_tryget(). We can't simply call percpu_ref_kill() and
4619 * proceed to offlining css's because percpu_ref_kill() doesn't
4620 * guarantee that the ref is seen as killed on all CPUs on return.
4621 *
4622 * Use percpu_ref_kill_and_confirm() to get notifications as each
4623 * css is confirmed to be seen as killed on all CPUs.
4624 */
4625 percpu_ref_kill_and_confirm(&css->refcnt, css_killed_ref_fn);
4626}
4627
4628/**
4599 * cgroup_destroy_locked - the first stage of cgroup destruction 4629 * cgroup_destroy_locked - the first stage of cgroup destruction
4600 * @cgrp: cgroup to be destroyed 4630 * @cgrp: cgroup to be destroyed
4601 * 4631 *
@@ -4641,30 +4671,12 @@ static int cgroup_destroy_locked(struct cgroup *cgrp)
4641 return -EBUSY; 4671 return -EBUSY;
4642 4672
4643 /* 4673 /*
4644 * Block new css_tryget() by killing css refcnts. cgroup core 4674 * Initiate massacre of all css's. cgroup_destroy_css_killed()
4645 * guarantees that, by the time ->css_offline() is invoked, no new 4675 * will be invoked to perform the rest of destruction once the
4646 * css reference will be given out via css_tryget(). We can't 4676 * percpu refs of all css's are confirmed to be killed.
4647 * simply call percpu_ref_kill() and proceed to offlining css's
4648 * because percpu_ref_kill() doesn't guarantee that the ref is seen
4649 * as killed on all CPUs on return.
4650 *
4651 * Use percpu_ref_kill_and_confirm() to get notifications as each
4652 * css is confirmed to be seen as killed on all CPUs.
4653 * cgroup_destroy_css_killed() will be invoked to perform the rest
4654 * of destruction once the percpu refs of all css's are confirmed
4655 * to be killed.
4656 */ 4677 */
4657 for_each_root_subsys(cgrp->root, ss) { 4678 for_each_root_subsys(cgrp->root, ss)
4658 struct cgroup_subsys_state *css = cgroup_css(cgrp, ss->subsys_id); 4679 kill_css(cgroup_css(cgrp, ss->subsys_id));
4659
4660 /*
4661 * Killing would put the base ref, but we need to keep it
4662 * alive until after ->css_offline.
4663 */
4664 percpu_ref_get(&css->refcnt);
4665
4666 percpu_ref_kill_and_confirm(&css->refcnt, css_killed_ref_fn);
4667 }
4668 4680
4669 /* 4681 /*
4670 * Mark @cgrp dead. This prevents further task migration and child 4682 * Mark @cgrp dead. This prevents further task migration and child