diff --git a/etc/rc.conf b/etc/rc.conf index 123d58e6..895641db 100644 --- a/etc/rc.conf +++ b/etc/rc.conf @@ -198,10 +198,9 @@ rc_tty_number=12 # "unified" mounts cgroups version 2 on /sys/fs/cgroup #rc_cgroup_mode="hybrid" -# This is a list of controllers which should be enabled for cgroups version 2. -# If hybrid mode is being used, controllers listed here will not be -# available for cgroups version 1. -# This is a global setting. +# This is a list of controllers which should be enabled for cgroups version 2 +# when hybrid mode is being used. +# Controllers listed here will not be available for cgroups version 1. #rc_cgroup_controllers="" # This variable contains the cgroups version 2 settings for your services. diff --git a/init.d/cgroups.in b/init.d/cgroups.in index 3d5bfa7b..c5399e37 100644 --- a/init.d/cgroups.in +++ b/init.d/cgroups.in @@ -83,14 +83,22 @@ cgroup2_controllers() local active cgroup_path x y cgroup_path="$(cgroup2_find_path)" [ -z "${cgroup_path}" ] && return 0 - [ -e "${cgroup_path}/cgroup.controllers" ] && + [ ! -e "${cgroup_path}/cgroup.controllers" ] && return 0 + [ ! -e "${cgroup_path}/cgroup.subtree_control" ]&& return 0 read -r active < "${cgroup_path}/cgroup.controllers" - for x in ${rc_cgroup_controllers}; do - for y in ${active}; do - [ "$x" = "$y" ] && - [ -e "${cgroup_path}/cgroup.subtree_control" ]&& + for x in ${active}; do + case "$rc_cgroup_mode" in + unified) echo "+${x}" > "${cgroup_path}/cgroup.subtree_control" - done + ;; + hybrid) + for y in ${rc_cgroup_controllers}; do + if [ "$x" = "$y" ]; then + echo "+${x}" > "${cgroup_path}/cgroup.subtree_control" + fi + done + ;; + esac done return 0 }