Java application will not start due to "Failed to reserve shared memory" error on Linux

Solution Verified - Updated

Environment

  • Sun JDK
  • OpenJDK
  • Linux

Issue

  • I try the -XX:+UseLargePages parameter in JBoss run.conf but I get this error (sent to standard out) when trying to start JBoss:

          Java HotSpot(TM) 64-Bit Server VM warning: Failed to reserve shared memory (errno = 12)
    
  • A variation of this error:

          Java HotSpot(TM) 64-Bit Server VM warning: Failed to reserve shared memory (errno = 28)    
    
  • A fatal error log is not created, but what looks like the beginning of a the fatal error log is sent to standard out along with an error:

          #
          # An unexpected error has been detected by Java Runtime Environment:
          #
          #  SIGSEGV (0xb) at pc=0x00002af03f31aa27, pid=1856, tid=1350097216
          #
          # Java VM: Java HotSpot(TM) 64-Bit Server VM (10.0-b23 mixed mode linux-amd64)
          # Problematic frame:
          # V  [libjvm.so+0x5d8a27]
          #
          
          [error occurred during error reporting , id 0xb]
    

Resolution

  1. Fix large pages configuration or allocate more pages.
  2. If on RHEL 6 and using transparent huge pages, do one of the following:

Note: that configuring them explicitly and using the option may perform slightly better, since it guarantees the use of huge pages and you can more reliably predict the amount you would need with fixed heap/perm gen sizes, whereas with transparent huge pages some of the process may still get normal pages or the OS may not decide to use them.

Root Cause

  • Large pages are not set up correctly, or there are not enough pages.
  • Insufficient or fragmented address space and/or physical memory.
  • RHEL 6 transparent huge pages are expected to provide the large pages for the JVM here, but transparent huge pages do not work with the -XX:+UseLargePages option. What "transparent huge pages" does is cause the kernel to transparently switch part or all of a process to using huge pages without having to ask for it. -XX:+UseLargePages causes the JVM to specifically ask for huge pages, which will fail because there are no huge pages available since they have not been configured explicitly.

Diagnostic Steps

Components

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.