Pivotal Knowledge Base

Follow

Java Application gets OutOfMemory Exit Code 137 due to MALLOC_ARENA_MAX

Environment

Pivotal Cloud Foundry, versions 2.0.7 and lower

Java Buildpack, versions 4.8 and lower

Symptom

Java application is getting error Exited with status 137 (out of memory). This behavior indicates application container memory has been exceeded (NOT the JVM hitting OOM)

The environment has large size Diego cells (for example, R4.large with 16 CPU cores).

Java application is under high load with JVM near heap memory limit for continuous periods of time.

Error Message:

2018-01-29T19:52:07.20-0500 [API/0] OUT App instance exited with guid 6ed5f4ac-3603-4fc7-a7ae-2b12b55183c7 payload: {"instance"=>"b66fa54b-ab36-4052-7762-0f05", "index"=>0, "reason"=>"CRASHED", "exit_description"=>"APP/PROC/WEB: Exited with status 137 (out of memory)", "crash_count"=>5, "crash_timestamp"=>1517273525487748928, "version"=>"8eecb7dd-d9e7-4c18-aadc-e12e2d20e493"}```

Cause 

There is a Java buildpack glibc environment variable called MALLOC_ARENA_MAX which sets the maximum number of arenas that can be allocated. This is set to unlimited by default in Java buildpack below version 4.9.

An arena is a scratchpad that glibc maintains to return smaller blocks to the requestor. In addition to the main arena, glibc malloc will allocate additional arenas during thread contention. The reason for the creation of arenas is to improve the performance of multithreaded processes.

Java applications running on large-sized Diego cells may encounter OutOfMemory as a result of new arenas being created. This happens when a heavy load (for instance when Java garbage collection occurs) and there is thread contention between the CPU cores resulting in many arenas which exceed the container memory limit. 

Resolution

MALLOC_ARENA_MAX needs to be set to 2 in order to prevent arena memory from exceeding container memory limit.

You can set MALLOC_ARENA_MAX on your application by the command:

cf set-env <app-name> MALLOC_ARENA_MAX 2

You can set a running-environment variable to apply this variable to all application in your org:

 cf set-running-environment-variable-group '{"MALLOC_ARENA_MAX":"2"}'

This issue will be fixed in java buildpack 4.9 and higher versions. 

Additional Information 

For further information on MALLOC_ARENA_MAX, see articles: https://github.com/cloudfoundry/java-buildpack/issues/320 - https://access.redhat.com/solutions/457543 

This issue is documented in Java buildpack release notes: https://github.com/cloudfoundry/java-buildpack/releases/tag/v4.9

Comments

Powered by Zendesk