1

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?

RMSD
  • 476
  • 5
  • 12
  • 2
    It looks like the machine you're running this on doesn't have enough RAM to allocate what you've asked for. You'll have to either get more RAM, or choose values that line up better with the amount of RAM you have available. – Dawood ibn Kareem Apr 04 '22 at 23:25
  • 4
    By year 2022’s standards, a max heap of 4GB is not “pretty memory intensive” and not necessarily a reason to switch from G1GC to ZGC. I wouldn’t use a GC without string deduplication anyway, which ZGC learned only in JDK 18, which happens to be the version where the bug you’ve linked has been fixed too. – Holger Apr 05 '22 at 08:17
  • These are both good tips, there any good documentation points for these recommend practices I can spread around my company? – RMSD Apr 05 '22 at 18:54
  • @DawoodibnKareem I guessed that too, but I'm not sure what I'd reduce the -Xms/Xmx values to give ZGC enough overhead to even start the GC. – RMSD Apr 05 '22 at 18:59
  • 1
    I'd say you want to reduce both `-Xmx` and `-Xms`. But getting some more RAM is better, unless you've got a really good reason not to. RAM is cheap. – Dawood ibn Kareem Apr 05 '22 at 19:07
  • I'll ask around my infra team. Thanks for the tips! – RMSD Apr 05 '22 at 19:20
  • Please confirm if some of the tips worked for you. Note that Bug JDK-8276796 is indicating this issue was fixed in JDK 18. Did you have a chance to test it in that version? – Mario.Cadiz Sep 08 '22 at 18:18
  • @Mario.Cadiz Unfortunately my company's stuck at 17 for the moment because we're on an LTS release train, so I can't confirm any fixes to 18, but I was able to get ZGC to run after allocating a lot more ram. After reading docs I believe there was a minimum set -Xmx overhead of like a few gigs. Since I don't have string dedup, and have no gain for services so small, I reverted my work for now haven't really tested passed some theory gained from here: https://wiki.openjdk.org/display/zgc/Main – RMSD Sep 29 '22 at 00:12

0 Answers0