0

This continues kind of this question

I am making the same steps as there, but this time, I am dropping UseCGroupMemoryLimitForHeap:

java -XX:InitialRAMPercentage=50.0 -XX:MaxRAMPercentage=50.0 -XX:+AlwaysPreTouch Dummy &

And I am trying to inspect it a little:

jcmd 279 VM.flags

Among other things, I see :

-XX:InitialHeapSize=2063597568
-XX:InitialRAMPercentage=50.000000
-XX:MaxRAMPercentage=50.000000
-XX:MaxHeapSize=2063597568

From a recommendation from this answer from Pangin, he says that:

-XX:InitialRAMPercentage is used to calculate initial heap size when InitialHeapSize / -Xms is not set.

and :

... both -XX:MaxRAMPercentage and -XX:MinRAMPercentage are used to calculate maximum heap size when MaxHeapSize / -Xmx is not set

My understanding that I should not set InitialHeapSize/Xms and MaxHeapSize/Xmx and I don't, but they are set for me.

I thought that I could say -XX:InitialHeapSize=0 and -XX:MaxHeapSize=0, but of course this does not work and the VM does not start.

The last point is that :

top -o %MEM

shows a 2GB of resident memory for the java process, so yeah, both InitialRAMPercentage/MaxRAMPercentage seems to be pointless?


The interesting thing here is that if I run this in jdk-17:

 java -XX:InitialRAMPercentage=50.0 -XX:MaxRAMPercentage=50.0 -XX:+AlwaysPreTouch Dummy &

then top -o %MEM shows 1GB, exactly like I want it to be.

Eugene
  • 117,005
  • 15
  • 201
  • 306
  • the linked question has the solution, may be someone can come up with a better one. – Eugene Feb 16 '22 at 17:56
  • `MaxRAMPercentage` works as expected for me. Show the output of `-XX:+PrintFlagsFinal`. – apangin Feb 16 '22 at 21:38
  • @apangin that output is huge... [here is a link to it](https://gist.github.com/wind57/cfad67437824ddad8c41606ec5b4d766) – Eugene Feb 17 '22 at 06:47
  • I mean, `PrintFlagsFinal` together with the options you test: -XX:InitialRAMPercentage=50.0 -XX:MaxRAMPercentage=50.0 – apangin Feb 17 '22 at 10:35
  • @apangin [like this?](https://gist.github.com/wind57/cfad67437824ddad8c41606ec5b4d766) – Eugene Feb 17 '22 at 11:09
  • So JVM apparently detected available RAM as 4GB. What does `-XX:+UnlockDiagnosticVMOptions -XX:+PrintContainerInfo` say? – apangin Feb 17 '22 at 21:27
  • @apangin `OSContainer::init: Initializing Container Support Required cgroup memory subsystem not found`. this container is running on cgroup v2, on my machine there are 16GB of RAM, since cgroup does not work (because we are on java-8), it takes 4GB, which makes sense now, right? – Eugene Feb 18 '22 at 06:54

0 Answers0