Este contenido no está disponible en el idioma seleccionado.
3.12. Common Tunable Parameters
The following parameters are present in every created cgroup, regardless of the subsystem that the cgroup is using:
- tasks
- contains a list of processes, represented by their PIDs, that are running in a cgroup. The list of PIDs is not guaranteed to be ordered or unique (that is, it may contain duplicate entries). Writing a PID into the
tasks
file of a cgroup moves that process into that cgroup. - cgroup.procs
- contains a list of thread groups, represented by their TGIDs, that are running in a cgroup. The list of TGIDs is not guaranteed to be ordered or unique (that is, it may contain duplicate entries). Writing a TGID into the
cgroup.procs
file of a cgroup moves that thread group into that cgroup. - cgroup.event_control
- along with the cgroup notification API, allows notifications to be sent about a changing status of a cgroup.
- notify_on_release
- contains a Boolean value,
1
or0
, that either enables or disables the execution of the release agent. If thenotify_on_release
parameter is enabled, the kernel executes the contents of therelease_agent
file when a cgroup no longer contains any tasks (that is, the cgroup'stasks
file contained some PIDs and those PIDs were removed, leaving the file empty). A path to the empty cgroup is provided as an argument to the release agent.The default value of thenotify_on_release
parameter in the root cgroup is0
. All non-root cgroups inherit the value innotify_on_release
from their parent cgroup. - release_agent (present in the root cgroup only)
- contains a command to be executed when a “notify on release” is triggered. Once a cgroup is emptied of all processes, and the
notify_on_release
flag is enabled, the kernel runs the command in therelease_agent
file and supplies it with a relative path (relative to the root cgroup) to the emptied cgroup as an argument. The release agent can be used, for example, to automatically remove empty cgroups; for more information, see Example 3.4, “Automatically removing empty cgroups”.Example 3.4. Automatically removing empty cgroups
Follow these steps to configure automatic removal of any emptied cgroup from thecpu
cgroup:- Create a shell script that removes empty
cpu
cgroups, place it in, for example,/usr/local/bin
, and make it executable.~]#
cat /usr/local/bin/remove-empty-cpu-cgroup.sh
#!/bin/sh rmdir /cgroup/cpu/$1 ~]#chmod +x /usr/local/bin/remove-empty-cpu-cgroup.sh
The$1
variable contains a relative path to the emptied cgroup. - In the
cpu
cgroup, enable thenotify_on_release
flag:~]#
echo 1 > /cgroup/cpu/notify_on_release
- In the
cpu
cgroup, specify a release agent to be used:~]#
echo "/usr/local/bin/remove-empty-cpu-cgroup.sh" > /cgroup/cpu/release_agent
- Test your configuration to make sure emptied cgroups are properly removed:
cpu]#
pwd; ls
/cgroup/cpu cgroup.event_control cgroup.procs cpu.cfs_period_us cpu.cfs_quota_us cpu.rt_period_us cpu.rt_runtime_us cpu.shares cpu.stat libvirt notify_on_release release_agent tasks cpu]#cat notify_on_release
1 cpu]#cat release_agent
/usr/local/bin/remove-empty-cpu-cgroup.sh cpu]#mkdir blue; ls
blue cgroup.event_control cgroup.procs cpu.cfs_period_us cpu.cfs_quota_us cpu.rt_period_us cpu.rt_runtime_us cpu.shares cpu.stat libvirt notify_on_release release_agent tasks cpu]#cat blue/notify_on_release
1 cpu]#cgexec -g cpu:blue dd if=/dev/zero of=/dev/null bs=1024k &
[1] 8623 cpu]#cat blue/tasks
8623 cpu]#kill -9 8623
cpu]#ls
cgroup.event_control cgroup.procs cpu.cfs_period_us cpu.cfs_quota_us cpu.rt_period_us cpu.rt_runtime_us cpu.shares cpu.stat libvirt notify_on_release release_agent tasks