diff options
-rw-r--r-- | etc/rc.conf.Linux | 40 | ||||
-rw-r--r-- | sh/rc-cgroup.sh.in | 83 |
2 files changed, 90 insertions, 33 deletions
diff --git a/etc/rc.conf.Linux b/etc/rc.conf.Linux index 7571f984..4fb48ae9 100644 --- a/etc/rc.conf.Linux +++ b/etc/rc.conf.Linux @@ -29,12 +29,40 @@ rc_tty_number=12 # None of the other options in this section work if this is set to "NO". #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. +# The following settings allow you to set up values for the cgroup +# controllers for your services. +# They can be set in this file;, however, if you do this, the settings +# 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. +# The format is to specify the names of the settings followed by their +# values. Each variable can hold multiple settings. +# For example, you would use this to set the cpu.shares setting in the +# cpu controller to 512 for your service. +# 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. + +# Set the blkio controller settings for this service. +#rc_cgroup_blkio="" + +# Set the cpu controller settings for this service. +#rc_cgroup_cpu="" + +# Add this service to the cpuacct controller (any value means yes). +#rc_cgroup_cpuacct="" + +# Set the cpuset controller settings for this service. +#rc_cgroup_cpuset="" + +# Set the devices controller settings for this service. +#rc_cgroup_devices="" + +# Set the memory controller settings for this service. +#rc_cgroup_memory="" -# This is the number of CPU shares a service is allowed to use. The -# default value, set by the kernel, is 1024. -# This requires CONFIG_FAIR_GROUP_SCHED to be set in the kernel. -#rc_cgroup_cpu_shares=1024 +# Set the net_prio controller settings for this service. +#rc_cgroup_net_prio="" diff --git a/sh/rc-cgroup.sh.in b/sh/rc-cgroup.sh.in index c9a00622..449c1d37 100644 --- a/sh/rc-cgroup.sh.in +++ b/sh/rc-cgroup.sh.in @@ -15,45 +15,74 @@ cgroup_find_path() echo $result } -# prepare values to be attached inside cgroups -cgroup_prepare() +cgroup_set_values() { - local h=$(cgroup_find_path "$1") + [ -n "$1" -a -n "$2" -a -d "/sys/fs/cgroup/$1" ] || return 0 + + local controller="$1" h=$(cgroup_find_path "$1") cgroup="/sys/fs/cgroup/${1}${h}openrc_${RC_SVCNAME}" - [ -d ${cgroup} ] || mkdir -p ${cgroup} - return 0 -} + [ -d "$cgroup" ] || mkdir -p "$cgroup" -cgroup_set_value() -{ - [ -f "$cgroup/${1}" -a -n "$2" ] && echo $2 > "${cgroup}/${1}" - return 0 -} + set -- $2 + local name val + while [ -n "$1" -a "$controller" != "cpuacct" ]; do + case "$1" in + $controller.*) + if [ -n "$name" -a -f "$cgroup/$name" -a -n "$val" ]; then + veinfo "$RC_SVCNAME: Setting $cgroup/$name to $val" + echo $val > "$cgroup/$name" + fi + name=$1 + val= + ;; + *) + val="$val $1" + ;; + esac + shift + done + if [ -n "$name" -a -f "$cgroup/$name" -a -n "$val" ]; then + veinfo "$RC_SVCNAME: Setting $cgroup/$name to $val" + echo $val > "$cgroup/$name" + fi + + if [ -f "$cgroup/tasks" ]; then + veinfo "$RC_SVCNAME: adding to $cgroup/tasks" + echo 0 > "$cgroup/tasks" + fi -cgroup_add_process() -{ - [ -f "${cgroup}"/tasks ] && echo 0 > "${cgroup}"/tasks return 0 } cgroup_set_limits() { 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 + if [ -d "$openrc_cgroup" ]; then + cgroup="$openrc_cgroup/$RC_SVCNAME" + mkdir -p "$cgroup" + [ -f "$cgroup/tasks" ] && echo 0 > "$cgroup/tasks" fi - if [ -d /sys/fs/cgroup/cpu ]; then - local share + local blkio="${rc_cgroup_blkio:-$RC_CGROUP_BLKIO}" + [ -n "$blkio" ] && cgroup_set_values blkio "$blkio" + + local cpu="${rc_cgroup_cpu:-$RC_CGROUP_CPU}" + [ -n "$cpu" ] && cgroup_set_values cpu "$cpu" + + local cpuacct="${rc_cgroup_cpuacct:-$RC_CGROUP_CPUACCT}" + [ -n "$cpuacct" ] && cgroup_set_values cpuacct "$cpuacct" + + local cpuset="${rc_cgroup_cpuset:-$RC_CGROUP_cpuset}" + [ -n "$cpuset" ] && cgroup_set_values cpuset "$cpuset" + + local devices="${rc_cgroup_devices:-$RC_CGROUP_DEVICES}" + [ -n "$devices" ] && cgroup_set_values devices "$devices" + + local memory="${rc_cgroup_memory:-$RC_CGROUP_MEMORY}" + [ -n "$memory" ] && cgroup_set_values memory "$memory" + + local net_prio="${rc_cgroup_net_prio:-$RC_CGROUP_NET_PRIO}" + [ -n "$net_prio" ] && cgroup_set_values net_prio "$net_prio" - share=${rc_cgroup_cpu_shares:-$RC_CGROUP_CPU_SHARES} - if [ -n "$share" ]; then - cgroup_prepare "cpu" - cgroup_set_value "cpu.shares" $share - cgroup_add_process - fi - fi return 0 } |