From 4f19c2f512d9a08599b6bdf1129f508fc9a4e055 Mon Sep 17 00:00:00 2001 From: Alexander Vershilov Date: Fri, 26 Oct 2012 09:05:41 +0400 Subject: 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}. --- sh/runscript.sh.in | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'sh/runscript.sh.in') diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in index d53d70d..21ff39a 100644 --- a/sh/runscript.sh.in +++ b/sh/runscript.sh.in @@ -193,11 +193,24 @@ unset _conf_d # Load any system overrides sourcex -e "@SYSCONFDIR@/rc.conf" -if [ "$RC_UNAME" = "Linux" -a "$1" = "start" ]; then - if [ -d /sys/fs/cgroup/openrc ]; then - mkdir -p /sys/fs/cgroup/openrc/${RC_SVCNAME} - echo $$ > /sys/fs/cgroup/openrc/${RC_SVCNAME}/tasks +if [ "$RC_UNAME" = "Linux" -a "$RC_SYS" != "PREFIX" -a "$1" = "start" ]; then + openrc_cgroup=/sys/fs/cgroup/openrc + if [ -d ${openrc_cgroup} ]; then + cgroup=${openrc_cgroup}/${RC_SVCNAME} + mkdir -p ${cgroup} + [ -f "${cgroup}"/tasks ] && echo 0 > "${cgroup}"/tasks 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 fi -- cgit v1.2.3