From 210d0820aae80da227176a45295d89e264095a37 Mon Sep 17 00:00:00 2001 From: Johannes Gezachew Date: Fri, 11 Sep 2026 22:45:40 +0300 Subject: [PATCH] tests: skip --max in levels.sh on low-memory Linux systems `zstd --max` needs about 8.5 GB of memory, so compression/levels.sh gets OOM-killed (exit 137) on machines, VMs and containers with less memory than that. On Linux, read the physical memory from /proc/meminfo and lower it to the cgroup v2/v1 memory limit when there is one, since /proc/meminfo reports the host's memory inside a container. Skip the --max step when less than 9 GiB is available, the same way it is already skipped on 32-bit builds. Other platforms are unaffected. Fixes #4748 --- tests/cli-tests/compression/levels.sh | 16 ++++++++++++++++ .../cli-tests/compression/levels.sh.stderr.exact | 3 +++ 2 files changed, 19 insertions(+) diff --git a/tests/cli-tests/compression/levels.sh b/tests/cli-tests/compression/levels.sh index b8230f2a346..bfe60c87c2a 100755 --- a/tests/cli-tests/compression/levels.sh +++ b/tests/cli-tests/compression/levels.sh @@ -9,6 +9,19 @@ datagen > file # Note: command echoing differs between macos and linux, so it's disabled below set +v version_info=$(zstd -V) +# --max needs about 8.5 GB of memory. On Linux, find how much this test can use: +# the physical RAM, or the cgroup (e.g. container) memory limit if it is lower. +mem_kib= +if [ -r /proc/meminfo ]; then + mem_kib=$(awk '$1 == "MemTotal:" { print $2 }' /proc/meminfo) + for limit_file in /sys/fs/cgroup/memory.max /sys/fs/cgroup/memory/memory.limit_in_bytes; do + limit=$(cat "$limit_file" 2>/dev/null) || continue + case "$limit" in + ''|*[!0-9]*) ;; # "max": no limit + *) if [ $((limit / 1024)) -lt "$mem_kib" ]; then mem_kib=$((limit / 1024)); fi ;; + esac + done +fi set -v # Compress with various levels and ensure that their sizes are ordered @@ -19,6 +32,9 @@ zstd -19 file -o file-19.zst -q if echo "$version_info" | grep -q '32-bit'; then # skip --max test: not enough address space cp file-19.zst file-max.zst +elif [ -n "$mem_kib" ] && [ "$mem_kib" -lt 9437184 ]; then + # skip --max test: not enough memory (less than 9 GiB) + cp file-19.zst file-max.zst else zstd --max file -o file-max.zst -q fi diff --git a/tests/cli-tests/compression/levels.sh.stderr.exact b/tests/cli-tests/compression/levels.sh.stderr.exact index fd7c076d277..52936ff2bd0 100644 --- a/tests/cli-tests/compression/levels.sh.stderr.exact +++ b/tests/cli-tests/compression/levels.sh.stderr.exact @@ -13,6 +13,9 @@ zstd -19 file -o file-19.zst -q if echo "$version_info" | grep -q '32-bit'; then # skip --max test: not enough address space cp file-19.zst file-max.zst +elif [ -n "$mem_kib" ] && [ "$mem_kib" -lt 9437184 ]; then + # skip --max test: not enough memory (less than 9 GiB) + cp file-19.zst file-max.zst else zstd --max file -o file-max.zst -q fi