From 298ed2a6c44cde90b4262b884169c53b8deda508 Mon Sep 17 00:00:00 2001 From: Michele Bertasi <405934+mbrt@users.noreply.github.com> Date: Thu, 26 Mar 2026 22:19:14 +0100 Subject: Add support for cgroup limits (#443) * Add cgroup package * Refactor procGgroup * Add testdata generation * Add v1 testdata generation * Move scripts around * Add integration test in CI * Remove cgroup v1 * Move to cgroup struct * Remove half-core test as it's redundant --- bin/snapshot-cgroup | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 bin/snapshot-cgroup (limited to 'bin/snapshot-cgroup') diff --git a/bin/snapshot-cgroup b/bin/snapshot-cgroup new file mode 100755 index 0000000..5fed85f --- /dev/null +++ b/bin/snapshot-cgroup @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +# +# snapshot-cgroup - Copy cgroup v2 files from the live system into a +# directory tree suitable for use with TestIntegrationCgroupLimits. +# +# Usage: snapshot-cgroup +# +# The script reads /proc/self/cgroup to find the v2 group path and copies +# exactly the files that the cgroup package needs: +# +# proc/self/cgroup +# sys/fs/cgroup//cpu.max +# sys/fs/cgroup//memory.max + +set -euo pipefail + +if [[ $# -ne 1 ]]; then + echo "Usage: $0 " >&2 + exit 1 +fi + +out="$1" +mkdir -p "$out" + +copy_file() { + local src="$1" dst="$out/$2" + mkdir -p "$(dirname "$dst")" + cp "$src" "$dst" +} + +copy_file /proc/self/cgroup proc/self/cgroup + +group=$(awk -F: '/^0::/ { print $3 }' /proc/self/cgroup) +cgdir="/sys/fs/cgroup${group}" + +for f in cpu.max memory.max; do + if [[ -f "$cgdir/$f" ]]; then + copy_file "$cgdir/$f" "sys/fs/cgroup${group}/$f" + fi +done + +echo "Snapshot written to $out" -- cgit v1.2.3