diff options
| -rw-r--r-- | Documentation/cgroups.txt | 526 | ||||
| -rw-r--r-- | include/linux/cgroup.h | 214 | ||||
| -rw-r--r-- | include/linux/cgroup_subsys.h | 10 | ||||
| -rw-r--r-- | include/linux/magic.h | 1 | ||||
| -rw-r--r-- | include/linux/sched.h | 34 | ||||
| -rw-r--r-- | init/Kconfig | 8 | ||||
| -rw-r--r-- | init/main.c | 3 | ||||
| -rw-r--r-- | kernel/Makefile | 1 | ||||
| -rw-r--r-- | kernel/cgroup.c | 1198 |
9 files changed, 1994 insertions, 1 deletions
diff --git a/Documentation/cgroups.txt b/Documentation/cgroups.txt new file mode 100644 index 000000000000..4717887fd75d --- /dev/null +++ b/Documentation/cgroups.txt | |||
| @@ -0,0 +1,526 @@ | |||
| 1 | CGROUPS | ||
| 2 | ------- | ||
| 3 | |||
| 4 | Written by Paul Menage <menage@google.com> based on Documentation/cpusets.txt | ||
| 5 | |||
| 6 | Original copyright statements from cpusets.txt: | ||
| 7 | Portions Copyright (C) 2004 BULL SA. | ||
| 8 | Portions Copyright (c) 2004-2006 Silicon Graphics, Inc. | ||
| 9 | Modified by Paul Jackson <pj@sgi.com> | ||
| 10 | Modified by Christoph Lameter <clameter@sgi.com> | ||
| 11 | |||
| 12 | CONTENTS: | ||
| 13 | ========= | ||
| 14 | |||
| 15 | 1. Control Groups | ||
| 16 | 1.1 What are cgroups ? | ||
| 17 | 1.2 Why are cgroups needed ? | ||
| 18 | 1.3 How are cgroups implemented ? | ||
| 19 | 1.4 What does notify_on_release do ? | ||
| 20 | 1.5 How do I use cgroups ? | ||
| 21 | 2. Usage Examples and Syntax | ||
| 22 | 2.1 Basic Usage | ||
| 23 | 2.2 Attaching processes | ||
| 24 | 3. Kernel API | ||
| 25 | 3.1 Overview | ||
| 26 | 3.2 Synchronization | ||
| 27 | 3.3 Subsystem API | ||
| 28 | 4. Questions | ||
| 29 | |||
| 30 | 1. Control Groups | ||
| 31 | ========== | ||
| 32 | |||
| 33 | 1.1 What are cgroups ? | ||
| 34 | ---------------------- | ||
| 35 | |||
| 36 | Control Groups provide a mechanism for aggregating/partitioning sets of | ||
| 37 | tasks, and all their future children, into hierarchical groups with | ||
| 38 | specialized behaviour. | ||
| 39 | |||
| 40 | Definitions: | ||
| 41 | |||
| 42 | A *cgroup* associates a set of tasks with a set of parameters for one | ||
| 43 | or more subsystems. | ||
| 44 | |||
| 45 | A *subsystem* is a module that makes use of the task grouping | ||
| 46 | facilities provided by cgroups to treat groups of tasks in | ||
| 47 | particular ways. A subsystem is typically a "resource controller" that | ||
| 48 | schedules a resource or applies per-cgroup limits, but it may be | ||
| 49 | anything that wants to act on a group of processes, e.g. a | ||
| 50 | virtualization subsystem. | ||
| 51 | |||
| 52 | A *hierarchy* is a set of cgroups arranged in a tree, such that | ||
| 53 | every task in the system is in exactly one of the cgroups in the | ||
| 54 | hierarchy, and a set of subsystems; each subsystem has system-specific | ||
| 55 | state attached to each cgroup in the hierarchy. Each hierarchy has | ||
| 56 | an instance of the cgroup virtual filesystem associated with it. | ||
| 57 | |||
| 58 | At any one time there may be multiple active hierachies of task | ||
| 59 | cgroups. Each hierarchy is a partition of all tasks in the system. | ||
| 60 | |||
| 61 | User level code may create and destroy cgroups by name in an | ||
| 62 | instance of the cgroup virtual file system, specify and query to | ||
| 63 | which cgroup a task is assigned, and list the task pids assigned to | ||
| 64 | a cgroup. Those creations and assignments only affect the hierarchy | ||
| 65 | associated with that instance of the cgroup file system. | ||
| 66 | |||
| 67 | On their own, the only use for cgroups is for simple job | ||
| 68 | tracking. The intention is that other subsystems hook into the generic | ||
| 69 | cgroup support to provide new attributes for cgroups, such as | ||
| 70 | accounting/limiting the resources which processes in a cgroup can | ||
| 71 | access. For example, cpusets (see Documentation/cpusets.txt) allows | ||
| 72 | you to associate a set of CPUs and a set of memory nodes with the | ||
| 73 | tasks in each cgroup. | ||
| 74 | |||
| 75 | 1.2 Why are cgroups needed ? | ||
| 76 | ---------------------------- | ||
| 77 | |||
| 78 | There are multiple efforts to provide process aggregations in the | ||
| 79 | Linux kernel, mainly for resource tracking purposes. Such efforts | ||
| 80 | include cpusets, CKRM/ResGroups, UserBeanCounters, and virtual server | ||
| 81 | namespaces. These all require the basic notion of a | ||
| 82 | grouping/partitioning of processes, with newly forked processes ending | ||
| 83 | in the same group (cgroup) as their parent process. | ||
| 84 | |||
| 85 | The kernel cgroup patch provides the minimum essential kernel | ||
| 86 | mechanisms required to efficiently implement such groups. It has | ||
| 87 | minimal impact on the system fast paths, and provides hooks for | ||
| 88 | specific subsystems such as cpusets to provide additional behaviour as | ||
| 89 | desired. | ||
| 90 | |||
| 91 | Multiple hierarchy support is provided to allow for situations where | ||
| 92 | the division of tasks into cgroups is distinctly different for | ||
| 93 | different subsystems - having parallel hierarchies allows each | ||
| 94 | hierarchy to be a natural division of tasks, without having to handle | ||
| 95 | complex combinations of tasks that would be present if several | ||
| 96 | unrelated subsystems needed to be forced into the same tree of | ||
| 97 | cgroups. | ||
| 98 | |||
| 99 | At one extreme, each resource controller or subsystem could be in a | ||
| 100 | separate hierarchy; at the other extreme, all subsystems | ||
| 101 | would be attached to the same hierarchy. | ||
| 102 | |||
| 103 | As an example of a scenario (originally proposed by vatsa@in.ibm.com) | ||
| 104 | that can benefit from multiple hierarchies, consider a large | ||
| 105 | university server with various users - students, professors, system | ||
| 106 | tasks etc. The resource planning for this server could be along the | ||
| 107 | following lines: | ||
| 108 | |||
| 109 | CPU : Top cpuset | ||
| 110 | / \ | ||
| 111 | CPUSet1 CPUSet2 | ||
| 112 | | | | ||
| 113 | (Profs) (Students) | ||
| 114 | |||
| 115 | In addition (system tasks) are attached to topcpuset (so | ||
| 116 | that they can run anywhere) with a limit of 20% | ||
| 117 | |||
| 118 | Memory : Professors (50%), students (30%), system (20%) | ||
| 119 | |||
| 120 | Disk : Prof (50%), students (30%), system (20%) | ||
| 121 | |||
| 122 | Network : WWW browsing (20%), Network File System (60%), others (20%) | ||
| 123 | / \ | ||
| 124 | Prof (15%) students (5%) | ||
| 125 | |||
| 126 | Browsers like firefox/lynx go into the WWW network class, while (k)nfsd go | ||
| 127 | into NFS network class. | ||
| 128 | |||
| 129 | At the same time firefox/lynx will share an appropriate CPU/Memory class | ||
| 130 | depending on who launched it (prof/student). | ||
| 131 | |||
| 132 | With the ability to classify tasks differently for different resources | ||
| 133 | (by putting those resource subsystems in different hierarchies) then | ||
| 134 | the admin can easily set up a script which receives exec notifications | ||
| 135 | and depending on who is launching the browser he can | ||
| 136 | |||
| 137 | # echo browser_pid > /mnt/<restype>/<userclass>/tasks | ||
| 138 | |||
| 139 | With only a single hierarchy, he now would potentially have to create | ||
| 140 | a separate cgroup for every browser launched and associate it with | ||
| 141 | approp network and other resource class. This may lead to | ||
| 142 | proliferation of such cgroups. | ||
| 143 | |||
| 144 | Also lets say that the administrator would like to give enhanced network | ||
| 145 | access temporarily to a student's browser (since it is night and the user | ||
| 146 | wants to do online gaming :) OR give one of the students simulation | ||
| 147 | apps enhanced CPU power, | ||
| 148 | |||
| 149 | With ability to write pids directly to resource classes, its just a | ||
| 150 | matter of : | ||
| 151 | |||
| 152 | # echo pid > /mnt/network/<new_class>/tasks | ||
| 153 | (after some time) | ||
| 154 | # echo pid > /mnt/network/<orig_class>/tasks | ||
| 155 | |||
| 156 | Without this ability, he would have to split the cgroup into | ||
| 157 | multiple separate ones and then associate the new cgroups with the | ||
| 158 | new resource classes. | ||
| 159 | |||
| 160 | |||
| 161 | |||
| 162 | 1.3 How are cgroups implemented ? | ||
| 163 | --------------------------------- | ||
| 164 | |||
| 165 | Control Groups extends the kernel as follows: | ||
| 166 | |||
| 167 | - Each task in the system has a reference-counted pointer to a | ||
| 168 | css_set. | ||
| 169 | |||
| 170 | - A css_set contains a set of reference-counted pointers to | ||
| 171 | cgroup_subsys_state objects, one for each cgroup subsystem | ||
| 172 | registered in the system. There is no direct link from a task to | ||
| 173 | the cgroup of which it's a member in each hierarchy, but this | ||
| 174 | can be determined by following pointers through the | ||
| 175 | cgroup_subsys_state objects. This is because accessing the | ||
| 176 | subsystem state is something that's expected to happen frequently | ||
| 177 | and in performance-critical code, whereas operations that require a | ||
| 178 | task's actual cgroup assignments (in particular, moving between | ||
| 179 | cgroups) are less common. | ||
| 180 | |||
| 181 | - A cgroup hierarchy filesystem can be mounted for browsing and | ||
| 182 | manipulation from user space. | ||
| 183 | |||
| 184 | - You can list all the tasks (by pid) attached to any cgroup. | ||
| 185 | |||
| 186 | The implementation of cgroups requires a few, simple hooks | ||
| 187 | into the rest of the kernel, none in performance critical paths: | ||
| 188 | |||
| 189 | - in init/main.c, to initial | ||
