diff --git a/docs/configuration/jvm-options.md b/docs/configuration/jvm-options.md index 35c4bb02..255bafa1 100644 --- a/docs/configuration/jvm-options.md +++ b/docs/configuration/jvm-options.md @@ -158,3 +158,5 @@ When `MEMORY` is greater than or equal to 12G, then the Aikar flags will be adju [MeowIce has created an updated set of JVM flags](https://github.com/MeowIce/meowice-flags?tab=readme-ov-file#why-would-i-have-to-switch-) based on Aikar's flags but with support for optimizations for Java 17 and above The set of flags documented there can be added by setting the environment variable `USE_MEOWICE_FLAGS` to `true`. There is an optional `USE_MEOWICE_GRAALVM_FLAGS` variable to enable GraalVM specific optimizations, defaults to `FALSE`. + +MeowIce's flags use the G1 garbage collector by default. MeowIce also provides a [ZGC version of the flags](https://github.com/MeowIce/meowice-flags#zgc-version-for-large-servers-with-32gb-allocated-heap), which is recommended for servers with 32GB or more of allocated memory and many CPU cores. To use it instead, also set `USE_MEOWICE_ZGC_FLAGS` to `true`. When `MAX_MEMORY` (or `MEMORY`) is larger than 2GB, the soft max heap size is set to 2GB below it, as in MeowIce's flags. diff --git a/docs/variables.md b/docs/variables.md index a34513f3..640f84a4 100644 --- a/docs/variables.md +++ b/docs/variables.md @@ -129,6 +129,12 @@ alternatively, you can mount: /etc/localtime:/etc/localtime:ro true ⬜️ + + USE_MEOWICE_ZGC_FLAGS + uses the ZGC version of MeowIce's flags instead of the G1 version when USE_MEOWICE_FLAGS is also TRUE + false + ⬜️ + JVM_OPTS General JVM options can be passed to the Minecraft Server invocation by passing a JVM_OPTS environment variable. The JVM requires -XX options to precede -X options, so those can be declared in JVM_XX_OPTS. Both variables are space-delimited, raw JVM arguments diff --git a/scripts/start-finalExec-jvmFlags b/scripts/start-finalExec-jvmFlags index 842fb49f..29c566de 100755 --- a/scripts/start-finalExec-jvmFlags +++ b/scripts/start-finalExec-jvmFlags @@ -3,6 +3,7 @@ : "${USE_AIKAR_FLAGS:=false}" : "${USE_MEOWICE_FLAGS:=false}" : "${USE_MEOWICE_GRAALVM_FLAGS:=false}" +: "${USE_MEOWICE_ZGC_FLAGS:=false}" if isTrue "${USE_MEOWICE_FLAGS}" || isTrue "${USE_MEOWICE_GRAALVM_FLAGS}"; then java_major_version=$(mc-image-helper java-release) @@ -18,7 +19,29 @@ if isTrue "${USE_MEOWICE_FLAGS}"; then fi fi -if isTrue "${USE_AIKAR_FLAGS}" || isTrue "${USE_MEOWICE_FLAGS}"; then +use_meowice_zgc=false +if isTrue "${USE_MEOWICE_FLAGS}" && isTrue "${USE_MEOWICE_ZGC_FLAGS}"; then + use_meowice_zgc=true +fi + +if isTrue "${use_meowice_zgc}"; then + log "Using MeowIce's ZGC flags" + JVM_XX_OPTS="${JVM_XX_OPTS} + -XX:+UseZGC + -XX:-ZProactive + -XX:+UnlockExperimentalVMOptions + -XX:+DisableExplicitGC + -XX:+AlwaysPreTouch + -XX:+PerfDisableSharedMem + " + # MeowIce sets the soft max heap size to 2GB below the max heap size + if [[ $MAX_MEMORY ]] && max_memory_bytes=$(normalizeMemSize "${MAX_MEMORY}") \ + && (( max_memory_bytes > $(normalizeMemSize 2048m) )); then + JVM_XX_OPTS="${JVM_XX_OPTS} + -XX:SoftMaxHeapSize=$(( max_memory_bytes / 1048576 - 2048 ))M + " + fi +elif isTrue "${USE_AIKAR_FLAGS}" || isTrue "${USE_MEOWICE_FLAGS}"; then # From https://mcflags.emc.gs/ if isTrue "${USE_MEOWICE_FLAGS}"; then log "Using MeowIce's flags" @@ -81,8 +104,6 @@ if isTrue "${USE_MEOWICE_FLAGS}"; then JVM_XX_OPTS="${JVM_XX_OPTS} -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions - -XX:G1SATBBufferEnqueueingThresholdPercent=30 - -XX:G1ConcMarkStepDurationMillis=5 -XX:+UseNUMA -XX:-DontCompileHugeMethods -XX:MaxNodeLimit=240000 @@ -94,7 +115,6 @@ if isTrue "${USE_MEOWICE_FLAGS}"; then -XX:NmethodSweepActivity=1 -XX:+UseFastUnorderedTimeStamps -XX:+UseCriticalJavaThreadPriority - -XX:AllocatePrefetchStyle=3 -XX:+AlwaysActAsServerClassMachine -XX:+UseTransparentHugePages -XX:LargePageSizeInBytes=2M @@ -124,6 +144,17 @@ if isTrue "${USE_MEOWICE_FLAGS}"; then -XX:+UseCopySignIntrinsic -XX:+UseVectorStubs " + if isTrue "${use_meowice_zgc}"; then + JVM_XX_OPTS="${JVM_XX_OPTS} + -XX:AllocatePrefetchStyle=1 + " + else + JVM_XX_OPTS="${JVM_XX_OPTS} + -XX:G1SATBBufferEnqueueingThresholdPercent=30 + -XX:G1ConcMarkStepDurationMillis=5 + -XX:AllocatePrefetchStyle=3 + " + fi if [[ $(arch) == "x86_64" ]]; then JVM_XX_OPTS="${JVM_XX_OPTS} -XX:+UseFastStosb