My server has stopped after reaching max memory

I have a Minecraft server (1.16.4) and having trouble with RAM usage causing my server to suddenly stop working. I have 8GB RAM and my server runs on Linux and when I start the server, my ram is 3GB, but when someone joins (around 3-5 players) the RAM usage increases until it reaches 8GB ram, and after it reaches 8GB my server suddenly stopped working and I can't stop or restart the server because my console also freezes.

Before it reach 8GB ram, the server was at 20 TPS but after ram reach 8GB, my server suddenly dropped its TPS, but I don't know it because of my plugins or memory leaking.

  • with 3 to 5 player my ram is (3GB/8GB)
  • after playing for 1 hour my ram hit 8GB ram (7.89GB/8GB)

my server Startup Settings:

java -Xms8000M -Xmx8000M -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 -Dusing.aikars.flags=https://mcflags.emc.gs/ -Daikars.new.flags=true -jar server.jar nogui

this server is running on Pterodactyl Panel.

Plugins (62):

AdvancedEnchantments, AdvancedRegionMarket, AltDetector, AnimatedScoreboard, AutomaticBroadcast, AutoPluginLoader, BungeeTabListPlus, Citizens, ClearLag, ClearLagTimer*, ColoredSigns*, CommandPanels, CoreProtect, DeluxeMentions, DiscordSRV, Essentials, EssentialsAntiBuild, EssentialsChat, EssentialsGeoIP, EssentialsProtect, EssentialsSpawn, FastChunkPregenerator, FogusCore, GoldenCrates, GoldenEnchants, GSit, Harbor, HolographicDisplays, ImageMaps, Jobs, LuckPerms, LWC, mcMMO, Minepacks, MMOItems, MMOLib, Multiverse-Core, NexEngine, OpenInv, PlaceholderAPI, PlayTime*, Playtimes*, ProtocolLib, QuantumShop, Quests, RandomTeleport, SilkSpawners, Towny, TownyChat, TownyNameUpdater, UltimateAutoRestart, UnlimitedEnchants, Vault, ViaBackwards, ViaRewind, ViaVersion, Votifier, VotingPlugin, WorldEdit, WorldGuard, WorldGuard-Towny*, WorldGuardExtraFlags

What's causing my server to do this?


Solution 1:

First, some questions:

  1. Do you have a 'swapfile' configured?

If you don't, your OS might become unresponsive. In Linux, especially the less 'userfriendly' distros, you may have to configure this manually. It's recommended to have swap equal to twice your memory (in your case, 16GB). Your OS will decide which chunks of memory are 'stale' and can be swapped out to disk on the fly.

The swap file serves as a slower cache for memory that's accessed less often. For well-behaved programs, it can work quite well, especially if you have a faster disk (like, say, an SSD), although SSD's can wear out if they have to swap constantly (that is, if you're running heavy memory things 24/7).

  1. As in the comments, have you tried limiting minecraft to less memory, so you have some spare for your kernel, systemd, console, etc? (Say, 7G)

Most games are not well-behaved in this sense though. Because of their real-time requirements, and because interfacing with kernels is harder than DIY, developers often create their own internal rudimentary memory managers and request very large contiguous sections of memory from the OS.

Which means the OS is blind and doesn't know what to swap, so it either swaps everything or gives up.

If you still keep running into issues with running out of memory, try to check whether your server actually respects the command line you give it. If it won't, you might want to tell your OS to limit minecraft's memory usage.