Fix java.lang.OutOfMemoryError in Confluence
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
When Confluence stops working and java.lang.OutOfMemoryError
is appearing in the logs, adding the right amount of memory will get things running again.
Error type and memory size
Java applications like Jira, Crowd, and Confluence run in a "Java virtual machine" (JVM). When started, the JVM is allocated a certain amount of memory, which it makes available to applications like Confluence. By default, JVMs are allocated 64Mb of memory, no matter how many gigabytes of memory your server may actually have available. 64Mb is inadequate for most Confluence installations, so this needs to be increased.
Determine the type of error message
Look in the atlassian-confluence.log
to see which type of out-of-memory (OOM) error you're receiving. There are three common messages:
- Heap Space
- PermGen Space
- Garbage Collection (GC) Overhead
This document discusses increasing memory to address PermGen and Heap space errors. Follow the links above to assess the root cause for each issue.
For GC Overhead, refer to Confluence Crashes Due to 'OutOfMemoryError GC overhead limit exceeded'. Just adding more memory might not solve GC Overhead errors.
Determine available system memory
On Windows
From the Task Manager Dialog (Press ctrl-alt-delete), select the Performance tab.
The amount marked Available is the amount in kilobytes you have free to allocate to Confluence.
On Linux
Run this from the shell prompt to view memory usage.
cat /proc/meminfo
Be sure to leave some free memory unallocated for the operating system to use. If you allocate all available memory on a node, you run the risk of OOM errors, or the entire Confluence JVM could even be killed by the OS to free up memory. Even if that doesn't happen, the node will start swapping memory out to disk. This will severely impact performance.
Guidance
The default values supplied with Confluence are sufficient for small installations. Please refer to Managing Application Server Memory Settings and Server Hardware Requirements Guide for more details.
We aren't able to give a concrete recommendation for the amount of memory to allocate because that will depend greatly on your server setup, the size of your user base, and their behavior. You will need to find a value that works for you (no noticeable GC pauses and no OOM errors).
For reference, the 3 most common parameters used to change the memory (heap) allocation are:
Xms
- the minimum size of the heapXmx
- the maximum size of the heapXX:MaxPermSize
- the maximum size of PermGen (this is not used in Java 8 and above)Need advice regarding how much memory you should use? Here are some examples of hardware specifications.
If you decide to increase the memory settings, there are a few general guidelines to follow:
Increase Xmx in small increments (1-2GB at a time), until you no longer experience the OOM error
Increasing the heap beyond the capabilities of your server to adequately Garbage Collect can cause performance problems or freezing.
If your error is java.lang.OutOfMemoryError: PermGen space
Increase the XX:MaxPermSize
parameter in 256MB increments until the error stops occurring.
If your error does not reference PermGen, there is no need to increase it
PermGen is used to store classes, and is generally quite static in size. It's been removed as of Java 8.
Setting Xms and Xmx
- Consider setting
Xms
andXmx
to the same value; this can decrease the time GC takes to occur since it will not attempt to reduce the heap on each collection - It is possible to set the
Xms
andXmx
values as either gigabytes or megabytes - When setting these values in megabytes, set the value by multiplying the desired memory level by 1024. For example, to set the memory at 2 gigabytes, configure the Xms and Xmx to 2048m (2GB x 1024MB):
-Xms2048m -Xmx2048m
- For the same example using gigabytes, simply use the following:
-Xms2g -Xmx2g
When setting the value in gigabytes, do not use .5 increments as this will cause the JVM to not start properly
See our Garbage Collection (GC) Tuning Guide for more detailed information.
Add memory to the JVM
Linux
Windows (starting from a .bat file, not a service)
Windows Service
Follow the instructions in How to set system properties for Confluence running as a service on Windows
Verify your settings
To verify what settings are in place after restarting, check atlassian-confluence.log
for the last startup and search for "-Xms" or "-Xmx".
Alternatively, on Linux, run this to see the environment parameters.
ps -aux | grep java