Skip to content

Commit aa6ec29

Browse files
committed
cgroup: remove sane_behavior support on non-default hierarchies
sane_behavior has been used as a development vehicle for the default unified hierarchy. Now that the default hierarchy is in place, the flag became redundant and confusing as its usage is allowed on all hierarchies. There are gonna be either the default hierarchy or legacy ones. Let's make that clear by removing sane_behavior support on non-default hierarchies. This patch replaces cgroup_sane_behavior() with cgroup_on_dfl(). The comment on top of CGRP_ROOT_SANE_BEHAVIOR is moved to on top of cgroup_on_dfl() with sane_behavior specific part dropped. On the default and legacy hierarchies w/o sane_behavior, this shouldn't cause any behavior differences. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Vivek Goyal <vgoyal@redhat.com> Acked-by: Li Zefan <lizefan@huawei.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Michal Hocko <mhocko@suse.cz>
1 parent c1d5d42 commit aa6ec29

5 files changed

Lines changed: 86 additions & 104 deletions

File tree

‎block/blk-throttle.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,21 +412,21 @@ static void throtl_pd_init(struct blkcg_gq *blkg)
412412
int rw;
413413

414414
/*
415-
* If sane_hierarchy is enabled, we switch to properly hierarchical
415+
* If on the default hierarchy, we switch to properly hierarchical
416416
* behavior where limits on a given throtl_grp are applied to the
417417
* whole subtree rather than just the group itself. e.g. If 16M
418418
* read_bps limit is set on the root group, the whole system can't
419419
* exceed 16M for the device.
420420
*
421-
* If sane_hierarchy is not enabled, the broken flat hierarchy
421+
* If not on the default hierarchy, the broken flat hierarchy
422422
* behavior is retained where all throtl_grps are treated as if
423423
* they're all separate root groups right below throtl_data.
424424
* Limits of a group don't interact with limits of other groups
425425
* regardless of the position of the group in the hierarchy.
426426
*/
427427
parent_sq = &td->service_queue;
428428

429-
if (cgroup_sane_behavior(blkg->blkcg->css.cgroup) && blkg->parent)
429+
if (cgroup_on_dfl(blkg->blkcg->css.cgroup) && blkg->parent)
430430
parent_sq = &blkg_to_tg(blkg->parent)->service_queue;
431431

432432
throtl_service_queue_init(&tg->service_queue, parent_sq);

‎include/linux/cgroup.h‎

Lines changed: 54 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -256,68 +256,7 @@ struct cgroup {
256256

257257
/* cgroup_root->flags */
258258
enum {
259-
/*
260-
* Unfortunately, cgroup core and various controllers are riddled
261-
* with idiosyncrasies and pointless options. The following flag,
262-
* when set, will force sane behavior - some options are forced on,
263-
* others are disallowed, and some controllers will change their
264-
* hierarchical or other behaviors.
265-
*
266-
* The set of behaviors affected by this flag are still being
267-
* determined and developed and the mount option for this flag is
268-
* prefixed with __DEVEL__. The prefix will be dropped once we
269-
* reach the point where all behaviors are compatible with the
270-
* planned unified hierarchy, which will automatically turn on this
271-
* flag.
272-
*
273-
* The followings are the behaviors currently affected this flag.
274-
*
275-
* - Mount options "noprefix", "xattr", "clone_children",
276-
* "release_agent" and "name" are disallowed.
277-
*
278-
* - When mounting an existing superblock, mount options should
279-
* match.
280-
*
281-
* - Remount is disallowed.
282-
*
283-
* - rename(2) is disallowed.
284-
*
285-
* - "tasks" is removed. Everything should be at process
286-
* granularity. Use "cgroup.procs" instead.
287-
*
288-
* - "cgroup.procs" is not sorted. pids will be unique unless they
289-
* got recycled inbetween reads.
290-
*
291-
* - "release_agent" and "notify_on_release" are removed.
292-
* Replacement notification mechanism will be implemented.
293-
*
294-
* - "cgroup.clone_children" is removed.
295-
*
296-
* - "cgroup.subtree_populated" is available. Its value is 0 if
297-
* the cgroup and its descendants contain no task; otherwise, 1.
298-
* The file also generates kernfs notification which can be
299-
* monitored through poll and [di]notify when the value of the
300-
* file changes.
301-
*
302-
* - If mount is requested with sane_behavior but without any
303-
* subsystem, the default unified hierarchy is mounted.
304-
*
305-
* - cpuset: tasks will be kept in empty cpusets when hotplug happens
306-
* and take masks of ancestors with non-empty cpus/mems, instead of
307-
* being moved to an ancestor.
308-
*
309-
* - cpuset: a task can be moved into an empty cpuset, and again it
310-
* takes masks of ancestors.
311-
*
312-
* - memcg: use_hierarchy is on by default and the cgroup file for
313-
* the flag is not created.
314-
*
315-
* - blkcg: blk-throttle becomes properly hierarchical.
316-
*
317-
* - debug: disallowed on the default hierarchy.
318-
*/
319-
CGRP_ROOT_SANE_BEHAVIOR = (1 << 0),
320-
259+
CGRP_ROOT_SANE_BEHAVIOR = (1 << 0), /* __DEVEL__sane_behavior specified */
321260
CGRP_ROOT_NOPREFIX = (1 << 1), /* mounted subsystems have no named prefix */
322261
CGRP_ROOT_XATTR = (1 << 2), /* supports extended attributes */
323262
};
@@ -531,20 +470,64 @@ struct cftype {
531470
extern struct cgroup_root cgrp_dfl_root;
532471
extern struct css_set init_css_set;
533472

473+
/**
474+
* cgroup_on_dfl - test whether a cgroup is on the default hierarchy
475+
* @cgrp: the cgroup of interest
476+
*
477+
* The default hierarchy is the v2 interface of cgroup and this function
478+
* can be used to test whether a cgroup is on the default hierarchy for
479+
* cases where a subsystem should behave differnetly depending on the
480+
* interface version.
481+
*
482+
* The set of behaviors which change on the default hierarchy are still
483+
* being determined and the mount option is prefixed with __DEVEL__.
484+
*
485+
* List of changed behaviors:
486+
*
487+
* - Mount options "noprefix", "xattr", "clone_children", "release_agent"
488+
* and "name" are disallowed.
489+
*
490+
* - When mounting an existing superblock, mount options should match.
491+
*
492+
* - Remount is disallowed.
493+
*
494+
* - rename(2) is disallowed.
495+
*
496+
* - "tasks" is removed. Everything should be at process granularity. Use
497+
* "cgroup.procs" instead.
498+
*
499+
* - "cgroup.procs" is not sorted. pids will be unique unless they got
500+
* recycled inbetween reads.
501+
*
502+
* - "release_agent" and "notify_on_release" are removed. Replacement
503+
* notification mechanism will be implemented.
504+
*
505+
* - "cgroup.clone_children" is removed.
506+
*
507+
* - "cgroup.subtree_populated" is available. Its value is 0 if the cgroup
508+
* and its descendants contain no task; otherwise, 1. The file also
509+
* generates kernfs notification which can be monitored through poll and
510+
* [di]notify when the value of the file changes.
511+
*
512+
* - cpuset: tasks will be kept in empty cpusets when hotplug happens and
513+
* take masks of ancestors with non-empty cpus/mems, instead of being
514+
* moved to an ancestor.
515+
*
516+
* - cpuset: a task can be moved into an empty cpuset, and again it takes
517+
* masks of ancestors.
518+
*
519+
* - memcg: use_hierarchy is on by default and the cgroup file for the flag
520+
* is not created.
521+
*
522+
* - blkcg: blk-throttle becomes properly hierarchical.
523+
*
524+
* - debug: disallowed on the default hierarchy.
525+
*/
534526
static inline bool cgroup_on_dfl(const struct cgroup *cgrp)
535527
{
536528
return cgrp->root == &cgrp_dfl_root;
537529
}
538530

539-
/*
540-
* See the comment above CGRP_ROOT_SANE_BEHAVIOR for details. This
541-
* function can be called as long as @cgrp is accessible.
542-
*/
543-
static inline bool cgroup_sane_behavior(const struct cgroup *cgrp)
544-
{
545-
return cgrp->root->flags & CGRP_ROOT_SANE_BEHAVIOR;
546-
}
547-
548531
/* no synchronization, the result can only be used as a hint */
549532
static inline bool cgroup_has_tasks(struct cgroup *cgrp)
550533
{

‎kernel/cgroup.c‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,8 +1470,8 @@ static int cgroup_remount(struct kernfs_root *kf_root, int *flags, char *data)
14701470
struct cgroup_sb_opts opts;
14711471
unsigned int added_mask, removed_mask;
14721472

1473-
if (root->flags & CGRP_ROOT_SANE_BEHAVIOR) {
1474-
pr_err("sane_behavior: remount is not allowed\n");
1473+
if (root == &cgrp_dfl_root) {
1474+
pr_err("remount is not allowed\n");
14751475
return -EINVAL;
14761476
}
14771477

@@ -2943,9 +2943,9 @@ static int cgroup_rename(struct kernfs_node *kn, struct kernfs_node *new_parent,
29432943

29442944
/*
29452945
* This isn't a proper migration and its usefulness is very
2946-
* limited. Disallow if sane_behavior.
2946+
* limited. Disallow on the default hierarchy.
29472947
*/
2948-
if (cgroup_sane_behavior(cgrp))
2948+
if (cgroup_on_dfl(cgrp))
29492949
return -EPERM;
29502950

29512951
/*
@@ -3031,7 +3031,7 @@ static int cgroup_addrm_files(struct cgroup *cgrp, struct cftype cfts[],
30313031
/* does cft->flags tell us to skip this file on @cgrp? */
30323032
if ((cft->flags & CFTYPE_ONLY_ON_DFL) && !cgroup_on_dfl(cgrp))
30333033
continue;
3034-
if ((cft->flags & CFTYPE_INSANE) && cgroup_sane_behavior(cgrp))
3034+
if ((cft->flags & CFTYPE_INSANE) && cgroup_on_dfl(cgrp))
30353035
continue;
30363036
if ((cft->flags & CFTYPE_NOT_ON_ROOT) && !cgroup_parent(cgrp))
30373037
continue;
@@ -3764,8 +3764,9 @@ static int pidlist_uniq(pid_t *list, int length)
37643764
*
37653765
* All this extra complexity was caused by the original implementation
37663766
* committing to an entirely unnecessary property. In the long term, we
3767-
* want to do away with it. Explicitly scramble sort order if
3768-
* sane_behavior so that no such expectation exists in the new interface.
3767+
* want to do away with it. Explicitly scramble sort order if on the
3768+
* default hierarchy so that no such expectation exists in the new
3769+
* interface.
37693770
*
37703771
* Scrambling is done by swapping every two consecutive bits, which is
37713772
* non-identity one-to-one mapping which disturbs sort order sufficiently.
@@ -3780,7 +3781,7 @@ static pid_t pid_fry(pid_t pid)
37803781

37813782
static pid_t cgroup_pid_fry(struct cgroup *cgrp, pid_t pid)
37823783
{
3783-
if (cgroup_sane_behavior(cgrp))
3784+
if (cgroup_on_dfl(cgrp))
37843785
return pid_fry(pid);
37853786
else
37863787
return pid;
@@ -3883,7 +3884,7 @@ static int pidlist_array_load(struct cgroup *cgrp, enum cgroup_filetype type,
38833884
css_task_iter_end(&it);
38843885
length = n;
38853886
/* now sort & (if procs) strip out duplicates */
3886-
if (cgroup_sane_behavior(cgrp))
3887+
if (cgroup_on_dfl(cgrp))
38873888
sort(array, length, sizeof(pid_t), fried_cmppid, NULL);
38883889
else
38893890
sort(array, length, sizeof(pid_t), cmppid, NULL);

‎kernel/cpuset.c‎

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,12 +1383,9 @@ static int cpuset_can_attach(struct cgroup_subsys_state *css,
13831383

13841384
mutex_lock(&cpuset_mutex);
13851385

1386-
/*
1387-
* We allow to move tasks into an empty cpuset if sane_behavior
1388-
* flag is set.
1389-
*/
1386+
/* allow moving tasks into an empty cpuset if on default hierarchy */
13901387
ret = -ENOSPC;
1391-
if (!cgroup_sane_behavior(css->cgroup) &&
1388+
if (!cgroup_on_dfl(css->cgroup) &&
13921389
(cpumask_empty(cs->cpus_allowed) || nodes_empty(cs->mems_allowed)))
13931390
goto out_unlock;
13941391

@@ -2030,7 +2027,7 @@ static void cpuset_hotplug_update_tasks(struct cpuset *cs)
20302027
static cpumask_t off_cpus;
20312028
static nodemask_t off_mems;
20322029
bool is_empty;
2033-
bool sane = cgroup_sane_behavior(cs->css.cgroup);
2030+
bool on_dfl = cgroup_on_dfl(cs->css.cgroup);
20342031

20352032
retry:
20362033
wait_event(cpuset_attach_wq, cs->attach_in_progress == 0);
@@ -2054,12 +2051,12 @@ static void cpuset_hotplug_update_tasks(struct cpuset *cs)
20542051
mutex_unlock(&callback_mutex);
20552052

20562053
/*
2057-
* If sane_behavior flag is set, we need to update tasks' cpumask
2058-
* for empty cpuset to take on ancestor's cpumask. Otherwise, don't
2059-
* call update_tasks_cpumask() if the cpuset becomes empty, as
2060-
* the tasks in it will be migrated to an ancestor.
2054+
* If on_dfl, we need to update tasks' cpumask for empty cpuset to
2055+
* take on ancestor's cpumask. Otherwise, don't call
2056+
* update_tasks_cpumask() if the cpuset becomes empty, as the tasks
2057+
* in it will be migrated to an ancestor.
20612058
*/
2062-
if ((sane && cpumask_empty(cs->cpus_allowed)) ||
2059+
if ((on_dfl && cpumask_empty(cs->cpus_allowed)) ||
20632060
(!cpumask_empty(&off_cpus) && !cpumask_empty(cs->cpus_allowed)))
20642061
update_tasks_cpumask(cs);
20652062

@@ -2068,12 +2065,12 @@ static void cpuset_hotplug_update_tasks(struct cpuset *cs)
20682065
mutex_unlock(&callback_mutex);
20692066

20702067
/*
2071-
* If sane_behavior flag is set, we need to update tasks' nodemask
2072-
* for empty cpuset to take on ancestor's nodemask. Otherwise, don't
2073-
* call update_tasks_nodemask() if the cpuset becomes empty, as
2074-
* the tasks in it will be migratd to an ancestor.
2068+
* If on_dfl, we need to update tasks' nodemask for empty cpuset to
2069+
* take on ancestor's nodemask. Otherwise, don't call
2070+
* update_tasks_nodemask() if the cpuset becomes empty, as the
2071+
* tasks in it will be migratd to an ancestor.
20752072
*/
2076-
if ((sane && nodes_empty(cs->mems_allowed)) ||
2073+
if ((on_dfl && nodes_empty(cs->mems_allowed)) ||
20772074
(!nodes_empty(off_mems) && !nodes_empty(cs->mems_allowed)))
20782075
update_tasks_nodemask(cs);
20792076

@@ -2083,13 +2080,13 @@ static void cpuset_hotplug_update_tasks(struct cpuset *cs)
20832080
mutex_unlock(&cpuset_mutex);
20842081

20852082
/*
2086-
* If sane_behavior flag is set, we'll keep tasks in empty cpusets.
2083+
* If on_dfl, we'll keep tasks in empty cpusets.
20872084
*
20882085
* Otherwise move tasks to the nearest ancestor with execution
20892086
* resources. This is full cgroup operation which will
20902087
* also call back into cpuset. Should be done outside any lock.
20912088
*/
2092-
if (!sane && is_empty)
2089+
if (!on_dfl && is_empty)
20932090
remove_tasks_in_empty_cpuset(cs);
20942091
}
20952092

‎mm/memcontrol.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7024,16 +7024,17 @@ static void mem_cgroup_move_task(struct cgroup_subsys_state *css,
70247024

70257025
/*
70267026
* Cgroup retains root cgroups across [un]mount cycles making it necessary
7027-
* to verify sane_behavior flag on each mount attempt.
7027+
* to verify whether we're attached to the default hierarchy on each mount
7028+
* attempt.
70287029
*/
70297030
static void mem_cgroup_bind(struct cgroup_subsys_state *root_css)
70307031
{
70317032
/*
7032-
* use_hierarchy is forced with sane_behavior. cgroup core
7033+
* use_hierarchy is forced on the default hierarchy. cgroup core
70337034
* guarantees that @root doesn't have any children, so turning it
70347035
* on for the root memcg is enough.
70357036
*/
7036-
if (cgroup_sane_behavior(root_css->cgroup))
7037+
if (cgroup_on_dfl(root_css->cgroup))
70377038
mem_cgroup_from_css(root_css)->use_hierarchy = true;
70387039
}
70397040

0 commit comments

Comments
 (0)