Set subsystem parameters by running the cgset
command from a user account with permission to modify the relevant control group. For example, if /cgroup/cpuset/group1
exists, specify the CPUs to which this group has access with the following command:
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 control group relative to the root of the hierarchy. For example, to set the parameter of the root group, run:
$
cgset -r cpuset.cpus=1 /
Alternatively, because .
is relative to the root group (that is, the root group itself) you could also run:
$
cgset -r cpuset.cpus=1 .
Note, however, that /
is the preferred syntax.
To set the parameter of group1
, which is a subgroup of the root group, run:
$
cgset -r cpuset.cpus=1 group1
A trailing slash on the name of the group (for example, cpuset.cpus=1 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 cgset
is: cgset --copy-from
path_to_source_cgroup
path_to_target_cgroup
, where:
path_to_source_cgroup
is the path to the control group whose parameters are to be copied, relative to the root group of the hierarchy
path_to_target_cgroup
is the path to the destination control group, 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.
Alternative method
To set parameters in a control group directly, insert values into the relevant subsystem pseudofile using the echo
command. For example, this command inserts the value 0-1
into the cpuset.cpus
pseudofile of the control group group1
:
echo 0-1 > /cgroup/cpuset/group1/cpuset.cpus
With this value in place, the tasks in this control group are restricted to CPUs 0 and 1 on the system.