1

I understand the aim of SoftMaxHeapSize, but I can't find what it really does. Hopefully someone familiar with JDK internals can shed some light.

Specifically, when the soft limit is reached:

  • Does it simply change ZCollectionInterval and ZUncommitDelay? To what values?
  • Or does it do something else?
  • How much additional CPU overhead can I expect?

Finally, will an application work fine if I do something like -XX:SoftMaxHeapSize=1M -Xmx=1T?

Aleksandr Dubinsky
  • 22,436
  • 15
  • 82
  • 99
  • https://github.com/openjdk/zgc/blob/master/src/hotspot/share/gc/z/zDirector.cpp (soft_max_...)<- seems to be used for decisions about "are we running out of memory?". So if you set it too low, every time the question "should we GC?" comes up, the answer will be yes. –  Aug 31 '21 at 12:18
  • Maybe try enabling GC debugs and running something with the `-XX:SoftMaxHeapSize=1M -Xmx=1T` setting... –  Aug 31 '21 at 12:19
  • @dratenik Thanks for pointing to the source code. That makes the GC-trigger logic very clear. Looks like all the levers amount to a binary decision: to GC or not to GC. And as of JDK 16, it looks like using more heap than SoftMaxHeap puts the app in a GC loop that eats up an entire CPU core (but keeps mem usage very minimal and the app stays responsive :). – Aleksandr Dubinsky Aug 31 '21 at 18:38

1 Answers1

1

As of JDK 16, using more live heap than SoftMaxHeapSize puts the app in a perpetual GC loop. I wouldn't call this optimal, but because ZGC is concurrent it doesn't have a catastrophic effect on the application. In my test it ate 1 additional CPU core (but I assume this would depend on the number of GC threads).

Additionally, seems that all GC heuristics (which tune things like how often GC should run) first look at SoftMaxHeapSize.

Aleksandr Dubinsky
  • 22,436
  • 15
  • 82
  • 99