cloudfoundry / java-buildpack-memory-calculator

Cloud Foundry JVM Memory Calculator
Apache License 2.0
645 stars 70 forks source link

Calculation Default Values: ReservedCodeCache is NOT 240MB? #32

Closed tuxedo0801 closed 4 years ago

tuxedo0801 commented 4 years ago

Hi there,

I'm using the openjdk buildpack with my CF application. I set the CF container to 512MB an wondered why my JVM max heap is set to ~100MB any immediately runs out of memory...

I now checked the memory calculation and saw, that ReservedCodeCache is assumed with JVM default of 240MB (as described here: https://github.com/cloudfoundry/java-buildpack-memory-calculator/blob/master/README.md).

But: https://docs.oracle.com/javase/8/embedded/develop-apps-platforms/codecache.htm The default is either 32MB or 48MB, but not 240MB.

So, where do the 240MB come from and why is this very high value assumed as default?

nebhale commented 4 years ago

That document is not accurate in all situations. A quick test is to start up any Java application with the -XX:NativeMemoryTracking=detail flag.

$: java -cp . -XX:NativeMemoryTracking=detail MemoryTest

Then using the jcmd application, baseline and diff the current usage:

$: jcmd 97793 VM.native_memory baseline
97793:
Baseline succeeded

$: jcmd 97793 VM.native_memory detail.diff
97793:

Native Memory Tracking:

Total: reserved=5705578KB +14KB, committed=461654KB +14KB

-                 Java Heap (reserved=4194304KB, committed=262144KB)
                            (mmap: reserved=4194304KB, committed=262144KB)

-                     Class (reserved=1066112KB, committed=14208KB)
                            (classes #433)
                            (malloc=9344KB #160)
                            (mmap: reserved=1056768KB, committed=4864KB)

-                    Thread (reserved=20563KB, committed=20563KB)
                            (thread #21)
                            (stack: reserved=20480KB, committed=20480KB)
                            (malloc=60KB #110)
                            (arena=23KB #36)

-                      Code (reserved=249633KB, committed=2569KB)
                            (malloc=33KB #319)
                            (mmap: reserved=249600KB, committed=2536KB)

-                        GC (reserved=163627KB, committed=150831KB)
                            (malloc=10383KB #129)
                            (mmap: reserved=153244KB, committed=140448KB)
 ...

You can see by the output from my system, that regardless of what that document says, the default reserved amount for code cache is Code 249633KB or ~240M. I've verified that this is true in our linux containers as well.

nebhale commented 4 years ago

Since there's been no response on this issue in a couple of weeks, I'm going to close it. If you'd like to see it re-opened, please comment on the issue and I'll reopen it.