ZGC divides memory into regions, also called ZPages. ZPages can be dynamically created and destroyed. These can also be dynamically sized (unlike the G1 GC), which are multiples of 2 MB. Here are the size groups of heap regions:
- Small (2 MB)
- Medium (32 MB)
- Large (N * 2 MB)
ZGC heap can have multiple occurrences of these heap regions. The medium and large regions are allocated contiguously, as shown in the following diagram:
Unlike other GCs, the physical heap regions of ZGC can map into a bigger heap address space (which can include virtual memory). This can be crucial to combat memory fragmentation issues. Imagine that you can allocate a really big object in memory, but you can't do so due to unavailability of contiguous space in memory.
This often leads to multiple GC cycles to free up enough contiguous space. If none are available, even after (multiple) GC...