So I have been hosting Minecraft servers for friends for a while now, and I noticed that some of them are using way more ram than they should.
The main server I will be focusing on this thread has the following config:
- Paper with plugins
- Java 21
- Runs in a Docker container (Ubuntu based)
- Managed by Pterodactyl
- 10GB Heap allocated in JVM arguments.
Full list of JVM arguments: java -Xmx10G -Xms10G -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -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 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true -jar server.jar --nogui
Disclaimer: I am running this test in parallel to normal server things, so things may be updated in the middle of the test, and player activity also affects the results, so take them with a grain of salt.
I learned about a thing called “memory fragmentation” a while ago and was suspecting if this was the case, rather than an actual memory leak. All of my plugins are very popular and leaks would have already been caught much earlier, especially ones that are to the degree I am seeing.
Memory usage using different memory allocators:
| Malloc provider | Memory usage after a while |
|---|---|
| Glibc (Baseline, version 2.35) | about 25GB after 5 weeks and still growing (I killed it before it could use up all my RAM) |
| Jemalloc (5.2.1) | About 11.4GB after 1-2 weeks and not growing further at the 4 week mark |
| Mimalloc (2.0.5) | Currently being tested |
| Tcmalloc (2.9.1) | Going to be tested next |
| Idk any suggestions for other alternatives? |
Thought the results are interesting so sharing them here. Will come back and edit the post with results when I finish testing other implementations.