Top 3 G1GC Flags to Proactively Prevent Full GCs
Optimize G1GC for ML by tuning `-XX:InitiatingHeapOccupancyPercent` (IHOP) from its default 45% to trigger concurrent marking earlier, increasing `-XX:G1ReservePercent` (default 10%) to provide buffer space against evacuation failures, and setting a realistic `-XX:MaxGCPauseMillis` (default 200ms) to guide G1's adaptive behavior and avoid heap exhaustion.
The top 3
- IHOP's Critical Role: Triggering Early Concurrent Marking: The `-XX:InitiatingHeapOccupancyPercent` (IHOP) flag determines when G1GC starts its concurrent marking phase. By lowering its default of 45% (e.g., to 30-35%) for high allocation rate applications, G1 begins marking earlier, preventing the old generation from filling up prematurely and thus averting costly Full GCs due to marking not completing in time.
- Minimizing Heap Waste: Forcing More Mixed GCs: The `-XX:G1HeapWastePercent` flag controls the percentage of reclaimable memory G1 tolerates before stopping mixed garbage collections. Reducing its default value (typically 5%) compels G1 to perform more mixed GCs, even for regions with less reclaimable space, thereby aggressively reclaiming memory and preventing the heap from reaching a state that necessitates a Full GC.
- G1ReservePercent: Safeguarding Against Evacuation Failures: The `-XX:G1ReservePercent` flag allocates a percentage (default 10%) of the heap as reserve memory, specifically to prevent 'to-space overflows' during object evacuation. These overflows, which occur when G1 cannot find enough space to copy live objects, are a common trigger for Full GCs. Increasing this reserve provides a crucial buffer, especially for applications with high object promotion rates.
Sources
Open the full topic