![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0 */ 0002 /* 0003 * linux/cgroup-defs.h - basic definitions for cgroup 0004 * 0005 * This file provides basic type and interface. Include this file directly 0006 * only if necessary to avoid cyclic dependencies. 0007 */ 0008 #ifndef _LINUX_CGROUP_DEFS_H 0009 #define _LINUX_CGROUP_DEFS_H 0010 0011 #include <linux/limits.h> 0012 #include <linux/list.h> 0013 #include <linux/idr.h> 0014 #include <linux/wait.h> 0015 #include <linux/mutex.h> 0016 #include <linux/rcupdate.h> 0017 #include <linux/refcount.h> 0018 #include <linux/percpu-refcount.h> 0019 #include <linux/percpu-rwsem.h> 0020 #include <linux/u64_stats_sync.h> 0021 #include <linux/workqueue.h> 0022 #include <linux/bpf-cgroup-defs.h> 0023 #include <linux/psi_types.h> 0024 0025 #ifdef CONFIG_CGROUPS 0026 0027 struct cgroup; 0028 struct cgroup_root; 0029 struct cgroup_subsys; 0030 struct cgroup_taskset; 0031 struct kernfs_node; 0032 struct kernfs_ops; 0033 struct kernfs_open_file; 0034 struct seq_file; 0035 struct poll_table_struct; 0036 0037 #define MAX_CGROUP_TYPE_NAMELEN 32 0038 #define MAX_CGROUP_ROOT_NAMELEN 64 0039 #define MAX_CFTYPE_NAME 64 0040 0041 /* define the enumeration of all cgroup subsystems */ 0042 #define SUBSYS(_x) _x ## _cgrp_id, 0043 enum cgroup_subsys_id { 0044 #include <linux/cgroup_subsys.h> 0045 CGROUP_SUBSYS_COUNT, 0046 }; 0047 #undef SUBSYS 0048 0049 /* bits in struct cgroup_subsys_state flags field */ 0050 enum { 0051 CSS_NO_REF = (1 << 0), /* no reference counting for this css */ 0052 CSS_ONLINE = (1 << 1), /* between ->css_online() and ->css_offline() */ 0053 CSS_RELEASED = (1 << 2), /* refcnt reached zero, released */ 0054 CSS_VISIBLE = (1 << 3), /* css is visible to userland */ 0055 CSS_DYING = (1 << 4), /* css is dying */ 0056 }; 0057 0058 /* bits in struct cgroup flags field */ 0059 enum { 0060 /* Control Group requires release notifications to userspace */ 0061 CGRP_NOTIFY_ON_RELEASE, 0062 /* 0063 * Clone the parent's configuration when creating a new child 0064 * cpuset cgroup. For historical reasons, this option can be 0065 * specified at mount time and thus is implemented here. 0066 */ 0067 CGRP_CPUSET_CLONE_CHILDREN, 0068 0069 /* Control group has to be frozen. */ 0070 CGRP_FREEZE, 0071 0072 /* Cgroup is frozen. */ 0073 CGRP_FROZEN, 0074 0075 /* Control group has to be killed. */ 0076 CGRP_KILL, 0077 }; 0078 0079 /* cgroup_root->flags */ 0080 enum { 0081 CGRP_ROOT_NOPREFIX = (1 << 1), /* mounted subsystems have no named prefix */ 0082 CGRP_ROOT_XATTR = (1 << 2), /* supports extended attributes */ 0083 0084 /* 0085 * Consider namespaces as delegation boundaries. If this flag is 0086 * set, controller specific interface files in a namespace root 0087 * aren't writeable from inside the namespace. 0088 */ 0089 CGRP_ROOT_NS_DELEGATE = (1 << 3), 0090 0091 /* 0092 * Reduce latencies on dynamic cgroup modifications such as task 0093 * migrations and controller on/offs by disabling percpu operation on 0094 * cgroup_threadgroup_rwsem. This makes hot path operations such as 0095 * forks and exits into the slow path and more expensive. 0096 * 0097 * The static usage pattern of creating a cgroup, enabling controllers, 0098 * and then seeding it with CLONE_INTO_CGROUP doesn't require write 0099 * locking cgroup_threadgroup_rwsem and thus doesn't benefit from 0100 * favordynmod. 0101 */ 0102 CGRP_ROOT_FAVOR_DYNMODS = (1 << 4), 0103 0104 /* 0105 * Enable cpuset controller in v1 cgroup to use v2 behavior. 0106 */ 0107 CGRP_ROOT_CPUSET_V2_MODE = (1 << 16), 0108 0109 /* 0110 * Enable legacy local memory.events. 0111 */ 0112 CGRP_ROOT_MEMORY_LOCAL_EVENTS = (1 << 17), 0113 0114 /* 0115 * Enable recursive subtree protection 0116 */ 0117 CGRP_ROOT_MEMORY_RECURSIVE_PROT = (1 << 18), 0118 }; 0119 0120 /* cftype->flags */ 0121 enum { 0122 CFTYPE_ONLY_ON_ROOT = (1 << 0), /* only create on root cgrp */ 0123 CFTYPE_NOT_ON_ROOT = (1 << 1), /* don't create on root cgrp */ 0124 CFTYPE_NS_DELEGATABLE = (1 << 2), /* writeable beyond delegation boundaries */ 0125 0126 CFTYPE_NO_PREFIX = (1 << 3), /* (DON'T USE FOR NEW FILES) no subsys prefix */ 0127 CFTYPE_WORLD_WRITABLE = (1 << 4), /* (DON'T USE FOR NEW FILES) S_IWUGO */ 0128 CFTYPE_DEBUG = (1 << 5), /* create when cgroup_debug */ 0129 CFTYPE_PRESSURE = (1 << 6), /* only if pressure feature is enabled */ 0130 0131 /* internal flags, do not use outside cgroup core proper */ 0132 __CFTYPE_ONLY_ON_DFL = (1 << 16), /* only on default hierarchy */ 0133 __CFTYPE_NOT_ON_DFL = (1 << 17), /* not on default hierarchy */ 0134 }; 0135 0136 /* 0137 * cgroup_file is the handle for a file instance created in a cgroup which 0138 * is used, for example, to generate file changed notifications. This can 0139 * be obtained by setting cftype->file_offset. 0140 */ 0141 struct cgroup_file { 0142 /* do not access any fields from outside cgroup core */ 0143 struct kernfs_node *kn; 0144 unsigned long notified_at; 0145 struct timer_list notify_timer; 0146 }; 0147 0148 /* 0149 * Per-subsystem/per-cgroup state maintained by the system. This is the 0150 * fundamental structural building block that controllers deal with. 0151 * 0152 * Fields marked with "PI:" are public and immutable and may be accessed 0153 * directly without synchronization. 0154 */ 0155 struct cgroup_subsys_state { 0156 /* PI: the cgroup that this css is attached to */ 0157 struct cgroup *cgroup; 0158 0159 /* PI: the cgroup subsystem that this css is attached to */ 0160 struct cgroup_subsys *ss; 0161 0162 /* reference count - access via css_[try]get() and css_put() */ 0163 struct percpu_ref refcnt; 0164 0165 /* siblings list anchored at the parent's ->children */ 0166 struct list_head sibling; 0167 struct list_head children; 0168 0169 /* flush target list anchored at cgrp->rstat_css_list */ 0170 struct list_head rstat_css_node; 0171 0172 /* 0173 * PI: Subsys-unique ID. 0 is unused and root is always 1. The 0174 * matching css can be looked up using css_from_id(). 0175 */ 0176 int id; 0177 0178 unsigned int flags; 0179 0180 /* 0181 * Monotonically increasing unique serial number which defines a 0182 * uniform order among all csses. It's guaranteed that all 0183 * ->children lists are in the ascending order of ->serial_nr and 0184 * used to allow interrupting and resuming iterations. 0185 */ 0186 u64 serial_nr; 0187 0188 /* 0189 * Incremented by online self and children. Used to guarantee that 0190 * parents are not offlined before their children. 0191 */ 0192 atomic_t online_cnt; 0193 0194 /* percpu_ref killing and RCU release */ 0195 struct work_struct destroy_work; 0196 struct rcu_work destroy_rwork; 0197 0198 /* 0199 * PI: the parent css. Placed here for cache proximity to following 0200 * fields of the containing structure. 0201 */ 0202 struct cgroup_subsys_state *parent; 0203 }; 0204 0205 /* 0206 * A css_set is a structure holding pointers to a set of 0207 * cgroup_subsys_state objects. This saves space in the task struct 0208 * object and speeds up fork()/exit(), since a single inc/dec and a 0209 * list_add()/del() can bump the reference count on the entire cgroup 0210 * set for a task. 0211 */ 0212 struct css_set { 0213 /* 0214 * Set of subsystem states, one for each subsystem. This array is 0215 * immutable after creation apart from the init_css_set during 0216 * subsystem registration (at boot time). 0217 */ 0218 struct cgroup_subsys_state *subsys[CGROUP_SUBSYS_COUNT]; 0219 0220 /* reference count */ 0221 refcount_t refcount; 0222 0223 /* 0224 * For a domain cgroup, the following points to self. If threaded, 0225 * to the matching cset of the nearest domain ancestor. The 0226 * dom_cset provides access to the domain cgroup and its csses to 0227 * which domain level resource consumptions should be charged. 0228 */ 0229 struct css_set *dom_cset; 0230 0231 /* the default cgroup associated with this css_set */ 0232 struct cgroup *dfl_cgrp; 0233 0234 /* internal task count, protected by css_set_lock */ 0235 int nr_tasks; 0236 0237 /* 0238 * Lists running through all tasks using this cgroup group. 0239 * mg_tasks lists tasks which belong to this cset but are in the 0240 * process of being migrated out or in. Protected by 0241 * css_set_rwsem, but, during migration, once tasks are moved to 0242 * mg_tasks, it can be read safely while holding cgroup_mutex. 0243 */ 0244 struct list_head tasks; 0245 struct list_head mg_tasks; 0246 struct list_head dying_tasks; 0247 0248 /* all css_task_iters currently walking this cset */ 0249 struct list_head task_iters; 0250 0251 /* 0252 * On the default hierarchy, ->subsys[ssid] may point to a css 0253 * attached to an ancestor instead of the cgroup this css_set is 0254 * associated with. The following node is anchored at 0255 * ->subsys[ssid]->cgroup->e_csets[ssid] and provides a way to 0256 * iterate through all css's attached to a given cgroup. 0257 */ 0258 struct list_head e_cset_node[CGROUP_SUBSYS_COUNT]; 0259 0260 /* all threaded csets whose ->dom_cset points to this cset */ 0261 struct list_head threaded_csets; 0262 struct list_head threaded_csets_node; 0263 0264 /* 0265 * List running through all cgroup groups in the same hash 0266 * slot. Protected by css_set_lock 0267 */ 0268 struct hlist_node hlist; 0269 0270 /* 0271 * List of cgrp_cset_links pointing at cgroups referenced from this 0272 * css_set. Protected by css_set_lock. 0273 */ 0274 struct list_head cgrp_links; 0275 0276 /* 0277 * List of csets participating in the on-going migration either as 0278 * source or destination. Protected by cgroup_mutex. 0279 */ 0280 struct list_head mg_src_preload_node; 0281 struct list_head mg_dst_preload_node; 0282 struct list_head mg_node; 0283 0284 /* 0285 * If this cset is acting as the source of migration the following 0286 * two fields are set. mg_src_cgrp and mg_dst_cgrp are 0287 * respectively the source and destination cgroups of the on-going 0288 * migration. mg_dst_cset is the destination cset the target tasks 0289 * on this cset should be migrated to. Protected by cgroup_mutex. 0290 */ 0291 struct cgroup *mg_src_cgrp; 0292 struct cgroup *mg_dst_cgrp; 0293 struct css_set *mg_dst_cset; 0294 0295 /* dead and being drained, ignore for migration */ 0296 bool dead; 0297 0298 /* For RCU-protected deletion */ 0299 struct rcu_head rcu_head; 0300 }; 0301 0302 struct cgroup_base_stat { 0303 struct task_cputime cputime; 0304 0305 #ifdef CONFIG_SCHED_CORE 0306 u64 forceidle_sum; 0307 #endif 0308 }; 0309 0310 /* 0311 * rstat - cgroup scalable recursive statistics. Accounting is done 0312 * per-cpu in cgroup_rstat_cpu which is then lazily propagated up the 0313 * hierarchy on reads. 0314 * 0315 * When a stat gets updated, the cgroup_rstat_cpu and its ancestors are 0316 * linked into the updated tree. On the following read, propagation only 0317 * considers and consumes the updated tree. This makes reading O(the 0318 * number of descendants which have been active since last read) instead of 0319 * O(the total number of descendants). 0320 * 0321 * This is important because there can be a lot of (draining) cgroups which 0322 * aren't active and stat may be read frequently. The combination can 0323 * become very expensive. By propagating selectively, increasing reading 0324 * frequency decreases the cost of each read. 0325 * 0326 * This struct hosts both the fields which implement the above - 0327 * updated_children and updated_next - and the fields which track basic 0328 * resource statistics on top of it - bsync, bstat and last_bstat. 0329 */ 0330 struct cgroup_rstat_cpu { 0331 /* 0332 * ->bsync protects ->bstat. These are the only fields which get 0333 * updated in the hot path. 0334 */ 0335 struct u64_stats_sync bsync; 0336 struct cgroup_base_stat bstat; 0337 0338 /* 0339 * Snapshots at the last reading. These are used to calculate the 0340 * deltas to propagate to the global counters. 0341 */ 0342 struct cgroup_base_stat last_bstat; 0343 0344 /* 0345 * Child cgroups with stat updates on this cpu since the last read 0346 * are linked on the parent's ->updated_children through 0347 * ->updated_next. 0348 * 0349 * In addition to being more compact, singly-linked list pointing 0350 * to the cgroup makes it unnecessary for each per-cpu struct to 0351 * point back to the associated cgroup. 0352 * 0353 * Protected by per-cpu cgroup_rstat_cpu_lock. 0354 */ 0355 struct cgroup *updated_children; /* terminated by self cgroup */ 0356 struct cgroup *updated_next; /* NULL iff not on the list */ 0357 }; 0358 0359 struct cgroup_freezer_state { 0360 /* Should the cgroup and its descendants be frozen. */ 0361 bool freeze; 0362 0363 /* Should the cgroup actually be frozen? */ 0364 int e_freeze; 0365 0366 /* Fields below are protected by css_set_lock */ 0367 0368 /* Number of frozen descendant cgroups */ 0369 int nr_frozen_descendants; 0370 0371 /* 0372 * Number of tasks, which are counted as frozen: 0373 * frozen, SIGSTOPped, and PTRACEd. 0374 */ 0375 int nr_frozen_tasks; 0376 }; 0377 0378 struct cgroup { 0379 /* self css with NULL ->ss, points back to this cgroup */ 0380 struct cgroup_subsys_state self; 0381 0382 unsigned long flags; /* "unsigned long" so bitops work */ 0383 0384 /* 0385 * The depth this cgroup is at. The root is at depth zero and each 0386 * step down the hierarchy increments the level. This along with 0387 * ancestor_ids[] can determine whether a given cgroup is a 0388 * descendant of another without traversing the hierarchy. 0389 */ 0390 int level; 0391 0392 /* Maximum allowed descent tree depth */ 0393 int max_depth; 0394 0395 /* 0396 * Keep track of total numbers of visible and dying descent cgroups. 0397 * Dying cgroups are cgroups which were deleted by a user, 0398 * but are still existing because someone else is holding a reference. 0399 * max_descendants is a maximum allowed number of descent cgroups. 0400 * 0401 * nr_descendants and nr_dying_descendants are protected 0402 * by cgroup_mutex and css_set_lock. It's fine to read them holding 0403 * any of cgroup_mutex and css_set_lock; for writing both locks 0404 * should be held. 0405 */ 0406 int nr_descendants; 0407 int nr_dying_descendants; 0408 int max_descendants; 0409 0410 /* 0411 * Each non-empty css_set associated with this cgroup contributes 0412 * one to nr_populated_csets. The counter is zero iff this cgroup 0413 * doesn't have any tasks. 0414 * 0415 * All children which have non-zero nr_populated_csets and/or 0416 * nr_populated_children of their own contribute one to either 0417 * nr_populated_domain_children or nr_populated_threaded_children 0418 * depending on their type. Each counter is zero iff all cgroups 0419 * of the type in the subtree proper don't have any tasks. 0420 */ 0421 int nr_populated_csets; 0422 int nr_populated_domain_children; 0423 int nr_populated_threaded_children; 0424 0425 int nr_threaded_children; /* # of live threaded child cgroups */ 0426 0427 struct kernfs_node *kn; /* cgroup kernfs entry */ 0428 struct cgroup_file procs_file; /* handle for "cgroup.procs" */ 0429 struct cgroup_file events_file; /* handle for "cgroup.events" */ 0430 0431 /* 0432 * The bitmask of subsystems enabled on the child cgroups. 0433 * ->subtree_control is the one configured through 0434 * "cgroup.subtree_control" while ->subtree_ss_mask is the effective 0435 * one which may have more subsystems enabled. Controller knobs 0436 * are made available iff it's enabled in ->subtree_control. 0437 */ 0438 u16 subtree_control; 0439 u16 subtree_ss_mask; 0440 u16 old_subtree_control; 0441 u16 old_subtree_ss_mask; 0442 0443 /* Private pointers for each registered subsystem */ 0444 struct cgroup_subsys_state __rcu *subsys[CGROUP_SUBSYS_COUNT]; 0445 0446 struct cgroup_root *root; 0447 0448 /* 0449 * List of cgrp_cset_links pointing at css_sets with tasks in this 0450 * cgroup. Protected by css_set_lock. 0451 */ 0452 struct list_head cset_links; 0453 0454 /* 0455 * On the default hierarchy, a css_set for a cgroup with some 0456 * susbsys disabled will point to css's which are associated with 0457 * the closest ancestor which has the subsys enabled. The 0458 * following lists all css_sets which point to this cgroup's css 0459 * for the given subsystem. 0460 */ 0461 struct list_head e_csets[CGROUP_SUBSYS_COUNT]; 0462 0463 /* 0464 * If !threaded, self. If threaded, it points to the nearest 0465 * domain ancestor. Inside a threaded subtree, cgroups are exempt 0466 * from process granularity and no-internal-task constraint. 0467 * Domain level resource consumptions which aren't tied to a 0468 * specific task are charged to the dom_cgrp. 0469 */ 0470 struct cgroup *dom_cgrp; 0471 struct cgroup *old_dom_cgrp; /* used while enabling threaded */ 0472 0473 /* per-cpu recursive resource statistics */ 0474 struct cgroup_rstat_cpu __percpu *rstat_cpu; 0475 struct list_head rstat_css_list; 0476 0477 /* cgroup basic resource statistics */ 0478 struct cgroup_base_stat last_bstat; 0479 struct cgroup_base_stat bstat; 0480 struct prev_cputime prev_cputime; /* for printing out cputime */ 0481 0482 /* 0483 * list of pidlists, up to two for each namespace (one for procs, one 0484 * for tasks); created on demand. 0485 */ 0486 struct list_head pidlists; 0487 struct mutex pidlist_mutex; 0488 0489 /* used to wait for offlining of csses */ 0490 wait_queue_head_t offline_waitq; 0491 0492 /* used to schedule release agent */ 0493 struct work_struct release_agent_work; 0494 0495 /* used to track pressure stalls */ 0496 struct psi_group *psi; 0497 0498 /* used to store eBPF programs */ 0499 struct cgroup_bpf bpf; 0500 0501 /* If there is block congestion on this cgroup. */ 0502 atomic_t congestion_count; 0503 0504 /* Used to store internal freezer state */ 0505 struct cgroup_freezer_state freezer; 0506 0507 /* ids of the ancestors at each level including self */ 0508 u64 ancestor_ids[]; 0509 }; 0510 0511 /* 0512 * A cgroup_root represents the root of a cgroup hierarchy, and may be 0513 * associated with a kernfs_root to form an active hierarchy. This is 0514 * internal to cgroup core. Don't access directly from controllers. 0515 */ 0516 struct cgroup_root { 0517 struct kernfs_root *kf_root; 0518 0519 /* The bitmask of subsystems attached to this hierarchy */ 0520 unsigned int subsys_mask; 0521 0522 /* Unique id for this hierarchy. */ 0523 int hierarchy_id; 0524 0525 /* The root cgroup. Root is destroyed on its release. */ 0526 struct cgroup cgrp; 0527 0528 /* for cgrp->ancestor_ids[0] */ 0529 u64 cgrp_ancestor_id_storage; 0530 0531 /* Number of cgroups in the hierarchy, used only for /proc/cgroups */ 0532 atomic_t nr_cgrps; 0533 0534 /* A list running through the active hierarchies */ 0535 struct list_head root_list; 0536 0537 /* Hierarchy-specific flags */ 0538 unsigned int flags; 0539 0540 /* The path to use for release notifications. */ 0541 char release_agent_path[PATH_MAX]; 0542 0543 /* The name for this hierarchy - may be empty */ 0544 char name[MAX_CGROUP_ROOT_NAMELEN]; 0545 }; 0546 0547 /* 0548 * struct cftype: handler definitions for cgroup control files 0549 * 0550 * When reading/writing to a file: 0551 * - the cgroup to use is file->f_path.dentry->d_parent->d_fsdata 0552 * - the 'cftype' of the file is file->f_path.dentry->d_fsdata 0553 */ 0554 struct cftype { 0555 /* 0556 * By convention, the name should begin with the name of the 0557 * subsystem, followed by a period. Zero length string indicates 0558 * end of cftype array. 0559 */ 0560 char name[MAX_CFTYPE_NAME]; 0561 unsigned long private; 0562 0563 /* 0564 * The maximum length of string, excluding trailing nul, that can 0565 * be passed to write. If < PAGE_SIZE-1, PAGE_SIZE-1 is assumed. 0566 */ 0567 size_t max_write_len; 0568 0569 /* CFTYPE_* flags */ 0570 unsigned int flags; 0571 0572 /* 0573 * If non-zero, should contain the offset from the start of css to 0574 * a struct cgroup_file field. cgroup will record the handle of 0575 * the created file into it. The recorded handle can be used as 0576 * long as the containing css remains accessible. 0577 */ 0578 unsigned int file_offset; 0579 0580 /* 0581 * Fields used for internal bookkeeping. Initialized automatically 0582 * during registration. 0583 */ 0584 struct cgroup_subsys *ss; /* NULL for cgroup core files */ 0585 struct list_head node; /* anchored at ss->cfts */ 0586 struct kernfs_ops *kf_ops; 0587 0588 int (*open)(struct kernfs_open_file *of); 0589 void (*release)(struct kernfs_open_file *of); 0590 0591 /* 0592 * read_u64() is a shortcut for the common case of returning a 0593 * single integer. Use it in place of read() 0594 */ 0595 u64 (*read_u64)(struct cgroup_subsys_state *css, struct cftype *cft); 0596 /* 0597 * read_s64() is a signed version of read_u64() 0598 */ 0599 s64 (*read_s64)(struct cgroup_subsys_state *css, struct cftype *cft); 0600 0601 /* generic seq_file read interface */ 0602 int (*seq_show)(struct seq_file *sf, void *v); 0603 0604 /* optional ops, implement all or none */ 0605 void *(*seq_start)(struct seq_file *sf, loff_t *ppos); 0606 void *(*seq_next)(struct seq_file *sf, void *v, loff_t *ppos); 0607 void (*seq_stop)(struct seq_file *sf, void *v); 0608 0609 /* 0610 * write_u64() is a shortcut for the common case of accepting 0611 * a single integer (as parsed by simple_strtoull) from 0612 * userspace. Use in place of write(); return 0 or error. 0613 */ 0614 int (*write_u64)(struct cgroup_subsys_state *css, struct cftype *cft, 0615 u64 val); 0616 /* 0617 * write_s64() is a signed version of write_u64() 0618 */ 0619 int (*write_s64)(struct cgroup_subsys_state *css, struct cftype *cft, 0620 s64 val); 0621 0622 /* 0623 * write() is the generic write callback which maps directly to 0624 * kernfs write operation and overrides all other operations. 0625 * Maximum write size is determined by ->max_write_len. Use 0626 * of_css/cft() to access the associated css and cft. 0627 */ 0628 ssize_t (*write)(struct kernfs_open_file *of, 0629 char *buf, size_t nbytes, loff_t off); 0630 0631 __poll_t (*poll)(struct kernfs_open_file *of, 0632 struct poll_table_struct *pt); 0633 0634 #ifdef CONFIG_DEBUG_LOCK_ALLOC 0635 struct lock_class_key lockdep_key; 0636 #endif 0637 }; 0638 0639 /* 0640 * Control Group subsystem type. 0641 * See Documentation/admin-guide/cgroup-v1/cgroups.rst for details 0642 */ 0643 struct cgroup_subsys { 0644 struct cgroup_subsys_state *(*css_alloc)(struct cgroup_subsys_state *parent_css); 0645 int (*css_online)(struct cgroup_subsys_state *css); 0646 void (*css_offline)(struct cgroup_subsys_state *css); 0647 void (*css_released)(struct cgroup_subsys_state *css); 0648 void (*css_free)(struct cgroup_subsys_state *css); 0649 void (*css_reset)(struct cgroup_subsys_state *css); 0650 void (*css_rstat_flush)(struct cgroup_subsys_state *css, int cpu); 0651 int (*css_extra_stat_show)(struct seq_file *seq, 0652 struct cgroup_subsys_state *css); 0653 0654 int (*can_attach)(struct cgroup_taskset *tset); 0655 void (*cancel_attach)(struct cgroup_taskset *tset); 0656 void (*attach)(struct cgroup_taskset *tset); 0657 void (*post_attach)(void); 0658 int (*can_fork)(struct task_struct *task, 0659 struct css_set *cset); 0660 void (*cancel_fork)(struct task_struct *task, struct css_set *cset); 0661 void (*fork)(struct task_struct *task); 0662 void (*exit)(struct task_struct *task); 0663 void (*release)(struct task_struct *task); 0664 void (*bind)(struct cgroup_subsys_state *root_css); 0665 0666 bool early_init:1; 0667 0668 /* 0669 * If %true, the controller, on the default hierarchy, doesn't show 0670 * up in "cgroup.controllers" or "cgroup.subtree_control", is 0671 * implicitly enabled on all cgroups on the default hierarchy, and 0672 * bypasses the "no internal process" constraint. This is for 0673 * utility type controllers which is transparent to userland. 0674 * 0675 * An implicit controller can be stolen from the default hierarchy 0676 * anytime and thus must be okay with offline csses from previous 0677 * hierarchies coexisting with csses for the current one. 0678 */ 0679 bool implicit_on_dfl:1; 0680 0681 /* 0682 * If %true, the controller, supports threaded mode on the default 0683 * hierarchy. In a threaded subtree, both process granularity and 0684 * no-internal-process constraint are ignored and a threaded 0685 * controllers should be able to handle that. 0686 * 0687 * Note that as an implicit controller is automatically enabled on 0688 * all cgroups on the default hierarchy, it should also be 0689 * threaded. implicit && !threaded is not supported. 0690 */ 0691 bool threaded:1; 0692 0693 /* the following two fields are initialized automatically during boot */ 0694 int id; 0695 const char *name; 0696 0697 /* optional, initialized automatically during boot if not set */ 0698 const char *legacy_name; 0699 0700 /* link to parent, protected by cgroup_lock() */ 0701 struct cgroup_root *root; 0702 0703 /* idr for css->id */ 0704 struct idr css_idr; 0705 0706 /* 0707 * List of cftypes. Each entry is the first entry of an array 0708 * terminated by zero length name. 0709 */ 0710 struct list_head cfts; 0711 0712 /* 0713 * Base cftypes which are automatically registered. The two can 0714 * point to the same array. 0715 */ 0716 struct cftype *dfl_cftypes; /* for the default hierarchy */ 0717 struct cftype *legacy_cftypes; /* for the legacy hierarchies */ 0718 0719 /* 0720 * A subsystem may depend on other subsystems. When such subsystem 0721 * is enabled on a cgroup, the depended-upon subsystems are enabled 0722 * together if available. Subsystems enabled due to dependency are 0723 * not visible to userland until explicitly enabled. The following 0724 * specifies the mask of subsystems that this one depends on. 0725 */ 0726 unsigned int depends_on; 0727 }; 0728 0729 extern struct percpu_rw_semaphore cgroup_threadgroup_rwsem; 0730 0731 /** 0732 * cgroup_threadgroup_change_begin - threadgroup exclusion for cgroups 0733 * @tsk: target task 0734 * 0735 * Allows cgroup operations to synchronize against threadgroup changes 0736 * using a percpu_rw_semaphore. 0737 */ 0738 static inline void cgroup_threadgroup_change_begin(struct task_struct *tsk) 0739 { 0740 percpu_down_read(&cgroup_threadgroup_rwsem); 0741 } 0742 0743 /** 0744 * cgroup_threadgroup_change_end - threadgroup exclusion for cgroups 0745 * @tsk: target task 0746 * 0747 * Counterpart of cgroup_threadcgroup_change_begin(). 0748 */ 0749 static inline void cgroup_threadgroup_change_end(struct task_struct *tsk) 0750 { 0751 percpu_up_read(&cgroup_threadgroup_rwsem); 0752 } 0753 0754 #else /* CONFIG_CGROUPS */ 0755 0756 #define CGROUP_SUBSYS_COUNT 0 0757 0758 static inline void cgroup_threadgroup_change_begin(struct task_struct *tsk) 0759 { 0760 might_sleep(); 0761 } 0762 0763 static inline void cgroup_threadgroup_change_end(struct task_struct *tsk) {} 0764 0765 #endif /* CONFIG_CGROUPS */ 0766 0767 #ifdef CONFIG_SOCK_CGROUP_DATA 0768 0769 /* 0770 * sock_cgroup_data is embedded at sock->sk_cgrp_data and contains 0771 * per-socket cgroup information except for memcg association. 0772 * 0773 * On legacy hierarchies, net_prio and net_cls controllers directly 0774 * set attributes on each sock which can then be tested by the network 0775 * layer. On the default hierarchy, each sock is associated with the 0776 * cgroup it was created in and the networking layer can match the 0777 * cgroup directly. 0778 */ 0779 struct sock_cgroup_data { 0780 struct cgroup *cgroup; /* v2 */ 0781 #ifdef CONFIG_CGROUP_NET_CLASSID 0782 u32 classid; /* v1 */ 0783 #endif 0784 #ifdef CONFIG_CGROUP_NET_PRIO 0785 u16 prioidx; /* v1 */ 0786 #endif 0787 }; 0788 0789 static inline u16 sock_cgroup_prioidx(const struct sock_cgroup_data *skcd) 0790 { 0791 #ifdef CONFIG_CGROUP_NET_PRIO 0792 return READ_ONCE(skcd->prioidx); 0793 #else 0794 return 1; 0795 #endif 0796 } 0797 0798 static inline u32 sock_cgroup_classid(const struct sock_cgroup_data *skcd) 0799 { 0800 #ifdef CONFIG_CGROUP_NET_CLASSID 0801 return READ_ONCE(skcd->classid); 0802 #else 0803 return 0; 0804 #endif 0805 } 0806 0807 static inline void sock_cgroup_set_prioidx(struct sock_cgroup_data *skcd, 0808 u16 prioidx) 0809 { 0810 #ifdef CONFIG_CGROUP_NET_PRIO 0811 WRITE_ONCE(skcd->prioidx, prioidx); 0812 #endif 0813 } 0814 0815 static inline void sock_cgroup_set_classid(struct sock_cgroup_data *skcd, 0816 u32 classid) 0817 { 0818 #ifdef CONFIG_CGROUP_NET_CLASSID 0819 WRITE_ONCE(skcd->classid, classid); 0820 #endif 0821 } 0822 0823 #else /* CONFIG_SOCK_CGROUP_DATA */ 0824 0825 struct sock_cgroup_data { 0826 }; 0827 0828 #endif /* CONFIG_SOCK_CGROUP_DATA */ 0829 0830 #endif /* _LINUX_CGROUP_DEFS_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |