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

# Optimizing Minecraft Servers with Aikar's Flags

> A guide to using Aikar's flags to optimize the performance of your Minecraft server.

Aikar's Flags are startup flags (CLI options) designed to improve performance and optimize Minecraft servers.

Technical explanation: Command-line options for the [JVM](https://en.wikipedia.org/wiki/Java_virtual_machine) implementations like
OpenJDK and OpenJ9. These flags are designed to improve performance of the JVM's G1GC garbage
collector, this enhancing the performance for Minecraft servers.

Note: Aikar's Flags allocates all available memory to the server (unused memory is wasted memory) which may make the server appear to be using 100% RAM at all times. This is usually not the case.

To view actual usage for servers running Aikar's Flags, install the [Spark plugin](https://spark.lucko.me/download) and run the command `/spark health` for accurate memory usage.

## Setting up the flags

Setting up Aikar's Flags for your server is a very simple process, simply update
the parameters of the command that you use to start up your server with the
flags listed below.

<Info>
  Remember to replace `{SERVER_MEMORY}` with the amount of RAM you want to
  allocate to your server.
</Info>

### Less than 12GB of RAM

```bash JVM Flags
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
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
```

## Breakdown

* `-Xmx`: Sets the maximum amount of memory that the JVM can use. This can help
  prevent the server from crashing due to out-of-memory errors.
* `-Xms`: Sets the initial amount of memory that the JVM uses when starting up.
  Aikar's flags set this to the same value as `-Xmx`, because unused memory is
  wasted memory.
* `-XX:+UseG1GC`: Enables the Garbage-First (G1) Garbage Collector, which is a
  low-latency garbage collector that adaptively chooses how much memory to give
  to each region to optimize pause time
* `-XX:+ParallelRefProcEnabled`: Enables parallel reference processing and lets GC use multiple threads for weak reference checking.
* `-XX:MaxGCPauseMillis`: Sets the maximum amount of time that the JVM can spend
  on garbage collection.
* `-XX:+UnlockExperimentalVMOptions`: Unlocks experimental JVM options which are needed for Aikar's flags.
* `-XX:+DisableExplicitGC`: Disables explicit garbage collection, which prevents bad plugin code from affecting your server.
* `-XX:+AlwaysPreTouch`: Enables pre-touching, which will preallocate all the memory at process start.

<Warning>This flag is removed automatically on Fractal servers, and if you are running the [Pterodactyl](https://pterodactyl.io) or [Heliactyl](https://sryden.com/heliactyl) panels, you should remove this flag too. This flag pre-allocates all memory to the process on startup, starving and freezing/crashing the docker container. If not, you can ignore this warning.</Warning>

* `-XX:G1NewSizePercent`: Sets the percentage of the heap that is used for new
  objects.
* `-XX:G1MaxNewSizePercent`: Sets the maximum percentage of the heap that is
  used for new objects.
* `-XX:G1HeapRegionSize`: Sets the size of the G1 heap region.
* `-XX:G1ReservePercent`: Sets the percentage of the heap that is reserved for
  G1.
* `-XX:G1HeapWastePercent`: Sets the percentage of the heap that is wasted.
* `-XX:G1MixedGCCountTarget`: Sets the target number of mixed garbage
  collections.
* `-XX:InitiatingHeapOccupancyPercent`: Sets the percentage of the heap that is
  used before a mixed garbage collection is triggered.
* `-XX:G1MixedGCLiveThresholdPercent`: Sets the percentage of live objects that
  are required for a mixed garbage collection to be triggered.
* `-XX:G1RSetUpdatingPauseTimePercent`: Sets the percentage of time that is
  spent on updating the remembered set.
* `-XX:SurvivorRatio`: Sets the ratio of the survivor space to the eden space.
* `-XX:+PerfDisableSharedMem`: Disables shared memory.
* `-XX:MaxTenuringThreshold`: Sets the maximum tenuring threshold.

<Info>
  This is only a quick recap, you should give [Aikar's
  blog](https://mcflags.emc.gs) a read if you're interested on how these really
  work.
</Info>

It is important to carefully consider the values you use for each startup flag,
as setting them too high or too low can have negative impacts on the performance
of the server. If you are having trouble using Aikar's flags, check the
`server.log` file in the logs folder of your server for any error messages.

If these flags have helped your server significantly, consider donating to
[Aikar](https://donate.emc.gs/MC%20Flags) to support his work.
