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:
cpu_and_mem]# cgset -r cpuset.cpus=0-1 group1
The syntax for
cgset
is:
cgset -r
parameter=value path_to_cgroup
where:
- 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
cpuacct
subsystem is mounted to/cgroup/cpu_and_mem/
), change to the/cgroup/cpu_and_mem/
directory, and run:cpu_and_mem]#
cgset -r cpuacct.usage=0 /
Alternatively, because.
is relative to the root group (that is, the root group itself) you could also run:cpu_and_mem]#
cgset -r cpuacct.usage=0 .
Note, however, that/
is the preferred syntax.Note
Only a small number of parameters can be set for the root group (such as thecpuacct.usage
parameter 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 thecpuset.cpu
parameter.To set the parameter ofgroup1
, which is a subgroup of the root group, run:cpu_and_mem]#
cgset -r cpuacct.usage=0 group1
A 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:
cpu_and_mem]# cgset --copy-from group1/ group2/
The syntax to copy parameters with
cgset
is:
cgset --copy-from
path_to_source_cgroup path_to_target_cgroup
where:
- 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.
Alternative method
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 group1
:
~]# 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.