From f716970e3de6a4bcfce60245b77674da1ffb3b9e Mon Sep 17 00:00:00 2001 From: HÃ¥kon Hallingstad Date: Thu, 28 Oct 2021 17:24:42 +0200 Subject: Add method for getting value of cgroup v2 interface file --- .../src/main/sh/vespa-start-container-daemon.sh | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'container-disc') diff --git a/container-disc/src/main/sh/vespa-start-container-daemon.sh b/container-disc/src/main/sh/vespa-start-container-daemon.sh index 28c2c00a921..54791129a74 100755 --- a/container-disc/src/main/sh/vespa-start-container-daemon.sh +++ b/container-disc/src/main/sh/vespa-start-container-daemon.sh @@ -59,6 +59,52 @@ getconfig() { eval "$cmds" } +# Print the value of the cgroups v2 interface filename $1 for current process, +# returning 0 on success. $1 is e.g. memory.max. +vespa_cg2get() { + local filename="$1" + + # Verify cgroups v2 + if ! [ -e /sys/fs/cgroup/cgroup.controllers ]; then + return 1 + fi + + local cgroup_content + if ! cgroup_content=$(< /proc/self/cgroup); then + echo "No such file: /proc/self/cgroup" >& 2 + return 1 + fi + + local slice + while read -r; do + if [ -n "$slice" ]; then + echo "More than one line in /proc/self/cgroup" >&2 + return 1 + fi + # Ignore prefix of line up to and including the right-most ':'. + # Example line: "0::/user.slice/user-1002.slice/session-29.scope" + slice="${REPLY##*:}" + done <<< "$cgroup_content" + + local root_dir=/sys/fs/cgroup + local leaf_dir="$root_dir$slice" + local current_dir="$leaf_dir" + + while true; do + local path="$current_dir"/"$filename" + if [ -r "$path" ]; then + cat "$path" + return 0 + fi + + current_dir="${current_dir%/*}" + if (( ${#current_dir} < ${#root_dir} )); then + echo "No such filename was found at $leaf_dir: $filename" >&2 + return 1 + fi + done +} + configure_memory() { consider_fallback jvm_minHeapsize 1536 consider_fallback jvm_heapsize 1536 -- cgit v1.2.3