1. 程式人生 > >G1 gabage collector notes

G1 gabage collector notes

java gabage collection

Traditional: Eden Survivor 0 Survior 1 Old generation
G1: Various size regions (Free/Occupied)
Each region: young(Eden or survivor)/old/humongous

Humongous object:
Object < 50% region size (normal allocation into eden)
Object >= 50% region size (humongous object, allocation into old generation directly)

Object > region size (allocation into contiguous regions into old generation, humongous region)

Collection set (candidate regions for GC)
Young collection set -> all young regions
Mix collection set -> all youn regions + a few candidate old regions based on "most garbage first" principle
Incremental compaction in G1 VS monolithic stop world for normal full GC

Remembered set:
tracking incoming reference
5% memory footprint overhead
tracking old-to-young references + old-to-old references
more popular objects in remember set, it gets denser -> performance issue
Each old region has associated remember set, no need for young regions

Phases:
Young collection (stop the world)
Initial mark (stop the world) triggered when initiating heap occupancy percent is reached
-XX:InitiatingHeapOccupancyPercent (default 45%)
-XX:ConcGCThreads=<n>

Root object scanning

Concurrent marking can be interrupted by young collection

Remark (stop the world)
Cleanup (stop the world)
Mixed collection

1.8.40 ClassUnloadingWithConcurrentMark enabled by default
before 1.8.40 humongous objects are only collected during cleanup phase,
after 1.8.40 humongous objects can be collected in young collection

Tuning options:
Mixed GC happens too frequently
Mixed GC pause too long -> divide expensive collection further into smaller inexpensive collections


Strategy:
min number of old regions to include in the mixed collection set (-XX:G1MixedGcCountTarget=<n>)
max number of old regions to include in the mixed collection set (-XX:G1OldCSetRegionThresholdPercent=<p>)

Remove the expensive regions from mixed collection set
eliminate based on the liveness per old region -XX:G1MixedGCLiveThresholdPercent = <p> (default 85%)
eliminate expensive old regions towards the end of sorted array -XX:G1HeapWastePercent = <p> (default 5%)

Major contributor to GC pause:
ideally: copying live objects

others:

update remember set (problemetic)
other time (reference processing etc)

lots of long-lived humongous objects can cause evacuation failure
each humongous region can have 1 humongous object (wasted space)
promotion/evacuation failure can cause by fragmentation -> full GC


Prevent evacuation failure:

  • increase heap size

  • lower InitiatingHeapOccupancyPercent

  • increase marking threads

  • increase G1ReservePercent (make sure enough to space)


Always watch allocation rate/promotion rate and be aware of allocation spikes


https://www.youtube.com/watch?v=Io8hEdm6haw&list=PLy7t4z5SYNaRN2IDmjq_SSCrb9Sph4zAC&index=29



G1 gabage collector notes