> ## Documentation Index
> Fetch the complete documentation index at: https://docs.berrybyte.net/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Optimize Minecraft Server Performance with Aikar's Flags

> Guide to implementing Aikar's flags for Minecraft server optimization.

# How to Optimize Minecraft Server Performance with Aikar's Flags

Aikar's Flags are JVM startup parameters that improve server performance by optimizing garbage collection and memory management. They reduce lag spikes and provide smoother gameplay.

**All berrybyte Minecraft servers come with Aikar's flags by default.**

<Note>Aikar's Flags allocates all available memory, so your server may appear to use 100% RAM. This is normal. Install the [Spark plugin](https://spark.lucko.me/download) and run `/spark health` to see actual usage.</Note>

## Setting Up the Flags

Update your server startup command with the flags below. Replace `{SERVER_MEMORY}` with your RAM amount (e.g., `4096` for 4GB).

### Less than 12GB of RAM

```bash JVM Flags theme={null}
java -Xms{SERVER_MEMORY}M -Xmx{SERVER_MEMORY}M -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 paper.jar --nogui
```

### 12GB of RAM or more

```bash JVM Flags theme={null}
java -Xms{SERVER_MEMORY}M -Xmx{SERVER_MEMORY}M -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 -Dusing.aikars.flags=https://mcflags.emc.gs -Daikars.new.flags=true -jar paper.jar --nogui
```

## Flag Breakdown

<Note>On shared hosting (like berrybyte), leave about 1GB for JVM overhead. This is done automatically.</Note>

Key flags:

* `-Xmx` / `-Xms`: Maximum and initial memory (set to same value)
* `-XX:+UseG1GC`: Enables G1 garbage collector for better performance
* `-XX:+ParallelRefProcEnabled`: Parallel reference processing
* `-XX:MaxGCPauseMillis`: Maximum garbage collection pause time
* `-XX:+DisableExplicitGC`: Prevents bad plugin code from affecting GC

<Warning>Remove `-XX:+AlwaysPreTouch` on Pterodactyl/containerized servers. It can cause crashes by pre-allocating all memory.</Warning>

Other flags fine-tune G1 garbage collection settings. See [Aikar's blog](https://mcflags.emc.gs) for detailed explanations.

If you have issues, check `server.log` for error messages.

## Common Issues

**Server shows 100% RAM usage**

* Normal behavior - flags allocate all available memory
* Fix: Use Spark plugin and run `/spark health` for actual usage

**Server crashes with "Cannot allocate memory"**

* Usually caused by `-XX:+AlwaysPreTouch` in containers
* Fix: Remove `-XX:+AlwaysPreTouch` flag

**Poor performance**

* Incorrect memory allocation or wrong Java version
* Fix: Use Java 11+ and leave 1GB for JVM overhead

## Related Guides

* [Changing Minecraft Versions](/games/minecraft/changing-versions) - Switch versions
* [Connection Timeout Fix](/games/minecraft/common-errors/connection-timed-out) - Fix connection issues
* [Chunky Plugin](/games/minecraft/plugins/chunky) - Pre-generate chunks
* [Control Panel Overview](/panel/overview) - Monitor performance

Need help? Ask in our [Discord](https://berrybyte.net/discord). Consider [donating to Aikar](https://donate.emc.gs/MC%20Flags) if these flags helped your server.
