aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2014-07-08 18:02:57 -0400
committerTejun Heo <tj@kernel.org>2014-07-08 18:02:57 -0400
commitb4536f0cab2b18414e26101a2b9d484c5cbea0c0 (patch)
treebdd7ecc28ee6ae1d558f2fa99a49b95ffd19b655
parentf63070d350e3562baa6196f1043e01cd8da2509a (diff)
cgroup: implement cgroup_subsys->css_reset()
cgroup is implementing support for subsystem dependency which would require a way to enable a subsystem even when it's not directly configured through "cgroup.subtree_control". The previous patches added support for explicitly and implicitly enabled subsystems and showing/hiding their interface files. An explicitly enabled subsystem may become implicitly enabled if it's turned off through "cgroup.subtree_control" but there are subsystems depending on it. In such cases, the subsystem, as it's turned off when seen from userland, shouldn't enforce any resource control. Also, the subsystem may be explicitly turned on later again and its interface files should be as close to the intial state as possible. This patch adds cgroup_subsys->css_reset() which is invoked when a css is hidden. The callback should disable resource control and reset the state to the vanilla state. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizefan@huawei.com> Acked-by: Johannes Weiner <hannes@cmpxchg.org>
-rw-r--r--Documentation/cgroups/cgroups.txt14
-rw-r--r--include/linux/cgroup.h1
-rw-r--r--kernel/cgroup.c16
3 files changed, 27 insertions, 4 deletions
diff --git a/Documentation/cgroups/cgroups.txt b/Documentation/cgroups/cgroups.txt
index 821de56d1580..10c949b293e4 100644
--- a/Documentation/cgroups/cgroups.txt
+++ b/Documentation/cgroups/cgroups.txt
@@ -599,6 +599,20 @@ fork. If this method returns 0 (success) then this should remain valid
599while the caller holds cgroup_mutex and it is ensured that either 599while the caller holds cgroup_mutex and it is ensured that either
600attach() or cancel_attach() will be called in future. 600attach() or cancel_attach() will be called in future.
601 601
602void css_reset(struct cgroup_subsys_state *css)
603(cgroup_mutex held by caller)
604
605An optional operation which should restore @css's configuration to the
606initial state. This is currently only used on the unified hierarchy
607when a subsystem is disabled on a cgroup through
608"cgroup.subtree_control" but should remain enabled because other
609subsystems depend on it. cgroup core makes such a css invisible by
610removing the associated interface files and invokes this callback so
611that the hidden subsystem can return to the initial neutral state.
612This prevents unexpected resource control from a hidden css and
613ensures that the configuration is in the initial state when it is made
614visible again later.
615
602void cancel_attach(struct cgroup *cgrp, struct cgroup_taskset *tset) 616void cancel_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
603(cgroup_mutex held by caller) 617(cgroup_mutex held by caller)
604 618
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 5287f931680a..db99e3b923b1 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -642,6 +642,7 @@ struct cgroup_subsys {
642 int (*css_online)(struct cgroup_subsys_state *css); 642 int (*css_online)(struct cgroup_subsys_state *css);
643 void (*css_offline)(struct cgroup_subsys_state *css); 643 void (*css_offline)(struct cgroup_subsys_state *css);
644 void (*css_free)(struct cgroup_subsys_state *css); 644 void (*css_free)(struct cgroup_subsys_state *css);
645 void (*css_reset)(struct cgroup_subsys_state *css);
645 646
646 int (*can_attach)(struct cgroup_subsys_state *css, 647 int (*can_attach)(struct cgroup_subsys_state *css,
647 struct cgroup_taskset *tset); 648 struct cgroup_taskset *tset);
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 331fa296c7e0..3a6b77d7ba4a 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -2740,17 +2740,25 @@ static ssize_t cgroup_subtree_control_write(struct kernfs_open_file *of,
2740 /* 2740 /*
2741 * All tasks are migrated out of disabled csses. Kill or hide 2741 * All tasks are migrated out of disabled csses. Kill or hide
2742 * them. A css is hidden when the userland requests it to be 2742 * them. A css is hidden when the userland requests it to be
2743 * disabled while other subsystems are still depending on it. 2743 * disabled while other subsystems are still depending on it. The
2744 * css must not actively control resources and be in the vanilla
2745 * state if it's made visible again later. Controllers which may
2746 * be depended upon should provide ->css_reset() for this purpose.
2744 */ 2747 */
2745 for_each_subsys(ss, ssid) { 2748 for_each_subsys(ss, ssid) {
2746 if (!(disable & (1 << ssid))) 2749 if (!(disable & (1 << ssid)))
2747 continue; 2750 continue;
2748 2751
2749 cgroup_for_each_live_child(child, cgrp) { 2752 cgroup_for_each_live_child(child, cgrp) {
2750 if (css_disable & (1 << ssid)) 2753 struct cgroup_subsys_state *css = cgroup_css(child, ss);
2751 kill_css(cgroup_css(child, ss)); 2754
2752 else 2755 if (css_disable & (1 << ssid)) {
2756 kill_css(css);
2757 } else {
2753 cgroup_clear_dir(child, 1 << ssid); 2758 cgroup_clear_dir(child, 1 << ssid);
2759 if (ss->css_reset)
2760 ss->css_reset(css);
2761 }
2754 } 2762 }
2755 } 2763 }
2756 2764