Memory: -Xms and -Xmx
-Xmx is the maximum heap Java may use and -Xms the starting size. For a Minecraft server, set them to the same value so Java does not keep resizing the heap.
Do not give Java all of the machine's or container's memory. Java uses memory outside the heap too, for threads, native libraries and the garbage collector. Leave around 1 to 1.5 GB of headroom, more on large modpacks, or the operating system or container may kill the process when it goes over.
Aikar's flags
Aikar's flags are a tuned set of G1 garbage collector settings that most Paper servers use. They make collections shorter and more frequent, which shows up as fewer noticeable freezes. For heaps up to about 12 GB:
- -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200
- -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch
- -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M
- -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4
- -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90
- -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1
Above 12 GB
For larger heaps, change G1NewSizePercent to 40, G1MaxNewSizePercent to 50, G1HeapRegionSize to 16M, G1ReservePercent to 15 and InitiatingHeapOccupancyPercent to 20. Very few servers need more than 12 GB; if yours does, check that the memory is really in use before adding more.
Putting it together
A complete command looks like java -Xms6G -Xmx6G followed by the flags, then -jar server.jar --nogui. On a hosted server you usually do not write this by hand: the panel builds the command from your plan's memory and a startup template, and on StormNodes the Startup page shows the variables you can change.
What flags will not fix
Flags tune garbage collection. They do not fix a plugin that blocks the main thread, a redstone clock or an oversized view distance. If the server lags with free memory, profile it with spark before touching flags.