2.7. Setting Parameters
Set subsystem parameters by running the
cgset command from a user account with permission to modify the relevant cgroup. For example, if
cpuset is mounted to
/cgroup/cpu_and_mem/ and the
/cgroup/cpu_and_mem/group1 subdirectory exists, specify the CPUs to which this group has access with the following command:
cgset -r cpuset.cpus=0-1 group1
The syntax for
-r parameter=value path_to_cgroup
- parameter is the parameter to be set, which corresponds to the file in the directory of the given cgroup.
- value is the value for the parameter.
- path_to_cgroup is the path to the cgroup relative to the root of the hierarchy. For example, to set the parameter of the root group (if the
cpuacctsubsystem is mounted to
/cgroup/cpu_and_mem/), change to the
/cgroup/cpu_and_mem/directory, and run:
cgset -r cpuacct.usage=0 /Alternatively, because
.is relative to the root group (that is, the root group itself) you could also run:
cgset -r cpuacct.usage=0 .Note, however, that
/is the preferred syntax.
NoteOnly a small number of parameters can be set for the root group (such as the
cpuacct.usageparameter shown in the examples above). This is because a root group owns all of the existing resources, therefore, it would make no sense to limit all existing processes by defining certain parameters, for example the
cpuset.cpuparameter.To set the parameter of
group1, which is a subgroup of the root group, run:
cgset -r cpuacct.usage=0 group1A trailing slash after the name of the group (for example,
cpuacct.usage=0 group1/) is optional.
The values that you can set with
cgset might depend on values set higher in a particular hierarchy. For example, if
group1 is limited to use only CPU 0 on a system, you cannot set
group1/subgroup1 to use CPUs 0 and 1, or to use only CPU 1.
You can also use
cgset to copy the parameters of one cgroup into another existing cgroup. For example:
cgset --copy-from group1/ group2/
The syntax to copy parameters with
--copy-from path_to_source_cgroup path_to_target_cgroup
- path_to_source_cgroup is the path to the cgroup whose parameters are to be copied, relative to the root group of the hierarchy.
- path_to_target_cgroup is the path to the destination cgroup, relative to the root group of the hierarchy.
Ensure that any mandatory parameters for the various subsystems are set before you copy parameters from one group to another, or the command will fail. For more information on mandatory parameters, refer to Important.
To set parameters in a cgroup directly, insert values into the relevant subsystem pseudofile using the
echo command. In the following example, the
echo command inserts the value of
0-1 into the
cpuset.cpus pseudofile of the cgroup
echo 0-1 > /cgroup/cpu_and_mem/group1/cpuset.cpus
With this value in place, the tasks in this cgroup are restricted to CPUs 0 and 1 on the system.