Skip to content

Commit 47dfe40

Browse files
committed
Merge branch 'for-3.17' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup
Pull cgroup changes from Tejun Heo: "Mostly changes to get the v2 interface ready. The core features are mostly ready now and I think it's reasonable to expect to drop the devel mask in one or two devel cycles at least for a subset of controllers. - cgroup added a controller dependency mechanism so that block cgroup can depend on memory cgroup. This will be used to finally support IO provisioning on the writeback traffic, which is currently being implemented. - The v2 interface now uses a separate table so that the interface files for the new interface are explicitly declared in one place. Each controller will explicitly review and add the files for the new interface. - cpuset is getting ready for the hierarchical behavior which is in the similar style with other controllers so that an ancestor's configuration change doesn't change the descendants' configurations irreversibly and processes aren't silently migrated when a CPU or node goes down. All the changes are to the new interface and no behavior changed for the multiple hierarchies" * 'for-3.17' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup: (29 commits) cpuset: fix the WARN_ON() in update_nodemasks_hier() cgroup: initialize cgrp_dfl_root_inhibit_ss_mask from !->dfl_files test cgroup: make CFTYPE_ONLY_ON_DFL and CFTYPE_NO_ internal to cgroup core cgroup: distinguish the default and legacy hierarchies when handling cftypes cgroup: replace cgroup_add_cftypes() with cgroup_add_legacy_cftypes() cgroup: rename cgroup_subsys->base_cftypes to ->legacy_cftypes cgroup: split cgroup_base_files[] into cgroup_{dfl|legacy}_base_files[] cpuset: export effective masks to userspace cpuset: allow writing offlined masks to cpuset.cpus/mems cpuset: enable onlined cpu/node in effective masks cpuset: refactor cpuset_hotplug_update_tasks() cpuset: make cs->{cpus, mems}_allowed as user-configured masks cpuset: apply cs->effective_{cpus,mems} cpuset: initialize top_cpuset's configured masks at mount cpuset: use effective cpumask to build sched domains cpuset: inherit ancestor's masks if effective_{cpus, mems} becomes empty cpuset: update cs->effective_{cpus, mems} when config changes cpuset: update cpuset->effective_{cpus,mems} at hotplug cpuset: add cs->effective_cpus and cs->effective_mems cgroup: clean up sane_behavior handling ...
2 parents f2a8417 + a138126 commit 47dfe40

16 files changed

Lines changed: 806 additions & 436 deletions

File tree

‎Documentation/cgroups/cgroups.txt‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,20 @@ fork. If this method returns 0 (success) then this should remain valid
599599
while the caller holds cgroup_mutex and it is ensured that either
600600
attach() or cancel_attach() will be called in future.
601601

602+
void css_reset(struct cgroup_subsys_state *css)
603+
(cgroup_mutex held by caller)
604+
605+
An optional operation which should restore @css's configuration to the
606+
initial state. This is currently only used on the unified hierarchy
607+
when a subsystem is disabled on a cgroup through
608+
"cgroup.subtree_control" but should remain enabled because other
609+
subsystems depend on it. cgroup core makes such a css invisible by
610+
removing the associated interface files and invokes this callback so
611+
that the hidden subsystem can return to the initial neutral state.
612+
This prevents unexpected resource control from a hidden css and
613+
ensures that the configuration is in the initial state when it is made
614+
visible again later.
615+
602616
void cancel_attach(struct cgroup *cgrp, struct cgroup_taskset *tset)
603617
(cgroup_mutex held by caller)
604618

‎Documentation/cgroups/unified-hierarchy.txt‎

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,35 @@ change soon.
9494

9595
mount -t cgroup -o __DEVEL__sane_behavior cgroup $MOUNT_POINT
9696

97-
All controllers which are not bound to other hierarchies are
98-
automatically bound to unified hierarchy and show up at the root of
99-
it. Controllers which are enabled only in the root of unified
100-
hierarchy can be bound to other hierarchies at any time. This allows
101-
mixing unified hierarchy with the traditional multiple hierarchies in
102-
a fully backward compatible way.
97+
All controllers which support the unified hierarchy and are not bound
98+
to other hierarchies are automatically bound to unified hierarchy and
99+
show up at the root of it. Controllers which are enabled only in the
100+
root of unified hierarchy can be bound to other hierarchies. This
101+
allows mixing unified hierarchy with the traditional multiple
102+
hierarchies in a fully backward compatible way.
103+
104+
For development purposes, the following boot parameter makes all
105+
controllers to appear on the unified hierarchy whether supported or
106+
not.
107+
108+
cgroup__DEVEL__legacy_files_on_dfl
109+
110+
A controller can be moved across hierarchies only after the controller
111+
is no longer referenced in its current hierarchy. Because per-cgroup
112+
controller states are destroyed asynchronously and controllers may
113+
have lingering references, a controller may not show up immediately on
114+
the unified hierarchy after the final umount of the previous
115+
hierarchy. Similarly, a controller should be fully disabled to be
116+
moved out of the unified hierarchy and it may take some time for the
117+
disabled controller to become available for other hierarchies;
118+
furthermore, due to dependencies among controllers, other controllers
119+
may need to be disabled too.
120+
121+
While useful for development and manual configurations, dynamically
122+
moving controllers between the unified and other hierarchies is
123+
strongly discouraged for production use. It is recommended to decide
124+
the hierarchies and controller associations before starting using the
125+
controllers.
103126

104127

105128
2-2. cgroup.subtree_control

‎block/blk-cgroup.c‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,15 @@ struct cgroup_subsys blkio_cgrp_subsys = {
928928
.css_offline = blkcg_css_offline,
929929
.css_free = blkcg_css_free,
930930
.can_attach = blkcg_can_attach,
931-
.base_cftypes = blkcg_files,
931+
.legacy_cftypes = blkcg_files,
932+
#ifdef CONFIG_MEMCG
933+
/*
934+
* This ensures that, if available, memcg is automatically enabled
935+
* together on the default hierarchy so that the owner cgroup can
936+
* be retrieved from writeback pages.
937+
*/
938+
.depends_on = 1 << memory_cgrp_id,
939+
#endif
932940
};
933941
EXPORT_SYMBOL_GPL(blkio_cgrp_subsys);
934942

@@ -1120,7 +1128,8 @@ int blkcg_policy_register(struct blkcg_policy *pol)
11201128

11211129
/* everything is in place, add intf files for the new policy */
11221130
if (pol->cftypes)
1123-
WARN_ON(cgroup_add_cftypes(&blkio_cgrp_subsys, pol->cftypes));
1131+
WARN_ON(cgroup_add_legacy_cftypes(&blkio_cgrp_subsys,
1132+
pol->cftypes));
11241133
ret = 0;
11251134
out_unlock:
11261135
mutex_unlock(&blkcg_pol_mutex);

‎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: 85 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,15 @@ struct cgroup {
203203
struct kernfs_node *kn; /* cgroup kernfs entry */
204204
struct kernfs_node *populated_kn; /* kn for "cgroup.subtree_populated" */
205205

206-
/* the bitmask of subsystems enabled on the child cgroups */
206+
/*
207+
* The bitmask of subsystems enabled on the child cgroups.
208+
* ->subtree_control is the one configured through
209+
* "cgroup.subtree_control" while ->child_subsys_mask is the
210+
* effective one which may have more subsystems enabled.
211+
* Controller knobs are made available iff it's enabled in
212+
* ->subtree_control.
213+
*/
214+
unsigned int subtree_control;
207215
unsigned int child_subsys_mask;
208216

209217
/* Private pointers for each registered subsystem */
@@ -248,73 +256,9 @@ struct cgroup {
248256

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

320264
/*
@@ -440,9 +384,11 @@ struct css_set {
440384
enum {
441385
CFTYPE_ONLY_ON_ROOT = (1 << 0), /* only create on root cgrp */
442386
CFTYPE_NOT_ON_ROOT = (1 << 1), /* don't create on root cgrp */
443-
CFTYPE_INSANE = (1 << 2), /* don't create if sane_behavior */
444387
CFTYPE_NO_PREFIX = (1 << 3), /* (DON'T USE FOR NEW FILES) no subsys prefix */
445-
CFTYPE_ONLY_ON_DFL = (1 << 4), /* only on default hierarchy */
388+
389+
/* internal flags, do not use outside cgroup core proper */
390+
__CFTYPE_ONLY_ON_DFL = (1 << 16), /* only on default hierarchy */
391+
__CFTYPE_NOT_ON_DFL = (1 << 17), /* not on default hierarchy */
446392
};
447393

448394
#define MAX_CFTYPE_NAME 64
@@ -526,20 +472,64 @@ struct cftype {
526472
extern struct cgroup_root cgrp_dfl_root;
527473
extern struct css_set init_css_set;
528474

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

534-
/*
535-
* See the comment above CGRP_ROOT_SANE_BEHAVIOR for details. This
536-
* function can be called as long as @cgrp is accessible.
537-
*/
538-
static inline bool cgroup_sane_behavior(const struct cgroup *cgrp)
539-
{
540-
return cgrp->root->flags & CGRP_ROOT_SANE_BEHAVIOR;
541-
}
542-
543533
/* no synchronization, the result can only be used as a hint */
544534
static inline bool cgroup_has_tasks(struct cgroup *cgrp)
545535
{
@@ -602,7 +592,8 @@ static inline void pr_cont_cgroup_path(struct cgroup *cgrp)
602592

603593
char *task_cgroup_path(struct task_struct *task, char *buf, size_t buflen);
604594

605-
int cgroup_add_cftypes(struct cgroup_subsys *ss, struct cftype *cfts);
595+
int cgroup_add_dfl_cftypes(struct cgroup_subsys *ss, struct cftype *cfts);
596+
int cgroup_add_legacy_cftypes(struct cgroup_subsys *ss, struct cftype *cfts);
606597
int cgroup_rm_cftypes(struct cftype *cfts);
607598

608599
bool cgroup_is_descendant(struct cgroup *cgrp, struct cgroup *ancestor);
@@ -634,6 +625,7 @@ struct cgroup_subsys {
634625
int (*css_online)(struct cgroup_subsys_state *css);
635626
void (*css_offline)(struct cgroup_subsys_state *css);
636627
void (*css_free)(struct cgroup_subsys_state *css);
628+
void (*css_reset)(struct cgroup_subsys_state *css);
637629

638630
int (*can_attach)(struct cgroup_subsys_state *css,
639631
struct cgroup_taskset *tset);
@@ -682,8 +674,21 @@ struct cgroup_subsys {
682674
*/
683675
struct list_head cfts;
684676

685-
/* base cftypes, automatically registered with subsys itself */
686-
struct cftype *base_cftypes;
677+
/*
678+
* Base cftypes which are automatically registered. The two can
679+
* point to the same array.
680+
*/
681+
struct cftype *dfl_cftypes; /* for the default hierarchy */
682+
struct cftype *legacy_cftypes; /* for the legacy hierarchies */
683+
684+
/*
685+
* A subsystem may depend on other subsystems. When such subsystem
686+
* is enabled on a cgroup, the depended-upon subsystems are enabled
687+
* together if available. Subsystems enabled due to dependency are
688+
* not visible to userland until explicitly enabled. The following
689+
* specifies the mask of subsystems that this one depends on.
690+
*/
691+
unsigned int depends_on;
687692
};
688693

689694
#define SUBSYS(_x) extern struct cgroup_subsys _x ## _cgrp_subsys;

0 commit comments

Comments
 (0)