Search code examples
javadockercontainersamazon-ecs

JVM -XX:MaxRAMPercentage not being applied in container


I am trying to run a Java app which requires a large heap. It is running on AWS ECS inside a container. On a host with 128GB RAM. The container has ~115GB assigned.

The Dockerfile is based on eclipse-temurin:11

I am launching with the option -XX:MaxRAMPercentage=85.0 and also -XX:+PrintFlagsFinal to get feedback. This is what I get abridged (too large for SO) Full flags here https://pastebin.com/jm7Md2c8

2023-01-17 11:02:40      bool MaxFDLimit                               = true                                      {product} {default}
2023-01-17 11:02:40     uintx MaxGCMinorPauseMillis                    = 18446744073709551615                      {product} {default}
2023-01-17 11:02:40     uintx MaxGCPauseMillis                         = 200                                       {product} {default}
2023-01-17 11:02:40     uintx MaxHeapFreeRatio                         = 70                                     {manageable} {default}
2023-01-17 11:02:40    size_t MaxHeapSize                              = 32178700288                               {product} {ergonomic}
2023-01-17 11:02:40      intx MaxInlineLevel                           = 15                                        {product} {default}
2023-01-17 11:02:40      intx MaxInlineSize                            = 35                                        {product} {default}
2023-01-17 11:02:40    size_t MaxMetaspaceExpansion                    = 5451776                                   {product} {default}
2023-01-17 11:02:40     uintx MaxMetaspaceFreeRatio                    = 70                                        {product} {default}
2023-01-17 11:02:40    size_t MaxMetaspaceSize                         = 18446744073709547520                      {product} {default}
2023-01-17 11:02:40    size_t MaxNewSize                               = 19306381312                               {product} {ergonomic}
2023-01-17 11:02:40      intx MaxNodeLimit                             = 80000                                  {C2 product} {default}
2023-01-17 11:02:40  uint64_t MaxRAM                                   = 137438953472                           {pd product} {default}
2023-01-17 11:02:40     uintx MaxRAMFraction                           = 4                                         {product} {default}
2023-01-17 11:02:40    double MaxRAMPercentage                         = 85.000000                                 {product} {command line}
2023-01-17 11:02:40      intx MaxRecursiveInlineLevel                  = 1                                         {product} {default}
2023-01-17 11:02:40     uintx MaxTenuringThreshold                     = 15                                        {product} {default}
2023-01-17 11:02:40      intx MaxTrivialSize                           = 6                                         {product} {default}
2023-01-17 11:02:40      intx MaxVectorSize                            = 32                                     {C2 product} {default}
2023-01-17 11:02:40    size_t MetaspaceSize                            = 21807104                               {pd product} {default}
2023-01-17 11:02:40      bool MethodFlushing                           = true                                      {product} {default}
2023-01-17 11:02:40    size_t MinHeapDeltaBytes                        = 4194304                                   {product} {ergonomic}
2023-01-17 11:02:40     uintx MinHeapFreeRatio                         = 40                                     {manageable} {default}
2023-01-17 11:02:40      intx MinInliningThreshold                     = 250                                       {product} {default}
2023-01-17 11:02:40      intx MinJumpTableSize                         = 10                                  {C2 pd product} {default}
2023-01-17 11:02:40    size_t MinMetaspaceExpansion                    = 339968                                    {product} {default}
2023-01-17 11:02:40     uintx MinMetaspaceFreeRatio                    = 40                                        {product} {default}
2023-01-17 11:02:40     uintx MinRAMFraction                           = 2                                         {product} {default}
2023-01-17 11:02:40    double MinRAMPercentage                         = 50.000000                                 {product} {default}
2023-01-17 11:02:40     uintx MinSurvivorRatio                         = 3                                         {product} {default}
2023-01-17 11:02:40      bool UseContainerSupport                      = true                                      {product} {default}

So it seems reasonable, the JVM detected the host ram MaxRAM = 137438953472 = 128GB the option MaxRAMPercentage = 85.000000 was correctly set. UseContainerSupport = true so my understanding is these options should be applied.

So I dont understand why MaxHeapSize = 32178700288 which is only ~29.9GB? I think its 1/4 of the 115GB assigned to the container which seems to imply my settings are not being applied, why?.

Testing locally with

docker run --memory='2g' eclipse-temurin:11 java -XX:MaxRAMPercentage=85.0 -XX:+PrintFlagsFinal -version | grep MaxHeapSize

Appears to work as expected when varying the container memory assigned and the MaxRAMPercentage


Solution

  • Thanks to Andrey. The solution was to add -XX:-UseCompressedOops