Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 43 additions & 44 deletions init.d/cgroups.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ depend()

cgroup1_base()
{
eerror "cgroups v1 is deprecated. Please unset rc_cgroup_mode."
grep -qw cgroup /proc/filesystems || return 0
if ! mountinfo -q /sys/fs/cgroup; then
ebegin "Mounting cgroup filesystem"
Expand All @@ -44,63 +45,65 @@ cgroup1_controllers()
{
yesno "${rc_controller_cgroups:-YES}" && [ -e /proc/cgroups ] &&
grep -qw cgroup /proc/filesystems || return 0

while read -r name _ _ enabled _; do
case "${enabled}" in
1) mountinfo -q "/sys/fs/cgroup/${name}" && continue
local x
for x in $rc_cgroup_controllers; do
[ "${name}" = "blkio" ] && [ "${x}" = "io" ] &&
continue 2
[ "${name}" = "${x}" ] &&
continue 2
done
mkdir "/sys/fs/cgroup/${name}"
mount -n -t cgroup -o "${cgroup_opts},${name}" \
"${name}" "/sys/fs/cgroup/${name}"
yesno "${rc_cgroup_memory_use_hierarchy:-no}" &&
[ "${name}" = memory ] &&
echo 1 > /sys/fs/cgroup/memory/memory.use_hierarchy
;;
esac
[ "$enabled" = 1 ] || continue;
mountinfo -q "/sys/fs/cgroup/${name}" && continue

local x
for x in $rc_cgroup_controllers; do
[ "${name}" = "blkio" ] && [ "${x}" = "io" ] && continue 2
[ "${name}" = "${x}" ] && continue 2
done

mkdir "/sys/fs/cgroup/${name}"
mount -n -t cgroup -o "${cgroup_opts},${name}" "${name}" "/sys/fs/cgroup/${name}"
if [ yesno "${rc_cgroup_memory_use_hierarchy:-no}" && [ "${name}" = memory ]; then
echo 1 > /sys/fs/cgroup/memory/memory.use_hierarchy
fi
done < /proc/cgroups
return 0
}

cgroup2_base()
{
grep -qw cgroup2 /proc/filesystems || return 0
local base
base="$(cgroup2_find_path)"
mkdir -p "${base}"
mount -t cgroup2 cgroup2 -o "${cgroup_opts},nsdelegate" "${base}" 2> /dev/null ||
mount -t cgroup2 cgroup2 -o "${cgroup_opts}" "${base}"
mkdir -p "${cgroup_root}"
mount -t cgroup2 cgroup2 -o "${cgroup_opts},nsdelegate" "${cgroup_root}" 2> /dev/null ||
mount -t cgroup2 cgroup2 -o "${cgroup_opts}" "${cgroup_root}"
mkdir -p "${cgroup_root}/rc"
return 0
}

cgroup2_controllers()
setup_controller()
{
grep -qw cgroup2 /proc/filesystems || return 0
local active cgroup_path x y
cgroup_path="$(cgroup2_find_path)"
[ -z "${cgroup_path}" ] && return 0
[ ! -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 ${active}; do
case "${rc_cgroup_mode:-unified}" in
unified)
echo "+${x}" > "${cgroup_path}/cgroup.subtree_control"
;;
local root="$1" controller allowed
shift

[ ! -e "${root}/cgroup.controllers" ] && return 0
[ ! -e "${root}/cgroup.subtree_control" ] && return 0

for controller; do
case "${rc_cgroup_mode:-unified}" in
unified) echo "+${controller}" > "${root}/cgroup.subtree_control" ;;
hybrid)
for y in ${rc_cgroup_controllers}; do
if [ "$x" = "$y" ]; then
echo "+${x}" > "${cgroup_path}/cgroup.subtree_control"
for allowed in ${rc_cgroup_controllers}; do
if [ "$controller" = "$allowed" ]; then
echo "+${controller}" > "${root}/cgroup.subtree_control"
fi
done
;;
esac
done
return 0
}

cgroup2_controllers()
{
grep -qw cgroup2 /proc/filesystems || return 0
local active
read -r active < "${cgroup_root}/cgroup.controllers"
setup_controller "${cgroup_root}" $active
setup_controller "${cgroup_root}/rc" $active
}

cgroups_hybrid()
Expand All @@ -109,21 +112,18 @@ cgroups_hybrid()
cgroup2_base
cgroup2_controllers
cgroup1_controllers
return 0
}

cgroups_legacy()
{
cgroup1_base
cgroup1_controllers
return 0
}

cgroups_unified()
{
cgroup2_base
cgroup2_controllers
return 0
}

mount_cgroups()
Expand All @@ -133,7 +133,6 @@ mount_cgroups()
legacy) cgroups_legacy ;;
unified) cgroups_unified ;;
esac
return 0
}

restorecon_cgroups()
Expand All @@ -143,7 +142,6 @@ restorecon_cgroups()
restorecon -rF /sys/fs/cgroup >/dev/null 2>&1
eend $?
fi
return 0
}

start()
Expand All @@ -153,5 +151,6 @@ start()
mount_cgroups
restorecon_cgroups
fi

return 0
}
9 changes: 9 additions & 0 deletions init.d/user.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,13 @@ start_pre() {
eerror "symbolic links to it for the users you want to start"
return 1
fi

if [ -d "$cgroup_path" ]; then
local user_cgroup=${cgroup_path}/daemons

mkdir "$user_cgroup"
chown "$user:$user" "$user_cgroup"

cgroup_path="${cgroup_path}/system"
fi
}
Loading
Loading