2015-08-05 17:20:21

by Tejun Heo

[permalink] [raw]
Subject: [PATCH cgroup/for-4.3 1/3] cgroup: replace error handling in cgroup_init() with WARN_ON()s

The init sequence shouldn't fail short of bugs and even when it does
it's better to continue with the rest of initialization and we were
silently ignoring /proc/cgroups creation failure.

Drop the explicit error handling and wrap sysfs_create_mount_point(),
register_filesystem() and proc_create() with WARN_ON()s.

Signed-off-by: Tejun Heo <[email protected]>
Cc: Li Zefan <[email protected]>
Cc: Johannes Weiner <[email protected]>
---
kernel/cgroup.c | 15 ++++-----------
1 file changed, 4 insertions(+), 11 deletions(-)

--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -5014,7 +5014,7 @@ int __init cgroup_init(void)
{
struct cgroup_subsys *ss;
unsigned long key;
- int ssid, err;
+ int ssid;

BUG_ON(percpu_init_rwsem(&cgroup_threadgroup_rwsem));
BUG_ON(cgroup_init_cftypes(NULL, cgroup_dfl_base_files));
@@ -5072,17 +5072,10 @@ int __init cgroup_init(void)
ss->bind(init_css_set.subsys[ssid]);
}

- err = sysfs_create_mount_point(fs_kobj, "cgroup");
- if (err)
- return err;
-
- err = register_filesystem(&cgroup_fs_type);
- if (err < 0) {
- sysfs_remove_mount_point(fs_kobj, "cgroup");
- return err;
- }
+ WARN_ON(sysfs_create_mount_point(fs_kobj, "cgroup"));
+ WARN_ON(register_filesystem(&cgroup_fs_type));
+ WARN_ON(!proc_create("cgroups", 0, NULL, &proc_cgroupstats_operations));

- proc_create("cgroups", 0, NULL, &proc_cgroupstats_operations);
return 0;
}


2015-08-05 17:20:50

by Tejun Heo

[permalink] [raw]
Subject: Re: [PATCH cgroup/for-4.3 2/3] cgroup: drop cgroup__DEVEL__legacy_files_on_dfl

Now that interfaces for the major three controllers - cpu, memory, io
- are shaping up, there's no reason to have an option to force legacy
files to show up on the unified hierarchy for testing. Drop it.

Signed-off-by: Tejun Heo <[email protected]>
Cc: Li Zefan <[email protected]>
Cc: Johannes Weiner <[email protected]>
---
Documentation/cgroups/unified-hierarchy.txt | 6 -----
kernel/cgroup.c | 30 +---------------------------
2 files changed, 2 insertions(+), 34 deletions(-)

--- a/Documentation/cgroups/unified-hierarchy.txt
+++ b/Documentation/cgroups/unified-hierarchy.txt
@@ -107,12 +107,6 @@ root of unified hierarchy can be bound t
allows mixing unified hierarchy with the traditional multiple
hierarchies in a fully backward compatible way.

-For development purposes, the following boot parameter makes all
-controllers to appear on the unified hierarchy whether supported or
-not.
-
- cgroup__DEVEL__legacy_files_on_dfl
-
A controller can be moved across hierarchies only after the controller
is no longer referenced in its current hierarchy. Because per-cgroup
controller states are destroyed asynchronously and controllers may
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -152,12 +152,6 @@ struct cgroup_root cgrp_dfl_root;
*/
static bool cgrp_dfl_root_visible;

-/*
- * Set by the boot param of the same name and makes subsystems with NULL
- * ->dfl_files to use ->legacy_files on the default hierarchy.
- */
-static bool cgroup_legacy_files_on_dfl;
-
/* some controllers are not supported in the default hierarchy */
static unsigned long cgrp_dfl_root_inhibit_ss_mask;

@@ -3340,17 +3334,8 @@ int cgroup_add_legacy_cftypes(struct cgr
{
struct cftype *cft;

- /*
- * If legacy_flies_on_dfl, we want to show the legacy files on the
- * dfl hierarchy but iff the target subsystem hasn't been updated
- * for the dfl hierarchy yet.
- */
- if (!cgroup_legacy_files_on_dfl ||
- ss->dfl_cftypes != ss->legacy_cftypes) {
- for (cft = cfts; cft && cft->name[0] != '\0'; cft++)
- cft->flags |= __CFTYPE_NOT_ON_DFL;
- }
-
+ for (cft = cfts; cft && cft->name[0] != '\0'; cft++)
+ cft->flags |= __CFTYPE_NOT_ON_DFL;
return cgroup_add_cftypes(ss, cfts);
}

@@ -5055,9 +5040,6 @@ int __init cgroup_init(void)

cgrp_dfl_root.subsys_mask |= 1 << ss->id;

- if (cgroup_legacy_files_on_dfl && !ss->dfl_cftypes)
- ss->dfl_cftypes = ss->legacy_cftypes;
-
if (!ss->dfl_cftypes)
cgrp_dfl_root_inhibit_ss_mask |= 1 << ss->id;

@@ -5474,14 +5456,6 @@ static int __init cgroup_disable(char *s
}
__setup("cgroup_disable=", cgroup_disable);

-static int __init cgroup_set_legacy_files_on_dfl(char *str)
-{
- printk("cgroup: using legacy files on the default hierarchy\n");
- cgroup_legacy_files_on_dfl = true;
- return 0;
-}
-__setup("cgroup__DEVEL__legacy_files_on_dfl", cgroup_set_legacy_files_on_dfl);
-
/**
* css_tryget_online_from_dir - get corresponding css from a cgroup dentry
* @dentry: directory dentry of interest

2015-08-05 17:21:21

by Tejun Heo

[permalink] [raw]
Subject: [PATCH cgroup/for-4.3 3/3] cgroup: replace __DEVEL__sane_behavior with cgroup2 fs type

With major controllers - cpu, memory and io - shaping up for the
unified hierarchy, cgroup2 is about ready to be, gradually, released
into the wild. Replace __DEVEL__sane_behavior flag which was used to
select the unified hierarchy with a separate filesystem type "cgroup2"
so that unified hierarchy can be mounted as follows.

mount -t cgroup2 none $MOUNT_POINT

Signed-off-by: Tejun Heo <[email protected]>
Cc: Li Zefan <[email protected]>
Cc: Johannes Weiner <[email protected]>
---
Documentation/cgroups/unified-hierarchy.txt | 6 +--
include/linux/cgroup-defs.h | 1
kernel/cgroup.c | 43 +++++++++++++---------------
3 files changed, 22 insertions(+), 28 deletions(-)

--- a/Documentation/cgroups/unified-hierarchy.txt
+++ b/Documentation/cgroups/unified-hierarchy.txt
@@ -94,11 +94,9 @@ the process.

2-1. Mounting

-Currently, unified hierarchy can be mounted with the following mount
-command. Note that this is still under development and scheduled to
-change soon.
+Unified hierarchy can be mounted with the following mount command.

- mount -t cgroup -o __DEVEL__sane_behavior cgroup $MOUNT_POINT
+ mount -t cgroup2 none $MOUNT_POINT

All controllers which support the unified hierarchy and are not bound
to other hierarchies are automatically bound to unified hierarchy and
--- a/include/linux/cgroup-defs.h
+++ b/include/linux/cgroup-defs.h
@@ -66,7 +66,6 @@ enum {

/* cgroup_root->flags */
enum {
- CGRP_ROOT_SANE_BEHAVIOR = (1 << 0), /* __DEVEL__sane_behavior specified */
CGRP_ROOT_NOPREFIX = (1 << 1), /* mounted subsystems have no named prefix */
CGRP_ROOT_XATTR = (1 << 2), /* supports extended attributes */
};
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -183,6 +183,7 @@ static unsigned long have_exit_callback
/* Ditto for the can_fork callback. */
static unsigned long have_canfork_callback __read_mostly;

+static struct file_system_type cgroup2_fs_type;
static struct cftype cgroup_dfl_base_files[];
static struct cftype cgroup_legacy_base_files[];

@@ -1391,10 +1392,6 @@ static int parse_cgroupfs_options(char *
all_ss = true;
continue;
}
- if (!strcmp(token, "__DEVEL__sane_behavior")) {
- opts->flags |= CGRP_ROOT_SANE_BEHAVIOR;
- continue;
- }
if (!strcmp(token, "noprefix")) {
opts->flags |= CGRP_ROOT_NOPREFIX;
continue;
@@ -1461,15 +1458,6 @@ static int parse_cgroupfs_options(char *
return -ENOENT;
}

- if (opts->flags & CGRP_ROOT_SANE_BEHAVIOR) {
- pr_warn("sane_behavior: this is still under development and its behaviors will change, proceed at your own risk\n");
- if (nr_opts != 1) {
- pr_err("sane_behavior: no other mount options allowed\n");
- return -EINVAL;
- }
- return 0;
- }
-
/*
* If the 'all' option was specified select all the subsystems,
* otherwise if 'none', 'name=' and a subsystem name options were
@@ -1765,6 +1753,17 @@ static struct dentry *cgroup_mount(struc
if (!use_task_css_set_links)
cgroup_enable_task_cg_lists();

+ if (fs_type == &cgroup2_fs_type) {
+ if (data) {
+ pr_err("cgroup2: unknown option \"%s\"\n", (char *)data);
+ return ERR_PTR(-EINVAL);
+ }
+ cgrp_dfl_root_visible = true;
+ root = &cgrp_dfl_root;
+ cgroup_get(&root->cgrp);
+ goto out_mount;
+ }
+
mutex_lock(&cgroup_mutex);

/* First find the desired set of subsystems */
@@ -1772,15 +1771,6 @@ static struct dentry *cgroup_mount(struc
if (ret)
goto out_unlock;

- /* look for a matching existing root */
- if (opts.flags & CGRP_ROOT_SANE_BEHAVIOR) {
- cgrp_dfl_root_visible = true;
- root = &cgrp_dfl_root;
- cgroup_get(&root->cgrp);
- ret = 0;
- goto out_unlock;
- }
-
/*
* Destruction of cgroup root is asynchronous, so subsystems may
* still be dying after the previous unmount. Let's drain the
@@ -1891,7 +1881,7 @@ out_free:

if (ret)
return ERR_PTR(ret);
-
+out_mount:
dentry = kernfs_mount(fs_type, flags, root->kf_root,
CGROUP_SUPER_MAGIC, &new_sb);
if (IS_ERR(dentry) || !new_sb)
@@ -1936,6 +1926,12 @@ static struct file_system_type cgroup_fs
.kill_sb = cgroup_kill_sb,
};

+static struct file_system_type cgroup2_fs_type = {
+ .name = "cgroup2",
+ .mount = cgroup_mount,
+ .kill_sb = cgroup_kill_sb,
+};
+
/**
* task_cgroup_path - cgroup path of a task in the first cgroup hierarchy
* @task: target task
@@ -5056,6 +5052,7 @@ int __init cgroup_init(void)

WARN_ON(sysfs_create_mount_point(fs_kobj, "cgroup"));
WARN_ON(register_filesystem(&cgroup_fs_type));
+ WARN_ON(register_filesystem(&cgroup2_fs_type));
WARN_ON(!proc_create("cgroups", 0, NULL, &proc_cgroupstats_operations));

return 0;

2015-08-10 10:20:47

by Zefan Li

[permalink] [raw]
Subject: Re: [PATCH cgroup/for-4.3 1/3] cgroup: replace error handling in cgroup_init() with WARN_ON()s

On 2015/8/6 1:20, Tejun Heo wrote:
> The init sequence shouldn't fail short of bugs and even when it does
> it's better to continue with the rest of initialization and we were
> silently ignoring /proc/cgroups creation failure.
>
> Drop the explicit error handling and wrap sysfs_create_mount_point(),
> register_filesystem() and proc_create() with WARN_ON()s.
>
> Signed-off-by: Tejun Heo <[email protected]>
> Cc: Li Zefan <[email protected]>
> Cc: Johannes Weiner <[email protected]>

acked

2015-08-10 10:20:22

by Zefan Li

[permalink] [raw]
Subject: Re: [PATCH cgroup/for-4.3 3/3] cgroup: replace __DEVEL__sane_behavior with cgroup2 fs type

On 2015/8/6 1:21, Tejun Heo wrote:
> With major controllers - cpu, memory and io - shaping up for the
> unified hierarchy, cgroup2 is about ready to be, gradually, released
> into the wild. Replace __DEVEL__sane_behavior flag which was used to
> select the unified hierarchy with a separate filesystem type "cgroup2"
> so that unified hierarchy can be mounted as follows.
>
> mount -t cgroup2 none $MOUNT_POINT
>
> Signed-off-by: Tejun Heo <[email protected]>
> Cc: Li Zefan <[email protected]>
> Cc: Johannes Weiner <[email protected]>

acked