aboutsummaryrefslogtreecommitdiffstats
path: root/container-disc
diff options
context:
space:
mode:
authorValerij Fredriksen <freva@users.noreply.github.com>2021-10-28 17:27:35 +0200
committerGitHub <noreply@github.com>2021-10-28 17:27:35 +0200
commitce8e3c5a2a75dc1098b92662ee2724e96060f11d (patch)
treed9654c7357ba211897ddeafc1e61a43dd6348938 /container-disc
parent0b3e5ffe02fa2b51ffe37bc5f1e82022c3eeb672 (diff)
parentf716970e3de6a4bcfce60245b77674da1ffb3b9e (diff)
Merge pull request #19781 from vespa-engine/hakonhall/add-method-for-getting-value-of-cgroup-v2-interface-file
Add method for getting value of cgroup v2 interface file
Diffstat (limited to 'container-disc')
-rwxr-xr-xcontainer-disc/src/main/sh/vespa-start-container-daemon.sh46
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 7f281d02fd3..ec3366a62d7 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