Support cpu usage management for Linux

This commit was modified by William Hubbs as follows:

- The paths in the cgroup fs were put into variables to ease
  maintenance.
- Documentation was added to rc.conf.Linux.
- The services were added originally to openrc/svcname cgroups under the
  controller cgroups, but this left an "openrc" cgroup which was unused.
  Now they are added to individual cgroups with the name openrc_${RC_SVCNAME}.
This commit is contained in:
Alexander Vershilov 2012-10-26 09:05:41 +04:00 committed by William Hubbs
parent cf7b904704
commit 4f19c2f512
2 changed files with 31 additions and 7 deletions

View File

@ -20,10 +20,21 @@
# consolefont, numlock, etc ...) # consolefont, numlock, etc ...)
rc_tty_number=12 rc_tty_number=12
##############################################################################
# CGROUPS RESOURCE MANAGEMENT
# If you have cgroups turned on in your kernel, this switch controls # If you have cgroups turned on in your kernel, this switch controls
# whether or not a group for each controler is mounted under # whether or not a group for each controler is mounted under
# /sys/fs/cgroup. # /sys/fs/cgroup.
# Support for process management by cgroups is planned in the future, # None of the other options in this section work if this is set to "NO".
# so if you turn this off, be aware that you may not be able to use that
# feature.
#rc_controller_cgroups="YES" #rc_controller_cgroups="YES"
# These options can be set globally in this file; however, if you do
# this, the same setting will apply to all of your services.
# If you want different settings for each service, place the settings in
# /etc/conf.d/foo for service foo.
# This is the number of CPU shares a service is allowed to use. The
# default value, set by the kernel, is 1024.
# Also, this setting is not preserved if you suspend your computer.
#rc_cgroup_cpu_shares=1024

View File

@ -193,11 +193,24 @@ unset _conf_d
# Load any system overrides # Load any system overrides
sourcex -e "@SYSCONFDIR@/rc.conf" sourcex -e "@SYSCONFDIR@/rc.conf"
if [ "$RC_UNAME" = "Linux" -a "$1" = "start" ]; then if [ "$RC_UNAME" = "Linux" -a "$RC_SYS" != "PREFIX" -a "$1" = "start" ]; then
if [ -d /sys/fs/cgroup/openrc ]; then openrc_cgroup=/sys/fs/cgroup/openrc
mkdir -p /sys/fs/cgroup/openrc/${RC_SVCNAME} if [ -d ${openrc_cgroup} ]; then
echo $$ > /sys/fs/cgroup/openrc/${RC_SVCNAME}/tasks cgroup=${openrc_cgroup}/${RC_SVCNAME}
mkdir -p ${cgroup}
[ -f "${cgroup}"/tasks ] && echo 0 > "${cgroup}"/tasks
fi fi
shares="${rc_cgroup_cpu_shares:-$RC_CGROUP_CPU_SHARES}"
if [ -n "${shares}" -a -d /sys/fs/cgroup/cpu ]; then
cgroup=/sys/fs/cgroup/cpu/openrc_${RC_SVCNAME}
if [ ! -d ${cgroup} ]; then
mkdir -p ${cgroup}
fi
[ -f "${cgroup}"/cpu.shares ] && echo ${shares} > "${cgroup}"/cpu.shares
[ -f "${cgroup}"/tasks ] && echo 0 >> "${cgroup}"/tasks
fi
#todo: add processes to cgroups based on settings in conf.d #todo: add processes to cgroups based on settings in conf.d
fi fi