Fix java.lang.OutOfMemoryError in Confluence

Still need help?

The Atlassian Community is here for you.

Ask the community

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:

  1. Heap Space
  2. PermGen Space
  3. Garbage Collection (GC) Overhead
tip/resting Created with Sketch.

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 heap
  • Xmx - the maximum size of the heap
  • XX: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 and Xmx 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 and Xmx 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
  • (warning) When setting the value in gigabytes, do not use .5 increments as this will cause the JVM to not start properly


tip/resting Created with Sketch.

See our Garbage Collection (GC) Tuning Guide for more detailed information.

Add memory to the JVM

Linux

Click here to expand...

Add memory in Linux by modifying setenv.sh

  1. Shutdown Confluence
  2. Edit <confluence-install>/bin/setenv.sh
  3. Find the line where the node's memory is set

    1. For Xms and Xmx, it should look similar to this 

      CATALINA_OPTS="[...] -Xms<memory size> -Xmx<memory size> [...] ${CATALINA_OPTS}"
    2. For PermGen, it should look similar to this 

      CATALINA_OPTS="[...] XX:MaxPermSize=<memory size> [...] ${CATALINA_OPTS}"
  4. Increase the values
    1. Xmx is the maximum amount
    2. Xms is the starting amount
  5. Restart Confluence

Windows (starting from a .bat file, not a service)

Click here to expand...

If you start Confluence as a Service on Windows, then you should not use these instructions. Instead, refer to the "Windows Service" section below.

Add memory in Windows by modifying setenv.bat

  1. Shutdown Confluence
  2. Edit <confluence-install>\bin\setenv.bat
  3. Find the line where the node's memory is set

    1. For Xms and Xmx, it should look similar to this 

      CATALINA_OPTS="[...] -Xms<memory size> -Xmx<memory size> [...] ${CATALINA_OPTS}"
    2. For PermGen, it should look similar to this 

      CATALINA_OPTS="[...] XX:MaxPermSize=<memory size> [...] ${CATALINA_OPTS}"
  4. Increase the values
    1. Xmx is the maximum amount
    2. Xms is the starting amount
  5. Start Confluence

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
Last modified on Nov 4, 2024

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.