Skip to content

Commit 6a71104

Browse files
committed
use 'cgroup_util_read_cgroup_memory_limit_with_fallback' in boot scripts
1 parent 6320909 commit 6a71104

File tree

2 files changed

+8
-28
lines changed

2 files changed

+8
-28
lines changed

bin/heroku-php-apache2

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -394,26 +394,16 @@ ram=
394394
# this will handle cgroups v1 and v2, and, for v2, prefer memory.high over memory.max over memory.low
395395
if [[ -d "/proc" ]]; then # check for /proc, just in case someone is running this on e.g. macOS
396396
[[ $verbose ]] && echo "Checking cgroupfs for memory limits..." >&2
397-
ram=$(CGROUP_UTIL_VERBOSE=${verbose:+1} cgroup_util_read_cgroup_memory_limit) || {
397+
ram=$(CGROUP_UTIL_VERBOSE=${verbose:+1} cgroup_util_read_cgroup_memory_limit_with_fallback) || {
398398
# 99 means the limit was exceeded; in verbose mode, a message was then already printed
399-
if (( $? == 99)); then
400-
ram="512M"
401-
echo "Assuming RAM to be ${ram} Bytes" >&2
402-
elif [[ $verbose ]]; then
399+
if (( $? != 99)) && [[ $verbose ]]; then
403400
echo "No cgroup memory limits found" >&2
404401
fi
405402
}
406403
fi
407404
if [[ -z "$ram" ]]; then
408-
# for maximum backward compatibility, use a hard-coded path's value as the default if it exists
409-
mlib="/sys/fs/cgroup/memory/memory.limit_in_bytes"
410-
if [[ -f "$mlib" ]]; then
411-
[[ $verbose ]] && echo "Reading available RAM from '$mlib'" >&2
412-
ram=$(cat "$mlib")
413-
else
414-
ram="512M"
415-
echo "Assuming RAM to be ${ram} Bytes" >&2
416-
fi
405+
ram="512M"
406+
echo "Assuming RAM to be ${ram} Bytes" >&2
417407
fi
418408

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

bin/heroku-php-nginx

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -394,26 +394,16 @@ ram=
394394
# this will handle cgroups v1 and v2, and, for v2, prefer memory.high over memory.max over memory.low
395395
if [[ -d "/proc" ]]; then # check for /proc, just in case someone is running this on e.g. macOS
396396
[[ $verbose ]] && echo "Checking cgroupfs for memory limits..." >&2
397-
ram=$(CGROUP_UTIL_VERBOSE=${verbose:+1} cgroup_util_read_cgroup_memory_limit) || {
397+
ram=$(CGROUP_UTIL_VERBOSE=${verbose:+1} cgroup_util_read_cgroup_memory_limit_with_fallback) || {
398398
# 99 means the limit was exceeded; in verbose mode, a message was then already printed
399-
if (( $? == 99)); then
400-
ram="512M"
401-
echo "Assuming RAM to be ${ram} Bytes" >&2
402-
elif [[ $verbose ]]; then
399+
if (( $? != 99)) && [[ $verbose ]]; then
403400
echo "No cgroup memory limits found" >&2
404401
fi
405402
}
406403
fi
407404
if [[ -z "$ram" ]]; then
408-
# for maximum backward compatibility, use a hard-coded path's value as the default if it exists
409-
mlib="/sys/fs/cgroup/memory/memory.limit_in_bytes"
410-
if [[ -f "$mlib" ]]; then
411-
[[ $verbose ]] && echo "Reading available RAM from '$mlib'" >&2
412-
ram=$(cat "$mlib")
413-
else
414-
ram="512M"
415-
echo "Assuming RAM to be ${ram} Bytes" >&2
416-
fi
405+
ram="512M"
406+
echo "Assuming RAM to be ${ram} Bytes" >&2
417407
fi
418408

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

0 commit comments

Comments
 (0)