Menu

Tools

Server start command

Pick what you run and how much memory the machine has. You get the Java version that Minecraft release actually requires, the flag set the community standardised on, tuned to your heap, and a start script and Docker Compose file you can paste straight in.

Software
Leaves
Minecraft
1.21.11
Java required
Java 21 or newer
Heap
32 GB

Start command

One line. The heap is fixed at both ends on purpose, which is what -Xms and -Xmx matching means.

Get the jar
java -Xms32G -Xmx32G -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=40 -XX:G1MaxNewSizePercent=50 -XX:G1HeapRegionSize=16M -XX:G1ReservePercent=15 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=20 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -jar server.jar nogui

start.sh

The same thing as a script, with a restart loop.

#!/usr/bin/env bash
# Start script for Leaves on Minecraft 1.21.11
# Generated by MCReference. Restarts the server if it stops.
set -euo pipefail

while true; do
  java -Xms32G -Xmx32G \
    -XX:+UseG1GC \
    -XX:+ParallelRefProcEnabled \
    -XX:MaxGCPauseMillis=200 \
    -XX:+UnlockExperimentalVMOptions \
    -XX:+DisableExplicitGC \
    -XX:+AlwaysPreTouch \
    -XX:G1NewSizePercent=40 \
    -XX:G1MaxNewSizePercent=50 \
    -XX:G1HeapRegionSize=16M \
    -XX:G1ReservePercent=15 \
    -XX:G1HeapWastePercent=5 \
    -XX:G1MixedGCCountTarget=4 \
    -XX:InitiatingHeapOccupancyPercent=20 \
    -XX:G1MixedGCLiveThresholdPercent=90 \
    -XX:G1RSetUpdatingPauseTimePercent=5 \
    -XX:SurvivorRatio=32 \
    -XX:+PerfDisableSharedMem \
    -XX:MaxTenuringThreshold=1 \
    -jar server.jar nogui
  echo "Server stopped. Restarting in 5 seconds, press Ctrl+C to quit."
  sleep 5
done

compose.yaml

Docker Compose, on the official Eclipse Temurin 21 image.

services:
  minecraft:
    image: eclipse-temurin:21-jre
    container_name: minecraft
    working_dir: /data
    command: >
      java -Xms32G -Xmx32G
      -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=40 -XX:G1MaxNewSizePercent=50 -XX:G1HeapRegionSize=16M -XX:G1ReservePercent=15 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=20 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1
      -jar server.jar nogui
    stdin_open: true
    tty: true
    restart: unless-stopped
    ports:
      - "25565:25565"
    volumes:
      - ./data:/data
    # A server needs its heap plus room for the JVM itself and the OS page cache.
    mem_limit: 40g

What these flags actually do

They are Aikar’s flags, the set Paper servers have used since 2018 and still the sensible default. They tune G1, the garbage collector, to favour many small pauses over occasional long ones. A Minecraft server runs on a single tick loop, so a 400ms garbage collection is 8 dropped ticks that every player feels; the same work split into short pauses is invisible.

-Xms and -Xmx are set to the same value deliberately. Letting the heap grow means the JVM spends early game time resizing it, and -XX:+AlwaysPreTouch claims the pages up front so that cost is paid at startup rather than mid-game.

Above 12 GB the numbers change: the nursery is allowed to grow and the region size doubles to 16M. A large heap running the small-heap values spends its life in mixed collections, which is why a copied 8 GB script can make a 32 GB server worse rather than better. This page picks the right set from the memory you chose.

Do not give the JVM every gigabyte the machine has. The server also needs room for the operating system and its page cache, which is what actually keeps world chunks fast. On a 16 GB machine, a 10 to 12 GB heap is healthier than 15.

Common questions

Do Aikar's flags still work on modern Java?

Yes. They target the G1 collector, which ships in Java 8, 17, 21 and 25 alike, so the same flags are correct across every version Minecraft has required. Nothing here needs changing when you upgrade Java. G1 is not the only collector worth knowing about, though: ZGC and Shenandoah come up increasingly often for very large heaps, where G1's pause times can still be noticeable. For the heap sizes most Minecraft servers run, G1 with these flags remains the well-tested default.

How much RAM should I give the server?

Enough for your world and player count, and never all of the machine's memory. Vanilla with a handful of players is happy at 2 to 4 GB; a large modpack wants 8 or more. Leave at least a quarter of the machine free for the operating system's page cache.

Why are -Xms and -Xmx the same?

So the JVM never resizes the heap while players are online. Resizing is work done at the worst possible moment, and combined with AlwaysPreTouch it means the memory is claimed at startup instead of during a busy tick.

Do these flags work for a proxy like Velocity?

A proxy needs far less memory than a server, usually 512 MB to 1 GB, because it holds no world. The flags do no harm, but the heap size is the part that matters and it should be much smaller.

Will this fix my lag?

Only if the lag is garbage collection. Flags cannot fix a slow plugin, an overloaded chunk generator or a machine that is out of CPU. Check your server's own timings report first; these flags remove one specific cause, not all of them.

Is this information wrong or missing something? .