imbajin commented on code in PR #3320:
URL: https://github.com/apache/hugegraph/pull/3320#discussion_r4248130252
##########
hugegraph-server/hugegraph-dist/src/assembly/static/bin/util.sh:
##########
@@ -413,6 +413,94 @@ function wait_for_startup() {
return 1
}
+# Return the remaining memory (MiB) under visible cgroup hard limits. Keep
+# missing/unlimited controllers empty so ordinary host sizing stays unchanged.
+function cgroup_free_memory() {
+ local root="${1:-/sys/fs/cgroup}"
+ local membership="${2:-/proc/self/cgroup}"
+ local mountinfo="${3:-/proc/self/mountinfo}"
+ local base="" path="" limit_file="" usage_file=""
+ local version=""
+ local id controllers member
+ if [[ -r "$membership" ]]; then
+ while IFS=: read -r id controllers member; do
+ if [[ ",$controllers," == *,memory,* ]]; then
+ base="$root/memory"
+ path="$member"
+ limit_file="memory.limit_in_bytes"
+ usage_file="memory.usage_in_bytes"
+ version="cgroup"
+ break
+ elif [[ "$id" == 0 && -z "$controllers" ]]; then
+ base="$root"
+ path="$member"
+ limit_file="memory.max"
+ usage_file="memory.current"
+ version="cgroup2"
+ fi
+ done < "$membership"
+ fi
+ [[ -n "$base" ]] || return 0
+
+ # Mount points and exposed roots need not use the conventional hierarchy.
+ # The kernel escapes whitespace/backslashes in mountinfo path fields.
+ local mount_root="" mountpoint=""
+ if [[ -r "$mountinfo" ]]; then
+ read -r mount_root mountpoint < <(awk -v version="$version" '
+ {
+ split($0, parts, " - ");
+ split(parts[2], tail, " ");
+ if (tail[1] == version && (version == "cgroup2" ||
+ index("," tail[3] ",", ",memory,") > 0)) {
+ print $4, $5;
+ exit;
Review Comment:
Fixed mount selection on the original source branch. The helper checks that
a mount covers the process membership and scans the usable matches to retain
the broadest visible ancestor view, so an unrelated or narrower first mount
cannot hide the applicable limit.
The unrelated-first fixture now returns 768 MiB, and a
narrow-first/wider-second ancestor fixture returns the tighter 512 MiB budget.
Cgroup fixtures, shell checks, clean compilation and three independent final
reviews passed. New-head CI and live Linux pressure validation remain pending.
##########
hugegraph-server/hugegraph-dist/src/assembly/static/bin/util.sh:
##########
@@ -413,6 +413,94 @@ function wait_for_startup() {
return 1
}
+# Return the remaining memory (MiB) under visible cgroup hard limits. Keep
+# missing/unlimited controllers empty so ordinary host sizing stays unchanged.
+function cgroup_free_memory() {
+ local root="${1:-/sys/fs/cgroup}"
+ local membership="${2:-/proc/self/cgroup}"
+ local mountinfo="${3:-/proc/self/mountinfo}"
+ local base="" path="" limit_file="" usage_file=""
+ local version=""
+ local id controllers member
+ if [[ -r "$membership" ]]; then
+ while IFS=: read -r id controllers member; do
+ if [[ ",$controllers," == *,memory,* ]]; then
+ base="$root/memory"
+ path="$member"
+ limit_file="memory.limit_in_bytes"
+ usage_file="memory.usage_in_bytes"
+ version="cgroup"
+ break
+ elif [[ "$id" == 0 && -z "$controllers" ]]; then
+ base="$root"
+ path="$member"
+ limit_file="memory.max"
+ usage_file="memory.current"
+ version="cgroup2"
+ fi
+ done < "$membership"
+ fi
+ [[ -n "$base" ]] || return 0
+
+ # Mount points and exposed roots need not use the conventional hierarchy.
+ # The kernel escapes whitespace/backslashes in mountinfo path fields.
+ local mount_root="" mountpoint=""
+ if [[ -r "$mountinfo" ]]; then
+ read -r mount_root mountpoint < <(awk -v version="$version" '
+ {
+ split($0, parts, " - ");
+ split(parts[2], tail, " ");
+ if (tail[1] == version && (version == "cgroup2" ||
+ index("," tail[3] ",", ",memory,") > 0)) {
+ print $4, $5;
+ exit;
+ }
+ }' "$mountinfo") || true
+ if [[ -n "$mountpoint" ]]; then
+ printf -v base '%b' "$mountpoint"
+ printf -v mount_root '%b' "$mount_root"
+ if [[ "$mount_root" != / && "$path" == "$mount_root" ]]; then
+ path=/
+ elif [[ "$mount_root" != / && "$path" == "$mount_root/"* ]]; then
+ path="${path#"$mount_root"}"
+ fi
+ fi
+ fi
+
+ # A cgroup namespace can expose its own root while /proc still names a
+ # host-relative membership. Fall back to the visible mount root in that
+ # case; never follow a membership path out of the controller mount.
+ local dir="$base"
+ if [[ "$path" == /* && "$path" != *"/../"* && "$path" != */.. &&
+ -d "$base$path" ]]; then
+ dir="$base$path"
+ dir="${dir%/}"
+ fi
+ local limit usage available smallest=""
+ while :; do
+ limit=""
+ usage=0
+ [[ ! -r "$dir/$limit_file" ]] || read -r limit < "$dir/$limit_file" ||
true
+ [[ ! -r "$dir/$usage_file" ]] || read -r usage < "$dir/$usage_file" ||
true
+ if [[ "$limit" =~ ^[0-9]+$ ]]; then
+ [[ "$usage" =~ ^[0-9]+$ ]] || usage=0
+ # awk avoids shell integer overflow for v1's unlimited sentinel.
+ available=$(awk -v limit="$limit" -v usage="$usage" 'BEGIN {
+ remaining = limit - usage;
+ printf "%.0f\n", (remaining > 0 ? int(remaining / 1048576) :
0);
Review Comment:
Fixed reclaimable-cache accounting on the original source branch. The helper
discounts v2 inactive_file or v1 total_inactive_file at the applicable
hierarchy level; missing or invalid statistics retain the conservative usage
budget. An inconsistent inactive value larger than usage receives zero cache
credit.
The warm-cache fixture no longer rejects startup with a 256 MiB budget, and
ancestor/v1/inconsistent-stat controls pass. Shell checks, clean compilation
and three independent final reviews passed. This verifies the calculation; a
live Linux warm-cache pressure run remains to be completed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]