Skip to content

Commit cd5367a

Browse files
htejunAlex Shi
authored andcommitted
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 The cgroup2 fs has its own magic number - 0x63677270 ("cgrp"). v2: Assign a different magic number to cgroup2 fs. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Li Zefan <lizefan@huawei.com> Cc: Johannes Weiner <hannes@cmpxchg.org> (cherry picked from commit 67e9c74b8a873408c27ac9a8e4c1d1c8d72c93ff) Signed-off-by: Alex Shi <alex.shi@linaro.org>
1 parent 1f565de commit cd5367a

4 files changed

Lines changed: 26 additions & 29 deletions

File tree

Documentation/cgroups/unified-hierarchy.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,9 @@ the process.
9494

9595
2-1. Mounting
9696

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

101-
mount -t cgroup -o __DEVEL__sane_behavior cgroup $MOUNT_POINT
99+
mount -t cgroup2 none $MOUNT_POINT
102100

103101
All controllers which support the unified hierarchy and are not bound
104102
to other hierarchies are automatically bound to unified hierarchy and

include/linux/cgroup-defs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ enum {
6666

6767
/* cgroup_root->flags */
6868
enum {
69-
CGRP_ROOT_SANE_BEHAVIOR = (1 << 0), /* __DEVEL__sane_behavior specified */
7069
CGRP_ROOT_NOPREFIX = (1 << 1), /* mounted subsystems have no named prefix */
7170
CGRP_ROOT_XATTR = (1 << 2), /* supports extended attributes */
7271
};

include/uapi/linux/magic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454

5555
#define SMB_SUPER_MAGIC 0x517B
5656
#define CGROUP_SUPER_MAGIC 0x27e0eb
57+
#define CGROUP2_SUPER_MAGIC 0x63677270
5758

5859

5960
#define STACK_END_MAGIC 0x57AC6E9D

kernel/cgroup.c

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ static unsigned long have_free_callback __read_mostly;
211211
/* Ditto for the can_fork callback. */
212212
static unsigned long have_canfork_callback __read_mostly;
213213

214+
static struct file_system_type cgroup2_fs_type;
214215
static struct cftype cgroup_dfl_base_files[];
215216
static struct cftype cgroup_legacy_base_files[];
216217

@@ -1650,10 +1651,6 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)
16501651
all_ss = true;
16511652
continue;
16521653
}
1653-
if (!strcmp(token, "__DEVEL__sane_behavior")) {
1654-
opts->flags |= CGRP_ROOT_SANE_BEHAVIOR;
1655-
continue;
1656-
}
16571654
if (!strcmp(token, "noprefix")) {
16581655
opts->flags |= CGRP_ROOT_NOPREFIX;
16591656
continue;
@@ -1720,15 +1717,6 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)
17201717
return -ENOENT;
17211718
}
17221719

1723-
if (opts->flags & CGRP_ROOT_SANE_BEHAVIOR) {
1724-
pr_warn("sane_behavior: this is still under development and its behaviors will change, proceed at your own risk\n");
1725-
if (nr_opts != 1) {
1726-
pr_err("sane_behavior: no other mount options allowed\n");
1727-
return -EINVAL;
1728-
}
1729-
return 0;
1730-
}
1731-
17321720
/*
17331721
* If the 'all' option was specified select all the subsystems,
17341722
* otherwise if 'none', 'name=' and a subsystem name options were
@@ -2007,6 +1995,7 @@ static struct dentry *cgroup_mount(struct file_system_type *fs_type,
20071995
int flags, const char *unused_dev_name,
20081996
void *data)
20091997
{
1998+
bool is_v2 = fs_type == &cgroup2_fs_type;
20101999
struct super_block *pinned_sb = NULL;
20112000
struct cgroup_subsys *ss;
20122001
struct cgroup_root *root;
@@ -2023,22 +2012,24 @@ static struct dentry *cgroup_mount(struct file_system_type *fs_type,
20232012
if (!use_task_css_set_links)
20242013
cgroup_enable_task_cg_lists();
20252014

2015+
if (is_v2) {
2016+
if (data) {
2017+
pr_err("cgroup2: unknown option \"%s\"\n", (char *)data);
2018+
return ERR_PTR(-EINVAL);
2019+
}
2020+
cgrp_dfl_root_visible = true;
2021+
root = &cgrp_dfl_root;
2022+
cgroup_get(&root->cgrp);
2023+
goto out_mount;
2024+
}
2025+
20262026
mutex_lock(&cgroup_mutex);
20272027

20282028
/* First find the desired set of subsystems */
20292029
ret = parse_cgroupfs_options(data, &opts);
20302030
if (ret)
20312031
goto out_unlock;
20322032

2033-
/* look for a matching existing root */
2034-
if (opts.flags & CGRP_ROOT_SANE_BEHAVIOR) {
2035-
cgrp_dfl_root_visible = true;
2036-
root = &cgrp_dfl_root;
2037-
cgroup_get(&root->cgrp);
2038-
ret = 0;
2039-
goto out_unlock;
2040-
}
2041-
20422033
/*
20432034
* Destruction of cgroup root is asynchronous, so subsystems may
20442035
* still be dying after the previous unmount. Let's drain the
@@ -2149,9 +2140,10 @@ static struct dentry *cgroup_mount(struct file_system_type *fs_type,
21492140

21502141
if (ret)
21512142
return ERR_PTR(ret);
2152-
2143+
out_mount:
21532144
dentry = kernfs_mount(fs_type, flags, root->kf_root,
2154-
CGROUP_SUPER_MAGIC, &new_sb);
2145+
is_v2 ? CGROUP2_SUPER_MAGIC : CGROUP_SUPER_MAGIC,
2146+
&new_sb);
21552147
if (IS_ERR(dentry) || !new_sb)
21562148
cgroup_put(&root->cgrp);
21572149

@@ -2194,6 +2186,12 @@ static struct file_system_type cgroup_fs_type = {
21942186
.kill_sb = cgroup_kill_sb,
21952187
};
21962188

2189+
static struct file_system_type cgroup2_fs_type = {
2190+
.name = "cgroup2",
2191+
.mount = cgroup_mount,
2192+
.kill_sb = cgroup_kill_sb,
2193+
};
2194+
21972195
/**
21982196
* task_cgroup_path - cgroup path of a task in the first cgroup hierarchy
21992197
* @task: target task
@@ -5383,6 +5381,7 @@ int __init cgroup_init(void)
53835381

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

53885387
return 0;

0 commit comments

Comments
 (0)