Allowed MEMORY to be unset and let JVM calculate from container

#742
This commit is contained in:
Geoff Bourne 2021-10-31 09:42:27 -05:00
parent c7f1d13f9b
commit 3713d9c4e8
2 changed files with 19 additions and 9 deletions

View file

@ -1288,7 +1288,9 @@ The values of all three are passed directly to the JVM and support format/units
-e MEMORY=2G
> NOTE: the settings above only set the Java **heap** limits. Memory resource requests and limits on the overall container should also account for non-heap memory usage. An extra 25% is [a general best practice](https://dzone.com/articles/best-practices-java-memory-arguments-for-container).
> To let the JVM calculate the heap size from the container declared memory limit, unset `MEMORY` with an empty value, such as `-e MEMORY=""`.
> The settings above only set the Java **heap** limits. Memory resource requests and limits on the overall container should also account for non-heap memory usage. An extra 25% is [a general best practice](https://dzone.com/articles/best-practices-java-memory-arguments-for-container).
### JVM Options

View file

@ -70,8 +70,8 @@ if [[ ${GUI} = false || ${GUI} = FALSE ]]; then
EXTRA_ARGS+=" nogui"
fi
# put these prior JVM_OPTS at the end to give any memory settings there higher precedence
log "Setting initial memory to ${INIT_MEMORY:=${MEMORY}} and max to ${MAX_MEMORY:=${MEMORY}}"
: "${INIT_MEMORY:=${MEMORY}}"
: "${MAX_MEMORY:=${MEMORY}}"
expandedDOpts=
if [ -n "$JVM_DD_OPTS" ]; then
@ -157,7 +157,15 @@ if isTrue "${DEBUG_MEMORY}"; then
free -m
fi
JVM_OPTS="-Xms${INIT_MEMORY} -Xmx${MAX_MEMORY} ${JVM_OPTS}"
if [[ ${INIT_MEMORY} || ${MAX_MEMORY} ]]; then
log "Setting initial memory to ${INIT_MEMORY:=${MEMORY}} and max to ${MAX_MEMORY:=${MEMORY}}"
if [[ ${INIT_MEMORY} ]]; then
JVM_OPTS="-Xms${INIT_MEMORY} ${JVM_OPTS}"
fi
if [[ ${MAX_MEMORY} ]]; then
JVM_OPTS="-Xmx${MAX_MEMORY} ${JVM_OPTS}"
fi
fi
function copyFilesForCurseForge() {
# copy player modification files unconditionally since their
@ -197,11 +205,11 @@ elif [[ ${TYPE} == "CURSEFORGE" ]]; then
cat > "${FTB_DIR}/settings-local.sh" <<EOF
export MIN_RAM="${INIT_MEMORY}"
export MAX_RAM="${MAX_MEMORY}"
export JAVA_PARAMETERS="${JVM_XX_OPTS} -Xms${INIT_MEMORY} ${JVM_OPTS} $expandedDOpts"
export JAVA_PARAMETERS="${JVM_XX_OPTS} ${JVM_OPTS} $expandedDOpts"
EOF
# patch CurseForge cfg file, if present
if [ -f "${FTB_DIR}/settings.cfg" ]; then
if [ -f "${FTB_DIR}/settings.cfg" ] && [[ ${MAX_MEMORY} ]]; then
sed -i "s/MAX_RAM=[^;]*/MAX_RAM=${MAX_MEMORY}/" "${FTB_DIR}/settings.cfg"
fi
@ -210,7 +218,7 @@ EOF
finalArgs="${FTB_SERVER_START}"
if isTrue ${SETUP_ONLY:=false}; then
if isTrue "${SETUP_ONLY:=false}"; then
echo "SETUP_ONLY: ${finalArgs}"
exit
fi
@ -248,11 +256,11 @@ else
exit
fi
if isTrue ${DEBUG_EXEC}; then
if isTrue "${DEBUG_EXEC}"; then
set -x
fi
if isTrue ${EXEC_DIRECTLY:-false}; then
if isTrue "${EXEC_DIRECTLY:-false}"; then
exec java "${finalArgs[@]}"
else
exec mc-server-runner ${bootstrapArgs} "${mcServerRunnerArgs[@]}" java "${finalArgs[@]}"