Skip to content

Commit

Permalink
use 'cgroup_util_read_cgroup_memory_limit_with_fallback' in boot scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
dzuelke committed Jun 24, 2024
1 parent 6320909 commit 6a71104
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 28 deletions.
18 changes: 4 additions & 14 deletions bin/heroku-php-apache2
Original file line number Diff line number Diff line change
Expand Up @@ -394,26 +394,16 @@ ram=
# this will handle cgroups v1 and v2, and, for v2, prefer memory.high over memory.max over memory.low
if [[ -d "/proc" ]]; then # check for /proc, just in case someone is running this on e.g. macOS
[[ $verbose ]] && echo "Checking cgroupfs for memory limits..." >&2
ram=$(CGROUP_UTIL_VERBOSE=${verbose:+1} cgroup_util_read_cgroup_memory_limit) || {
ram=$(CGROUP_UTIL_VERBOSE=${verbose:+1} cgroup_util_read_cgroup_memory_limit_with_fallback) || {
# 99 means the limit was exceeded; in verbose mode, a message was then already printed
if (( $? == 99)); then
ram="512M"
echo "Assuming RAM to be ${ram} Bytes" >&2
elif [[ $verbose ]]; then
if (( $? != 99)) && [[ $verbose ]]; then
echo "No cgroup memory limits found" >&2
fi
}
fi
if [[ -z "$ram" ]]; then
# for maximum backward compatibility, use a hard-coded path's value as the default if it exists
mlib="/sys/fs/cgroup/memory/memory.limit_in_bytes"
if [[ -f "$mlib" ]]; then
[[ $verbose ]] && echo "Reading available RAM from '$mlib'" >&2
ram=$(cat "$mlib")
else
ram="512M"
echo "Assuming RAM to be ${ram} Bytes" >&2
fi
ram="512M"
echo "Assuming RAM to be ${ram} Bytes" >&2
fi

# read number of available processor cores in a portable (Linux, macOS, BSDs) fashion (leading underscore is not always there)
Expand Down
18 changes: 4 additions & 14 deletions bin/heroku-php-nginx
Original file line number Diff line number Diff line change
Expand Up @@ -394,26 +394,16 @@ ram=
# this will handle cgroups v1 and v2, and, for v2, prefer memory.high over memory.max over memory.low
if [[ -d "/proc" ]]; then # check for /proc, just in case someone is running this on e.g. macOS
[[ $verbose ]] && echo "Checking cgroupfs for memory limits..." >&2
ram=$(CGROUP_UTIL_VERBOSE=${verbose:+1} cgroup_util_read_cgroup_memory_limit) || {
ram=$(CGROUP_UTIL_VERBOSE=${verbose:+1} cgroup_util_read_cgroup_memory_limit_with_fallback) || {
# 99 means the limit was exceeded; in verbose mode, a message was then already printed
if (( $? == 99)); then
ram="512M"
echo "Assuming RAM to be ${ram} Bytes" >&2
elif [[ $verbose ]]; then
if (( $? != 99)) && [[ $verbose ]]; then
echo "No cgroup memory limits found" >&2
fi
}
fi
if [[ -z "$ram" ]]; then
# for maximum backward compatibility, use a hard-coded path's value as the default if it exists
mlib="/sys/fs/cgroup/memory/memory.limit_in_bytes"
if [[ -f "$mlib" ]]; then
[[ $verbose ]] && echo "Reading available RAM from '$mlib'" >&2
ram=$(cat "$mlib")
else
ram="512M"
echo "Assuming RAM to be ${ram} Bytes" >&2
fi
ram="512M"
echo "Assuming RAM to be ${ram} Bytes" >&2
fi

# read number of available processor cores in a portable (Linux, macOS, BSDs) fashion (leading underscore is not always there)
Expand Down

0 comments on commit 6a71104

Please sign in to comment.