1 year ago

#375275

test-img

RMSD

ZGC out of memory error when moving from G1GC

I have an application in Java 17 configured like so:

-Xms4096m -Xmx4096m -XX:+UseG1GC -XX:MaxMetaspaceSize=1024m

It's a rather large web service that is pretty memory intensive over the years that's grown from a baseline other services use:

-Xms1024m -Xmx1024m -XX:+UseG1GC -XX:MaxMetaspaceSize=128m

I've started to trial ZGC in our company on our web services to try and get a little bit more performance out of our services so I switched some of our baseline services which seemed to perform fine:

-Xms1024m -Xmx1024m -XX:+UseZGC -XX:MaxMetaspaceSize=128m

but when I went to try our single large service on ZGC I run into an error:

-Xms4096m -Xmx4096m -XX:+UseZGC -XX:MaxMetaspaceSize=1024m

Results in:

Apr 4, 2022 @ 15:06:22.103  Error: Could not create the Java Virtual Machine.
Apr 4, 2022 @ 15:06:22.026  [0.983s][error][gc] Failed to allocate initial Java heap (4096M)
Apr 4, 2022 @ 15:06:21.952  [0.966s][error][gc] Failed to commit memory (Not enough space)
Apr 4, 2022 @ 15:06:21.881  [0.983s][error][gc] Forced to lower max Java heap size from 4096M(100%) to 3366M(82%)
Apr 4, 2022 @ 15:06:21.826  [0.982s][error][gc] Failed to commit memory (Not enough space)
Apr 4, 2022 @ 15:06:21.826  Error: A fatal exception has occurred. Program will exit.
Apr 4, 2022 @ 15:06:21.783  [0.934s][error][gc] Failed to commit memory (Not enough space)
Apr 4, 2022 @ 15:06:21.226  [0.979s][error][gc] Failed to commit memory (Not enough space)
Apr 4, 2022 @ 15:06:20.224  [0.591s][error][gc] Failed to commit memory (Not enough space)

I noticed that there was a similar JDK issue logged on one of their tests here and although I'm not using the -XX:+UseLargePages I believe the implication is that I'm not leaving enough space in the heap to let ZGC start up compared to G1GC. I'd definitely like to use ZGC in the bigger service as I feel like there's the most gain there; but ZGC is new enough that I haven't found a lot of information on it during my search. What are the appropriate values/ratios in the flags for utilizing ZGC? Are there official recommendations on when to use ZGC over Shenandoah or G1GC?

java

garbage-collection

g1gc

java-17

zgc

0 Answers

Your Answer

Accepted video resources