Skip to content

Commit

Permalink
pseudofs: cgroup: various improvements
Browse files Browse the repository at this point in the history
Default to cgroup2
Attempt to mount cgroup2 in containers to support nesting
Mount the systemd tracking cgroup when using cgroup1

Closes #74
  • Loading branch information
CameronNemo committed Dec 30, 2022
1 parent fa197f0 commit a1300a3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
20 changes: 18 additions & 2 deletions core-services/00-pseudofs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if [ -z "$VIRTUALIZATION" ]; then
_cgroupv1=""
_cgroupv2=""

case "${CGROUP_MODE:-hybrid}" in
case "${CGROUP_MODE:-unified}" in
legacy)
_cgroupv1="/sys/fs/cgroup"
;;
Expand All @@ -40,11 +40,27 @@ if [ -z "$VIRTUALIZATION" ]; then
mkdir -p "$_controller"
mountpoint -q "$_controller" || mount -t cgroup -o "$_subsys_name" cgroup "$_controller"
done < /proc/cgroups
# always mount the systemd tracking cgroup,
# to support containerized systemd instances
mkdir -p /sys/fs/cgroup/systemd
mountpoint -q /sys/fs/cgroup/systemd || \
mount -t cgroup -o none,name=systemd cgroup /sys/fs/cgroup/systemd
fi

# cgroup v2
if [ -n "$_cgroupv2" ]; then
mkdir -p "$_cgroupv2"
mountpoint -q "$_cgroupv2" || mount -t cgroup2 -o nsdelegate cgroup2 "$_cgroupv2"
mountpoint -q "$_cgroupv2" || \
mount -t cgroup2 -o nsdelegate cgroup2 "$_cgroupv2"
fi
else
# in containers, unless otherwise configured,
# attempt to mount cgroup2 at the standard path,
# but never fail
if [ "${CGROUP_MODE:-unified}" = "unified" ]; then
_cgroup2="/sys/fs/cgroup"
mkdir -p "$_cgroup2"
mountpoint -q "$_cgroup2" || \
mount -t cgroup2 -o nsdelegate cgroup2 "$_cgroup2" || true
fi
fi
2 changes: 1 addition & 1 deletion rc.conf
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
# cgroup v2 under /sys/fs/cgroup/unified
# legacy: mount cgroup v1 /sys/fs/cgroup
# unified: mount cgroup v2 under /sys/fs/cgroup
#CGROUP_MODE=hybrid
#CGROUP_MODE=unified

# Set this to true only if you do not want seed files to actually credit the
# RNG, for example if you plan to replicate this file system image and do not
Expand Down

0 comments on commit a1300a3

Please sign in to comment.