Short answer
Set -Xms and -Xmx to the same value, roughly 1000 to 1500 MB below your total RAM. On an 8 GB machine that is -Xms6G -Xmx6G. Check first that memory is the problem: /tps below 20 with plenty of free RAM means the bottleneck is tick work, not memory.
More memory is the most-requested server upgrade and the most frequently wasted one. A server at 20 ticks per second with 40 percent memory used is not slow because it needs more RAM, and giving it RAM changes nothing at all. A server that crashes with OutOfMemoryError needs it urgently.
This guide is in that order: establish that memory is the constraint, then size the heap properly, then find what is using it. The arithmetic is short, and it is the same on every platform that lets you set it.
Before you start
- Access to the server start command or the panel's memory setting
- The crash report or the /tps reading that made you look at memory
- Total RAM available to the server, not the total on your desktop
1. Decide whether memory is the constraint
Two observations settle it. Run /tps during a busy session: 20.0 means the tick loop is keeping up, whatever the memory graph shows. And read the memory graph itself: a server that runs out is one where usage climbs to the ceiling and stays there.
If TPS is fine and memory is not full, stop here. What you are feeling is lag, and it is fixed by reducing server lag, not by allocating more memory.
/tps
/mspt- TPS 20.0, memory 60% used: memory is not your problem.
- TPS 15, memory 95% used, climbs each day: memory is your problem, and something is leaking.
- Server crashed with
java.lang.OutOfMemoryError: memory, definitively.
2. Work out the heap your machine can give
Take the RAM available to the server process and subtract 1000 to 1500 MB for the JVM and the operating system. That remainder is your -Xmx. Paper documents this margin because a heap set to the full amount of RAM gets the process killed rather than allowed to fail gracefully.
Set -Xms equal to -Xmx. The JVM will otherwise start small and grow, and resizing costs pauses during a session.
4 GB total -> -Xms2G -Xmx2G
8 GB total -> -Xms6G -Xmx6G
12 GB total -> -Xms10G -Xmx10G
16 GB total -> -Xms13G -Xmx13G3. Set it where the server reads it
The heap is a startup argument, so it lives wherever your start command lives. A self-hosted server has it on the command line; a systemd unit has it in ExecStart; a hosting panel has a memory field that writes the same thing for you.
On a panel, use the memory control rather than editing anything by hand: the platform accounts for its own overhead, and a manual heap that exceeds it gets the process killed. On PufferHost the free tier is 3 GB and the platform sets the heap for it.
java -Xms6G -Xmx6G -XX:+UseG1GC -jar server.jar --noguiExecStart=/usr/bin/java -Xms6G -Xmx6G -XX:+UseG1GC -jar server.jar nogui4. If memory still runs out, find what is holding it
A correctly sized heap removes the crash caused by too little memory. It does not remove a leak: something that grows until it fills whatever ceiling you set. Turn on GC logging, restart, and let the server run through its usual week.
Then read it. A heap that returns to a low level after each collection is healthy. A heap that climbs towards -Xmx and stays there is a leak, and the class names in the log usually point at the plugin or the world responsible. The memory guide has the full procedure.
-Xlog:gc*:logs/gc.log:time,uptime:filecount=5,filesize=1M/spark heap5. Trim what you can before adding more
Memory tracks work. Chunks held in play, entities accumulating on a farm, and plugins holding caches all cost heap for as long as they exist. Lowering view and simulation distance, capping entity spawning and removing an unused plugin all reduce the ceiling you need.
That is why the sizing question comes before the shopping question: a server at 3 GB that holds a steady 2 GB is fine, and the same server at 6 GB that climbs to 5.9 GB every week has a problem more memory will only postpone.
view-distance=6
simulation-distance=6Good to know
- Memory pressure and tick load are different problems with different fixes. A server that stutters in pulses is usually garbage collection; a server that stutters constantly is usually tick work.
- Restarting with a bigger heap feels like a fix because the memory graph starts from zero. If the graph climbs back to the ceiling on the same schedule, the leak is unchanged.
- Two servers on one machine share nothing but the operating system, so divide the memory between them rather than giving each the full amount.
- Best JVM flags covers the flags that go alongside
-Xmx, and the memory guide covers leaks in full.
Common questions
How much RAM does a Minecraft server need?
A small vanilla world runs in about 2 GB. Paper with a modest plugin set wants 4 to 6 GB, and Paper recommends 6 to 10 GB whatever the player count. Whatever you choose, set the heap below the total RAM rather than equal to it.
Will more RAM fix lag?
No, if the server is keeping up at 20 TPS. More memory prevents out-of-memory crashes and smooths garbage collection. Tick lag comes from chunks, entities, redstone and plugins, and none of those are fixed by RAM.
Why did my server get killed when I used all my RAM?
Because the JVM and the operating system need memory too. When the heap takes everything, the kernel reclaims it and the process dies with no Java exception. Leave 1000 to 1500 MB of margin.
Should Xms and Xmx be the same?
Yes. Equal values mean the heap never resizes during a session, and resizing is one of the pauses people notice. Paper's own start script sets them equal for that reason.
How do I know if my server has a memory leak?
Turn on GC logging and let it run. A leak shows as collections happening constantly with the heap staying near -Xmx instead of dropping after each one. /spark heap after a restart shows what is on the heap, which usually names the plugin.
Sources
Official documentation this guide was checked against.
Rather not run this on your own machine? PufferHost gives every player a free Minecraft server with 3 GB of RAM and 10 slots. Create a free server.