From 59afcf08886848e1a8935c4247f33d7b8e3ec460 Mon Sep 17 00:00:00 2001 From: Nicky Gerritsen Date: Thu, 10 Oct 2024 20:16:34 +0200 Subject: [PATCH] Make sure to enable memory and cpuset cgroup in v2 --- doc/manual/install-judgehost.rst | 4 ++-- judge/create_cgroups.in | 21 ++++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/doc/manual/install-judgehost.rst b/doc/manual/install-judgehost.rst index a8d52e4c1c..9e28553e04 100644 --- a/doc/manual/install-judgehost.rst +++ b/doc/manual/install-judgehost.rst @@ -179,8 +179,8 @@ Optionally the timings can be made more stable by not letting the OS schedule any other tasks on the same CPU core the judgedaemon is using: ``GRUB_CMDLINE_LINUX_DEFAULT="quiet cgroup_enable=memory swapaccount=1 isolcpus=2"`` -You have now configured the system to use cgroups. On systems with -cgroups v1, you need to run:: +You have now configured the system to use cgroups. To create +the actual cgroups that DOMjudge will use you need to run:: sudo systemctl enable create-cgroups --now diff --git a/judge/create_cgroups.in b/judge/create_cgroups.in index 1b96cfee66..cca20b00c6 100755 --- a/judge/create_cgroups.in +++ b/judge/create_cgroups.in @@ -9,24 +9,27 @@ JUDGEHOSTUSER=@DOMJUDGE_USER@ CGROUPBASE="/sys/fs/cgroup" -# We do not need to do any of this with cgroup v2. -fs_type=$(awk '$2 == "/sys/fs/cgroup" {print $3}' /proc/mounts) -if [ "$fs_type" = "cgroup2" ]; then - echo "cgroup v2 detected, skipping cgroup creation" >&2 - exit 0 -fi - cgroup_error_and_usage () { echo "$1" >&2 echo "To fix this, please make the following changes: 1. In /etc/default/grub, add 'cgroup_enable=memory swapaccount=1' to GRUB_CMDLINE_LINUX_DEFAULT. - On modern distros (e.g. Debian bullseye and Ubuntu Jammy Jellyfish) which have cgroup v2 enabled by default, - you need to add 'systemd.unified_cgroup_hierarchy=0' as well. 2. Run update-grub 3. Reboot" >&2 exit 1 } +# Check whether cgroup v2 is available. +fs_type=$(awk '$2 == "/sys/fs/cgroup" {print $3}' /proc/mounts) +if [ "$fs_type" = "cgroup2" ]; then + if ! echo "+memory" >> /sys/fs/cgroup/cgroup.subtree_control; then + cgroup_error_and_usage "Error: Cannot add +memory to cgroup.subtree_control; check kernel params. Unable to continue." + fi + if ! echo "+cpuset" >> /sys/fs/cgroup/cgroup.subtree_control; then + cgroup_error_and_usage "Error: Cannot add +cpuset to cgroup.subtree_control; check kernel params. Unable to continue." + fi + exit 0 +fi + for i in cpuset memory; do mkdir -p $CGROUPBASE/$i if [ ! -d $CGROUPBASE/$i/ ]; then