This is Gentoo's testing wiki. It is a non-operational environment and its textual content is outdated.
Please visit our production wiki at https://wiki.gentoo.org
OpenRC/CGroups
Cgroups overview
General info about Linux cgroups: Wikipedia
OpenRC's cgroup implementation follows the FDO recommendations.
OpenRC creates its own cgroup controller named openrc in which the service processes are put. If set in the service's options a new cgroup controller named openrc_${service_name} is created to hold its process inclusive all its child services' processes. The result is a hierarchical tree of cgroups containing the service processes.
Turning the cgroup feature support on
The cgroup feature is only available on Linux.
To use cgroups in OpenRC turn on the following option in the main rc configuration file:
/etc/rc.conf
Turn on the cgroup feature supportrc_controller_cgroups="YES"
Each cgroup controller is mounted at: /sys/fs/cgroup
All other features described in this wiki page will work only if you have set this option to "YES".
Setting limits
For each cgroup controller one can set options in the form of:
/etc/rc.conf
Set cgroup controller option globally for all servicesrc_cgroup_${CONTROLLER_NAME}="${CONTROLLER_NAME}.${OPTION_NAME} ${OPTION VALUE}"
or
/etc/conf.d/${service_name}
Set cgroup controller option for one servicerc_cgroup_${CONTROLLER_NAME}="${CONTROLLER_NAME}.${OPTION_NAME} ${OPTION VALUE}"
For example, you would use this to set the cpu.shares setting in the cpu controller to 512 for your service.
/etc/conf.d/${service_name}
rc_cgroup_cpu="cpu.shares 512"
For more information about the adjustments that can be made with cgroups, see Documentation/cgroups/* in the linux kernel source tree.
Service cleanup
It is possible to trigger the killing of the whole service's process tree inside the same process cgroup if the service gets stopped or restarted. This is achieved by setting the following option in the service's rc script:
/etc/conf.d/${service_name}
an example of triggering cgroup cleanuprc_cgroup_cleanup="yes"
This option should not be set globally as it will kill all service's child processes e.g. SSH connections or apache workers, as OpenRC doesn't support automatic process cgroup-relocation as it is done in logind services.
Service death notification
TBD
Possible Improvements
- system notification about cleared cgroups (can be done via sh user script)
- grouping cgroups subsystems together
- support for userlevel cgroups
OpenRC cgroup architecture
TODO: shortly describe architecture