Both sides previous revisionPrevious revisionNext revision | Previous revision |
kernel:control_groups [2020/07/20 15:09] – old revision restored (2017/04/06 10:51) 192.151.145.82 | kernel:control_groups [2020/07/22 18:05] (current) – old revision restored (2020/07/20 16:09) 207.244.157.10 |
---|
* define a cgroup_subsys object called <name>_subsys | * define a cgroup_subsys object called <name>_subsys |
| |
If a subsystem can be compiled as a module, it should also have in its module initcall a call to **cgroup_load_subsys()**, and in its exitcall a call to **cgroup_unload_subsys()**. It should also set **its_subsys.module = THIS_MODULE** in its .c file. | If a subsystem can be compiled as a module, it should also have in its module initcall a call to cgroup_load_subsys(), and in its exitcall a call to cgroup_unload_subsys(). It should also set its_subsys.module = THIS_MODULE in its .c file. |
| |
Each subsystem may export the following methods. The only mandatory methods are create/destroy. Any others that are null are presumed to be successful no-ops. | Each subsystem may export the following methods. The only mandatory methods are create/destroy. Any others that are null are presumed to be successful no-ops. |
| |
<code c> | <code c> |
</code> | </code> |
| |
Called to create a subsystem state object for a cgroup. The subsystem should allocate its subsystem state object for the passed cgroup, returning a pointer to the new object on success or a negative error code. On success, the subsystem pointer should point to a structure of type **cgroup_subsys_state** (typically embedded in a larger subsystem-specific object), which will be initialized by the cgroup system. | Called to create a subsystem state object for a cgroup. The subsystem should allocate its subsystem state object for the passed cgroup, returning a pointer to the new object on success or a negative error code. On success, the subsystem pointer should point to a structure of type cgroup_subsys_state (typically embedded in a larger subsystem-specific object), which will be initialized by the cgroup system. Note that this will be called at initialization to create the root subsystem state for this subsystem; this case can be identified by the passed cgroup object having a NULL parent (since it's the root of the hierarchy) and may be an appropriate place for initialization code. |
| |
<WRAP info> | |
**NOTE:** This will be called at initialization to create the root subsystem state for this subsystem; this case can be identified by the passed cgroup object having a NULL parent (since it's the root of the hierarchy) and may be an appropriate place for initialization code. | |
</WRAP> | |
| |
<code c> | <code c> |
</code> | </code> |
| |
The cgroup system is about to destroy the passed cgroup; the subsystem should do any necessary cleanup and free its subsystem state object. By the time this method is called, the cgroup has already been unlinked from the file system and from the child list of its parent; **cgroup->parent** is still valid. | The cgroup system is about to destroy the passed cgroup; the subsystem should do any necessary cleanup and free its subsystem state object. By the time this method is called, the cgroup has already been unlinked from the file system and from the child list of its parent; cgroup->parent is still valid. (Note - can also be called for a newly-created cgroup if an error occurs after this subsystem's create() method has been called for the new cgroup). |
| |
<WRAP info> | |
**NOTE:** Can also be called for a newly-created cgroup if an error occurs after this subsystem's **create()** method has been called for the new cgroup. | |
</WRAP> | |
| |
<code c> | <code c> |
</code> | </code> |
| |
Called before checking the reference count on each subsystem. This may be useful for subsystems which have some extra references even if there are not tasks in the cgroup. If **pre_destroy()** returns error code, **rmdir()** will fail with it. From this behavior, pre_destroy() can be called multiple times against a cgroup. | Called before checking the reference count on each subsystem. This may be useful for subsystems which have some extra references even if there are not tasks in the cgroup. If pre_destroy() returns error code, rmdir() will fail with it. From this behavior, pre_destroy() can be called multiple times against a cgroup. |
| |
<code c> | <code c> |
</code> | </code> |
| |
Called prior to moving a task into a cgroup; if the subsystem returns an error, this will abort the attach operation. If a NULL task is passed, then a successful result indicates that *any* unspecified task can be moved into the cgroup. Note that this isn't called on a fork. If this method returns 0 (success) then this should remain valid while the caller holds **cgroup_mutex** and it is ensured that either **attach()** or **cancel_attach()** will be called in future. If **threadgroup** is true, then a successful result indicates that all threads in the given thread's threadgroup can be moved together. | Called prior to moving a task into a cgroup; if the subsystem returns an error, this will abort the attach operation. If a NULL task is passed, then a successful result indicates that *any* unspecified task can be moved into the cgroup. Note that this isn't called on a fork. If this method returns 0 (success) then this should remain valid while the caller holds cgroup_mutex and it is ensured that either attach() or cancel_attach() will be called in future. If threadgroup is true, then a successful result indicates that all threads in the given thread's threadgroup can be moved together. |
| |
<code c> | <code c> |
</code> | </code> |
| |
Called when a task attach operation has failed after **can_attach()** has succeeded. A subsystem whose can_attach() has some side-effects should provide this function, so that the subsystem can implement a rollback. If not, not necessary. This will be called only about subsystems whose can_attach() operation have succeeded. | Called when a task attach operation has failed after can_attach() has succeeded. A subsystem whose can_attach() has some side-effects should provide this function, so that the subsystem can implement a rollback. If not, not necessary. This will be called only about subsystems whose can_attach() operation have succeeded. |
| |
<code c> | <code c> |
</code> | </code> |
| |
Called after the task has been attached to the cgroup, to allow any post-attachment activity that requires memory allocations or blocking. If **threadgroup** is true, the subsystem should take care of all threads in the specified thread's threadgroup. Currently does not support any subsystem that might need the **old_cgrp** for every thread in the group. | Called after the task has been attached to the cgroup, to allow any post-attachment activity that requires memory allocations or blocking. If threadgroup is true, the subsystem should take care of all threads in the specified thread's threadgroup. Currently does not support any subsystem that might need the old_cgrp for every thread in the group. |
| |
<code c> | <code c> |
</code> | </code> |
| |
Called after creation of a cgroup to allow a subsystem to populate the cgroup directory with file entries. The subsystem should make calls to **cgroup_add_file()** with objects of type **cftype** (see include/linux/cgroup.h for details). Note that although this method can return an error code, the error code is currently not always handled well. | Called after creation of a cgroup to allow a subsystem to populate the cgroup directory with file entries. The subsystem should make calls to cgroup_add_file() with objects of type cftype (see include/linux/cgroup.h for details). Note that although this method can return an error code, the error code is currently not always handled well. |
| |
<code c> | <code c> |
</code> | </code> |
| |
Called at the end of **cgroup_clone()** to do any parameter initialization which might be required before a task could attach. For example in [[Kernel:CPU Sets|cpusets]], no task may attach before 'cpus' and 'mems' are set up. | Called at the end of cgroup_clone() to do any parameter initialization which might be required before a task could attach. For example in cpusets, no task may attach before 'cpus' and 'mems' are set up. |
| |
<code c> | <code c> |