aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/cgroup.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2014-07-15 11:05:10 -0400
committerTejun Heo <tj@kernel.org>2014-07-15 11:05:10 -0400
commita8ddc8215e1a4cd9dc5d6210811cfc381a489ec2 (patch)
tree647056238f18f982969e1aad6d2f564e99d99d65 /kernel/cgroup.c
parent2cf669a58dc08fa065a8bd0dca866c0e6cb358cc (diff)
cgroup: distinguish the default and legacy hierarchies when handling cftypes
Until now, cftype arrays carried files for both the default and legacy hierarchies and the files which needed to be used on only one of them were flagged with either CFTYPE_ONLY_ON_DFL or CFTYPE_INSANE. This gets confusing very quickly and we may end up exposing interface files to the default hierarchy without thinking it through. This patch makes cgroup core provide separate sets of interfaces for cftype handling so that the cftypes for the default and legacy hierarchies are clearly distinguished. The previous two patches renamed the existing ones so that they clearly indicate that they're for the legacy hierarchies. This patch adds the interface for the default hierarchy and apply them selectively depending on the hierarchy type. * cftypes added through cgroup_subsys->dfl_cftypes and cgroup_add_dfl_cftypes() only show up on the default hierarchy. * cftypes added through cgroup_subsys->legacy_cftypes and cgroup_add_legacy_cftypes() only show up on the legacy hierarchies. * cgroup_subsys->dfl_cftypes and ->legacy_cftypes can point to the same array for the cases where the interface files are identical on both types of hierarchies. * This makes all the existing subsystem interface files legacy-only by default and all subsystems will have no interface file created when enabled on the default hierarchy. Each subsystem should explicitly review and compose the interface for the default hierarchy. * A boot param "cgroup__DEVEL__legacy_files_on_dfl" is added which makes subsystems which haven't decided the interface files for the default hierarchy to present the legacy files on the default hierarchy so that its behavior on the default hierarchy can be tested. As the awkward name suggests, this is for development only. * memcg's CFTYPE_INSANE on "use_hierarchy" is noop now as the whole array isn't used on the default hierarchy. The flag is removed. v2: Updated documentation for cgroup__DEVEL__legacy_files_on_dfl. v3: Clear CFTYPE_ONLY_ON_DFL and CFTYPE_INSANE when cfts are removed as suggested by Li. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Neil Horman <nhorman@tuxdriver.com> Acked-by: Li Zefan <lizefan@huawei.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Michal Hocko <mhocko@suse.cz> Cc: Vivek Goyal <vgoyal@redhat.com> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Paul Mackerras <paulus@samba.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Aristeu Rozanski <aris@redhat.com> Cc: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Diffstat (limited to 'kernel/cgroup.c')
-rw-r--r--kernel/cgroup.c62
1 files changed, 59 insertions, 3 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index c275aa439a6f..374ebdf74f35 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -149,6 +149,12 @@ struct cgroup_root cgrp_dfl_root;
149 */ 149 */
150static bool cgrp_dfl_root_visible; 150static bool cgrp_dfl_root_visible;
151 151
152/*
153 * Set by the boot param of the same name and makes subsystems with NULL
154 * ->dfl_files to use ->legacy_files on the default hierarchy.
155 */
156static bool cgroup_legacy_files_on_dfl;
157
152/* some controllers are not supported in the default hierarchy */ 158/* some controllers are not supported in the default hierarchy */
153static const unsigned int cgrp_dfl_root_inhibit_ss_mask = 0 159static const unsigned int cgrp_dfl_root_inhibit_ss_mask = 0
154#ifdef CONFIG_CGROUP_DEBUG 160#ifdef CONFIG_CGROUP_DEBUG
@@ -3085,6 +3091,9 @@ static void cgroup_exit_cftypes(struct cftype *cfts)
3085 kfree(cft->kf_ops); 3091 kfree(cft->kf_ops);
3086 cft->kf_ops = NULL; 3092 cft->kf_ops = NULL;
3087 cft->ss = NULL; 3093 cft->ss = NULL;
3094
3095 /* revert flags set by cgroup core while adding @cfts */
3096 cft->flags &= ~(CFTYPE_ONLY_ON_DFL | CFTYPE_INSANE);
3088 } 3097 }
3089} 3098}
3090 3099
@@ -3195,8 +3204,37 @@ static int cgroup_add_cftypes(struct cgroup_subsys *ss, struct cftype *cfts)
3195 return ret; 3204 return ret;
3196} 3205}
3197 3206
3207/**
3208 * cgroup_add_dfl_cftypes - add an array of cftypes for default hierarchy
3209 * @ss: target cgroup subsystem
3210 * @cfts: zero-length name terminated array of cftypes
3211 *
3212 * Similar to cgroup_add_cftypes() but the added files are only used for
3213 * the default hierarchy.
3214 */
3215int cgroup_add_dfl_cftypes(struct cgroup_subsys *ss, struct cftype *cfts)
3216{
3217 struct cftype *cft;
3218
3219 for (cft = cfts; cft && cft->name[0] != '\0'; cft++)
3220 cft->flags |= CFTYPE_ONLY_ON_DFL;
3221 return cgroup_add_cftypes(ss, cfts);
3222}
3223
3224/**
3225 * cgroup_add_legacy_cftypes - add an array of cftypes for legacy hierarchies
3226 * @ss: target cgroup subsystem
3227 * @cfts: zero-length name terminated array of cftypes
3228 *
3229 * Similar to cgroup_add_cftypes() but the added files are only used for
3230 * the legacy hierarchies.
3231 */
3198int cgroup_add_legacy_cftypes(struct cgroup_subsys *ss, struct cftype *cfts) 3232int cgroup_add_legacy_cftypes(struct cgroup_subsys *ss, struct cftype *cfts)
3199{ 3233{
3234 struct cftype *cft;
3235
3236 for (cft = cfts; cft && cft->name[0] != '\0'; cft++)
3237 cft->flags |= CFTYPE_INSANE;
3200 return cgroup_add_cftypes(ss, cfts); 3238 return cgroup_add_cftypes(ss, cfts);
3201} 3239}
3202 3240
@@ -4893,9 +4931,19 @@ int __init cgroup_init(void)
4893 * disabled flag and cftype registration needs kmalloc, 4931 * disabled flag and cftype registration needs kmalloc,
4894 * both of which aren't available during early_init. 4932 * both of which aren't available during early_init.
4895 */ 4933 */
4896 if (!ss->disabled) { 4934 if (ss->disabled)
4897 cgrp_dfl_root.subsys_mask |= 1 << ss->id; 4935 continue;
4898 WARN_ON(cgroup_add_cftypes(ss, ss->legacy_cftypes)); 4936
4937 cgrp_dfl_root.subsys_mask |= 1 << ss->id;
4938
4939 if (cgroup_legacy_files_on_dfl && !ss->dfl_cftypes)
4940 ss->dfl_cftypes = ss->legacy_cftypes;
4941
4942 if (ss->dfl_cftypes == ss->legacy_cftypes) {
4943 WARN_ON(cgroup_add_cftypes(ss, ss->dfl_cftypes));
4944 } else {
4945 WARN_ON(cgroup_add_dfl_cftypes(ss, ss->dfl_cftypes));
4946 WARN_ON(cgroup_add_legacy_cftypes(ss, ss->legacy_cftypes));
4899 } 4947 }
4900 } 4948 }
4901 4949
@@ -5291,6 +5339,14 @@ static int __init cgroup_disable(char *str)
5291} 5339}
5292__setup("cgroup_disable=", cgroup_disable); 5340__setup("cgroup_disable=", cgroup_disable);
5293 5341
5342static int __init cgroup_set_legacy_files_on_dfl(char *str)
5343{
5344 printk("cgroup: using legacy files on the default hierarchy\n");
5345 cgroup_legacy_files_on_dfl = true;
5346 return 0;
5347}
5348__setup("cgroup__DEVEL__legacy_files_on_dfl", cgroup_set_legacy_files_on_dfl);
5349
5294/** 5350/**
5295 * css_tryget_online_from_dir - get corresponding css from a cgroup dentry 5351 * css_tryget_online_from_dir - get corresponding css from a cgroup dentry
5296 * @dentry: directory dentry of interest 5352 * @dentry: directory dentry of interest