diff options
Diffstat (limited to 'include/linux/cgroup.h')
| -rw-r--r-- | include/linux/cgroup.h | 165 |
1 files changed, 85 insertions, 80 deletions
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 8a111dd42d7a..b5223c570eba 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h | |||
| @@ -203,7 +203,15 @@ struct cgroup { | |||
| 203 | struct kernfs_node *kn; /* cgroup kernfs entry */ | 203 | struct kernfs_node *kn; /* cgroup kernfs entry */ |
| 204 | struct kernfs_node *populated_kn; /* kn for "cgroup.subtree_populated" */ | 204 | struct kernfs_node *populated_kn; /* kn for "cgroup.subtree_populated" */ |
| 205 | 205 | ||
| 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; | ||
| 207 | unsigned int child_subsys_mask; | 215 | unsigned int child_subsys_mask; |
| 208 | 216 | ||
| 209 | /* Private pointers for each registered subsystem */ | 217 | /* Private pointers for each registered subsystem */ |
| @@ -248,73 +256,9 @@ struct cgroup { | |||
| 248 | 256 | ||
| 249 | /* cgroup_root->flags */ | 257 | /* cgroup_root->flags */ |
| 250 | enum { | 258 | enum { |
| 251 | /* | 259 | CGRP_ROOT_SANE_BEHAVIOR = (1 << 0), /* __DEVEL__sane_behavior specified */ |
| 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 | |||
| 313 | CGRP_ROOT_NOPREFIX = (1 << 1), /* mounted subsystems have no named prefix */ | 260 | CGRP_ROOT_NOPREFIX = (1 << 1), /* mounted subsystems have no named prefix */ |
| 314 | CGRP_ROOT_XATTR = (1 << 2), /* supports extended attributes */ | 261 | CGRP_ROOT_XATTR = (1 << 2), /* supports extended attributes */ |
| 315 | |||
| 316 | /* mount options live below bit 16 */ | ||
| 317 | CGRP_ROOT_OPTION_MASK = (1 << 16) - 1, | ||
| 318 | }; | 262 | }; |
| 319 | 263 | ||
| 320 | /* | 264 | /* |
| @@ -440,9 +384,11 @@ struct css_set { | |||
| 440 | enum { | 384 | enum { |
| 441 | CFTYPE_ONLY_ON_ROOT = (1 << 0), /* only create on root cgrp */ | 385 | CFTYPE_ONLY_ON_ROOT = (1 << 0), /* only create on root cgrp */ |
| 442 | CFTYPE_NOT_ON_ROOT = (1 << 1), /* don't create on root cgrp */ | 386 | CFTYPE_NOT_ON_ROOT = (1 << 1), /* don't create on root cgrp */ |
| 443 | CFTYPE_INSANE = (1 << 2), /* don't create if sane_behavior */ | ||
| 444 | CFTYPE_NO_PREFIX = (1 << 3), /* (DON'T USE FOR NEW FILES) no subsys prefix */ | 387 | 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 */ | ||
| 446 | }; | 392 | }; |
| 447 | 393 | ||
| 448 | #define MAX_CFTYPE_NAME 64 | 394 | #define MAX_CFTYPE_NAME 64 |
| @@ -526,20 +472,64 @@ struct cftype { | |||
| 526 | extern struct cgroup_root cgrp_dfl_root; | 472 | extern struct cgroup_root cgrp_dfl_root; |
| 527 | extern struct css_set init_css_set; | 473 | extern struct css_set init_css_set; |
| 528 | 474 | ||
| 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 | */ | ||
| 529 | static inline bool cgroup_on_dfl(const struct cgroup *cgrp) | 528 | static inline bool cgroup_on_dfl(const struct cgroup *cgrp) |
| 530 | { | 529 | { |
| 531 | return cgrp->root == &cgrp_dfl_root; | 530 | return cgrp->root == &cgrp_dfl_root; |
| 532 | } | 531 | } |
| 533 | 532 | ||
| 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 | |||
| 543 | /* no synchronization, the result can only be used as a hint */ | 533 | /* no synchronization, the result can only be used as a hint */ |
| 544 | static inline bool cgroup_has_tasks(struct cgroup *cgrp) | 534 | static inline bool cgroup_has_tasks(struct cgroup *cgrp) |
| 545 | { | 535 | { |
| @@ -602,7 +592,8 @@ static inline void pr_cont_cgroup_path(struct cgroup *cgrp) | |||
| 602 | 592 | ||
| 603 | char *task_cgroup_path(struct task_struct *task, char *buf, size_t buflen); | 593 | char *task_cgroup_path(struct task_struct *task, char *buf, size_t buflen); |
| 604 | 594 | ||
| 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); | ||
| 606 | int cgroup_rm_cftypes(struct cftype *cfts); | 597 | int cgroup_rm_cftypes(struct cftype *cfts); |
| 607 | 598 | ||
| 608 | bool cgroup_is_descendant(struct cgroup *cgrp, struct cgroup *ancestor); | 599 | bool cgroup_is_descendant(struct cgroup *cgrp, struct cgroup *ancestor); |
| @@ -634,6 +625,7 @@ struct cgroup_subsys { | |||
| 634 | int (*css_online)(struct cgroup_subsys_state *css); | 625 | int (*css_online)(struct cgroup_subsys_state *css); |
| 635 | void (*css_offline)(struct cgroup_subsys_state *css); | 626 | void (*css_offline)(struct cgroup_subsys_state *css); |
| 636 | void (*css_free)(struct cgroup_subsys_state *css); | 627 | void (*css_free)(struct cgroup_subsys_state *css); |
| 628 | void (*css_reset)(struct cgroup_subsys_state *css); | ||
| 637 | 629 | ||
| 638 | int (*can_attach)(struct cgroup_subsys_state *css, | 630 | int (*can_attach)(struct cgroup_subsys_state *css, |
| 639 | struct cgroup_taskset *tset); | 631 | struct cgroup_taskset *tset); |
| @@ -682,8 +674,21 @@ struct cgroup_subsys { | |||
| 682 | */ | 674 | */ |
| 683 | struct list_head cfts; | 675 | struct list_head cfts; |
| 684 | 676 | ||
| 685 | /* base cftypes, automatically registered with subsys itself */ | 677 | /* |
| 686 | struct cftype *base_cftypes; | 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; | ||
| 687 | }; | 692 | }; |
| 688 | 693 | ||
| 689 | #define SUBSYS(_x) extern struct cgroup_subsys _x ## _cgrp_subsys; | 694 | #define SUBSYS(_x) extern struct cgroup_subsys _x ## _cgrp_subsys; |
