Skip to content

Commit a0728be

Browse files
committed
Error when missing cgroup value memory.peak in the kernel
This replaces the `memory.memsw.max_usage_in_bytes` value from cgroup v1. We always assume it's there so we should fail if it is not. Otherwise things silently degrade in a way they would not have before. Also document this in the create_cgroups script and manual. Addresses #2763
1 parent 29a6717 commit a0728be

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

doc/manual/install-judgehost.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ Optionally the timings can be made more stable by not letting the OS schedule
179179
any other tasks on the same CPU core the judgedaemon is using:
180180
``GRUB_CMDLINE_LINUX_DEFAULT="quiet cgroup_enable=memory swapaccount=1 isolcpus=2"``
181181

182+
On modern systems where cgroup v2 is available, DOMjudge will try to
183+
use that. This requires kernel versions 5.19 or 6.0 or later to
184+
support reporting peak memory usage. If not found, the system will try
185+
to fall back to cgroup v1, but this might require you to add
186+
``systemd.unified_cgroup_hierarchy=0`` to the boot options as well.
187+
182188
You have now configured the system to use cgroups. To create
183189
the actual cgroups that DOMjudge will use you need to run::
184190

judge/create_cgroups.in

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,19 @@ if [ "$fs_type" = "cgroup2" ]; then
2525
major=$(echo "$kernel_version" | cut -d '.' -f 1)
2626
minor=$(echo "$kernel_version" | cut -d '.' -f 2)
2727
if [ "$major" -lt 5 ] || { [ "$major" -eq 5 ] && [ "$minor" -lt 19 ]; }; then
28-
echo "WARNING: Kernel ($kernel_version) is too old to record peak RAM usage" >&2
28+
cgroup_error_and_usage "Error: kernel ($kernel_version) is too old to record peak RAM usage with cgroup V2.
29+
You can try using cgroup V1 by adding systemd.unified_cgroup_hierarchy=0 to the kernel params."
2930
fi
3031
if ! echo "+memory" >> /sys/fs/cgroup/cgroup.subtree_control; then
3132
cgroup_error_and_usage "Error: Cannot add +memory to cgroup.subtree_control; check kernel params. Unable to continue."
3233
fi
3334
if ! echo "+cpuset" >> /sys/fs/cgroup/cgroup.subtree_control; then
3435
cgroup_error_and_usage "Error: Cannot add +cpuset to cgroup.subtree_control; check kernel params. Unable to continue."
3536
fi
36-
exit 0
3737
fi
3838

39+
# Trying cgroup V1:
40+
3941
for i in cpuset memory; do
4042
mkdir -p $CGROUPBASE/$i
4143
if [ ! -d $CGROUPBASE/$i/ ]; then

judge/runguard.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ void output_cgroup_stats_v2(double *cputime)
504504
int64_t max_usage = 0;
505505
ret = cgroup_get_value_int64(cg_controller, "memory.peak", &max_usage);
506506
if ( ret == ECGROUPVALUENOTEXIST ) {
507-
write_meta("internal-warning", "Kernel too old and does not support memory.peak");
507+
error(ret, "kernel too old and does not support memory.peak");
508508
} else if ( ret!=0 ) {
509509
error(ret,"get cgroup value memory.peak");
510510
}

0 commit comments

Comments
 (0)