diff options
author | Håkon Hallingstad <hakon@verizonmedia.com> | 2021-10-28 17:24:42 +0200 |
---|---|---|
committer | Håkon Hallingstad <hakon@verizonmedia.com> | 2021-10-28 17:24:42 +0200 |
commit | f716970e3de6a4bcfce60245b77674da1ffb3b9e (patch) | |
tree | 7b0b1306de06b482b6675a4088acad9c38b28ab1 /container-disc | |
parent | 8964cbed0c69e539235eb482651e6f84efd22898 (diff) |
Add method for getting value of cgroup v2 interface file
Diffstat (limited to 'container-disc')
-rwxr-xr-x | container-disc/src/main/sh/vespa-start-container-daemon.sh | 46 |
1 files changed, 46 insertions, 0 deletions
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 |