Upgrade to Pro — share decks privately, control downloads, hide ads and more …

introduction-to-modern-gc

 introduction-to-modern-gc

Shenandoah GC・ZGC・Epsilon GCをざっくり理解したい!

JJUG CCC 2018 Spring での発表資料です

tomoya yokota

May 26, 2018
Tweet

More Decks by tomoya yokota

Other Decks in Technology

Transcript

  1. ͬ͘͟Γ

    Θ͔ͬͨؾʹͳΔ
    ϞμϯGC ೖ໳
    JJUG CCC 2018 Spring @yokotaso

    View full-size slide

  2. Agenda
    • ͜Ε·ͰͷGCͱͳͥ৽GC͕ඞཁͳͷ͔
    • Shenandoah GC
    • ZGC
    • Epsilon GC

    View full-size slide

  3. ͜Ε·ͰͷGC

    View full-size slide

  4. GCͱΞϓϦఀࢭ(STW)
    Compaction GC
    Parallel GC
    young gc old gc
    GC = ΞϓϦέʔγϣϯεϨουఀࢭ
    ϝϞϦ͕ϑϥάϝϯτ͠ͳ͍
    CPUෛՙ͸খ͍͞
    Stop The world = ΞϓϦέʔγϣϯεϨουͷఀࢭ
    Mark Compaction GC
    Noop

    View full-size slide

  5. GCͱΞϓϦఀࢭ(STW)
    CMS GC Compaction GC
    young gc
    marking sweep GC
    old gc
    initial-mark final-remark
    young gc͸ΞϓϦέʔγϣϯεϨουఀࢭ
    major gc͸΄΅ฒྻ
    ϝϞϦͷϑϥάϝϯτ͕ܽ఺
    Stop The world = ΞϓϦέʔγϣϯεϨουͷఀࢭ
    Concurrent = ΞϓϦέʔγϣϯεϨουͱฒྻ

    View full-size slide

  6. GCͱΞϓϦఀࢭ(STW)
    G1GC Compaction GC
    young gc
    Marking
    old gc
    initial-mark final-remark
    young gc͸ΞϓϦέʔγϣϯεϨουఀࢭ
    major gc͸໨ඪఀࢭ࣌ؒΛݩʹGCΛߦ͏
    ϝϞϦ͕ϑϥάϝϯτ͠ͳ͍
    Stop The world = ΞϓϦέʔγϣϯεϨουͷఀࢭ
    Compaction GC
    Concurrent = ΞϓϦέʔγϣϯεϨουͱฒྻ

    View full-size slide

  7. GCͱΞϓϦఀࢭ(STW)
    Parallel GC
    CMS GC
    G1GC
    young gc
    Concurrent mark Concurrent sweep
    Mark
    Concurrent mark
    old gc
    Compaction GC
    Compaction GC
    Compaction GC Compaction GC
    Compaction GC
    Noop

    View full-size slide

  8. GCͱΞϓϦͷఀࢭ(STW)
    • ίϯύΫγϣϯGCͰఀࢭ

    ੈ୅ܕGC͸Young GCͰఀࢭ

    ੜଘͷΦϒδΣΫτͷ଴ආͰఀࢭ
    • ίϯύΫγϣϯ͠ͳ͍ͱϝϞϦ͕

    ϑϥάϝϯτͯ͠͠·͏

    View full-size slide

  9. ͳͥ৽GCͳͷ͔

    View full-size slide

  10. ৽͍͠GCͷඞཁੑ
    • ڊେώʔϓΛ࢖͏ΞϓϦέʔγϣϯͷ୆಄

    ElasticsearchͳͲ
    • ίϯύΫγϣϯܕGCͷఀࢭΛ΍Ί͍ͨ

    Young GC / G1GCͷίϯύΫγϣϯ
    • ώʔϓྖҬͷେ͖͞ͱGCͰͷఀࢭ͕࣌ؒൺྫ

    View full-size slide

  11. Shenandoah GC

    View full-size slide

  12. Shenandoah GC
    • Redhat͕ࣾ։ൃͨ͠GC
    • 100GBͱ2GBͷఀࢭ͕࣌ؒมΘΒͳ͍
    • 2018/05 όοΫϙʔτ͕ඞཁ

    View full-size slide

  13. GCͷಛ௃
    • ੈ୅ܕϝϞϦ؅ཧΛ͠ͳ͍
    • ϦʔδϣϯܕͷϝϞϦ؅ཧ
    • ฒྻϚʔΩϯάɾฒྻίϯύΫγϣϯ
    • ΞϓϦέʔγϣϯͱฒྻͰಈ͔͠ͳ͕Β

    ίϯύΫγϣϯGC͢Δ೉͠͞ͱ͸ʁ

    View full-size slide

  14. ฒྻίϯύΫγϣϯͷ໰୊఺
    Pointer
    x = 1
    y = 2
    z= 3
    Pointer
    x = 1
    y= 2
    z= 3
    GCεϨου͕Ҡಈத
    • GCεϨου͕ΦϒδΣΫτͷҠಈதʹ

    ϦϑΝϨϯεͷॻ͖׵͕͑ى͖ΔՄೳੑ
    Ͳ͕ͬͪຊ෺ʁ

    View full-size slide

  15. ΦϒδΣΫτͷϔομ͕ΩϞ
    Pointer
    Header
    ͜ΕΛղܾ͢ΔͨΊʹBrooks pointerΛಋೖ

    ϙΠϯλ͕ࣗ෼Ҏ֎ͷϔομΛࢦ͍ͯ͠Δ৔߹

    ͦͷઌͷΦϒδΣΫτΛࢀর͢Δ
    x = 1
    y = 2
    z = 3
    Pointer
    Header
    x = 1
    y= 2
    z= 3
    ຊ෺
    ผͷ৔ॴʹ଴ආ

    View full-size slide

  16. Brooks pointer
    Pointer
    Header
    x = 1
    y = 2
    z= 3
    Pointer
    Header
    x = 1
    y= 2
    z= 3
    ࢀরઌ͕ίϯύΫγϣϯ͞Εͨݹ͍ΦϒδΣΫτͳΒ
    ϔομʔΛͨͲͬͯɺ৽͍͠ΦϒδΣΫτΛࢀর͢Δ

    View full-size slide

  17. GC શମΛோΊͯΈΔ
    Region Region Region Region
    Root

    View full-size slide

  18. Initial-Mark
    Root
    Region Region Region Region
    Root͔ΒͨͲΕΔΦϒδΣΫτΛϚʔΫ͢Δ
    Stop the world

    View full-size slide

  19. Concurrent-Mark
    Root
    Region Region Region Region
    Initial-MarkͰϚʔΫͨ͠ΦϒδΣΫτΛͨͲͬͯϚʔΫ͢Δ
    Concurrent
    ௥Ճ͞Εͨࢀর

    ࡟আ͞Εͨࢀর

    View full-size slide

  20. Final-Remark
    Root
    Region Region Region Region
    Concurrent-Markதʹൃੜͨ͠

    ࢀরͷมߋ൓өɾΰϛΦϒδΣΫτͷ֬ఆ
    Stop the world

    View full-size slide

  21. Concurrent-Compaction
    Root
    Region Region Region Region
    ίϯύΫγϣϯ͢ΔϦʔδϣϯΛܾఆͯ͠

    ΦϒδΣΫτΛୀආ͢Δ
    ୀආ͢ΔϦʔδϣϯ
    Concurrent

    View full-size slide

  22. Concurrent-Compaction
    Root
    Region Region Region Region
    ίϯύΫγϣϯ͢ΔϦʔδϣϯΛܾఆͯ͠

    ΦϒδΣΫτΛୀආ͢Δ
    Concurrent

    View full-size slide

  23. Concurrent-updateReference
    Root
    Region Region Region Region
    ࢀরઌͷϙΠϯλΛୀආઌʹߋ৽͢Δ
    Concurrent
    ৽͍͠ࢀর
    ଴ආઌʹϙΠϯλߋ৽

    View full-size slide

  24. Final-updateReference
    Root
    Region Region Region Region
    Concurrent-updateReferenceதʹൃੜͨ͠ߋ৽Λ൓ө͢Δ
    Stop the world
    ۭʹͳͬͨʂ

    View full-size slide

  25. GCશମΛͳ͕ΊͯΈΔ
    Initial Mark Final Remark
    Concurrent Mark
    Concurrent Compaction
    update Reference
    Concurrent update Reference
    final update Reference
    Application work Application work Application work
    ฒྻίϯύΫγϣϯͷ͓͔͛Ͱ

    ίϯύΫγϣϯ࣌ͷSTWΛͳͭͭ͘͠

    ϑϥάϝϯτΛ๷͙͜ͱ͕Ͱ͖ΔΑ͏ʹͳͬͨ
    Stop the world

    View full-size slide

  26. ZGC
    • OracleͰ։ൃ͞ΕͨGC
    • ਺TBͷώʔϓͰ΋GCʹΑΔఀࢭ࣌ؒ͸

    ୯ௐ૿Ճ͠ͳ͍
    • 2018/05ɺόοΫϙʔτ͕ඞཁ
    • Linux 64bit ͷΈಈ࡞

    View full-size slide

  27. Shenandoah GCͱࣅ͍ͯΔ
    • ίϯηϓτ͸ Shenandoah GCͱಉ͡

    ੈ୅؅ཧͳ͠ɾϦʔδϣϯܕͷϝϞϦ؅ཧ

    ฒྻίϯύΫγϣϯ
    • Linux 64 bit OSͰ͔͠ར༻Ͱ͖ͳ͍

    View full-size slide

  28. ZGCͰಛ௃తͳ΋ͷ
    • ΧϥʔɾϙΠϯλ
    • Linux Ծ૝ϝϞϦͷ׆༻

    64bitͷΞυϨεදݱΛϑϧ׆༻͢Δ
    • ϑΥϫʔσΟϯάɾςʔϒϧ

    View full-size slide

  29. ΧϥʔɾϙΠϯλ
    • ΦϒδΣΫτͷঢ়ଶΛΧϥʔͱͯ͠දݱ
    • ϚʔΫࡁ 0(marked0) ϚʔΫϑΣʔζʹ࢖͏
    • ϚʔΫࡁ 1(marked1) ޙͰৄ͘͠
    • ΦϒδΣΫτ଴ආࡁ (remapped)

    View full-size slide

  30. ΦϒδΣΫτͷΞυϨεදݱ
    42 bit
    ࠷େ4TBͷΞυϨεΛදݱͰ͖Δ
    4
    1
    17 bit
    ະ࢖༻
    ΧϥʔϙΠϯλΛදݱ
    1. 64bitͷΞυϨεۭؒશ෦࢖͏
    2. ώʔϓΞυϨε͸ԼҐ42bitΛར༻
    3. 4bitͰΧϥʔϙΠϯλͷ৭Λදݱ

    View full-size slide

  31. 64bitΞυϨεΛ࠷େݶར༻
    Heap(4TB)
    marked0
    marked1
    remapped
    0x0000040000000000
    0x0000000000000000
    0x0000080000000000
    0x00000C0000000000
    0x0000100000000000
    0x0000140000000000
    0x000010001234abcdef
    1. ΦϒδΣΫτ͸଴ආࡁΈ
    2. 001234abcdefʹ࣮ମ
    ZGCͰ͸64bitͷΞυϨεΛ࢖͏.ϝϞϦ͕128TBඞཁ

    View full-size slide

  32. ڊେϝϞϦͷਖ਼ମ͸Ծ૝Խ
    • ZGCͰ͸64bitΛ͢΂ͯ࢖͏ͷͰ128TBඞཁ
    • ͦΜͳڊେͳϝϞϦͳ͍ΜͰ͕͢…

    ͦ͜ͰԾ૝ϝϞϦΛ࢖ͬͯղܾ͢Δ
    Linuxͷ͍͍ຊ͕࠷ۙͰͨΒ͍͠Ͱ͢Α

    View full-size slide

  33. GC શମΛோΊͯΈΔ
    Region Region Region Region
    Root

    View full-size slide

  34. Initial-Mark
    Root
    Region Region Region Region
    Root͔ΒͨͲΕΔΦϒδΣΫτΛ ͰϚʔΫ͢Δ
    Stop the world

    View full-size slide

  35. Concurrent-Mark
    Root
    Region Region Region Region
    Initial-MarkͰϚʔΫͨ͠ΦϒδΣΫτΛͨͲͬͯϚʔΫ͢Δ
    Concurrent
    ௥Ճ͞Εͨࢀর

    ࡟আ͞Εͨࢀর

    View full-size slide

  36. Final-Remark
    Root
    Region Region Region Region
    Concurrent-Markதʹൃੜͨ͠ࢀরͷมߋ൓өͱ

    ΰϛΦϒδΣΫτͷ֬ఆ
    Stop the world

    View full-size slide

  37. Concurrent-Compaction
    Root
    Region Region Region Region
    ίϯύΫγϣϯ͢ΔϦʔδϣϯΛܾఆ.

    ΦϒδΣΫτΛ଴ආࡁΈͷ ͰϚʔΫͯ͠ɺୀආ͍ͯ͘͠ɻ
    ୀආ͢ΔϦʔδϣϯ
    Concurrent

    View full-size slide

  38. Concurrent-Compaction
    Root
    Region Region Region Region
    Concurrent
    ଴ආͨ͠ΦϒδΣΫτ͸

    ϑΥϫʔσΟϯάςʔϒϧʹϙΠϯλΛه࿥
    ϑΥϫʔσΟϯάɾςʔϒϧ

    View full-size slide

  39. ϑΥϫʔσΟϯάɾςʔϒϧ
    • Shenandoah GCͩͱΦϒδΣΫτ͝ͱʹ

    ϔομʔΛ෇͚Δ෼ɺΦʔόʔϔου͕େ͖͍
    • ΧϥʔϙΠϯλͷ͓͔͛ͰΦϒδΣΫτ͕

    ݹ͍ɾ৽͍͠Λ൑அՄೳ
    • ϑΥϫʔσΟϯάɾςʔϒϧͰϝϞϦઅ໿

    View full-size slide

  40. ࢀরͷߋ৽͸ʁ

    View full-size slide

  41. GCશମΛͳ͕ΊͯΈΔ
    Initial Mark Final Remark
    Concurrent Mark
    Concurrent Compaction
    Application work Application work

    View full-size slide

  42. GCશମΛͳ͕ΊͯΈΔ
    ark Final Remark
    oncurrent Mark
    Concurrent Compaction
    pplication work Application work
    Initial Mark Final Remark
    Concurrent Mark/Remap
    Concurrent Compaction
    Application work Application work
    GC1प໨
    GC2प໨

    View full-size slide

  43. ࢀরͷߋ৽͸࣍ͷGCαΠΫϧͰ
    • ࢀরͷߋ৽͸࣍ͷConcurrent-Markதʹ΍Δ
    • ਖ਼໊ࣜশ͸Concurrent-Mark/Remap
    • ࢀরΛͨͲΔճ਺Λઅ໿
    • ϚʔΩϯά͞ΕͨΦϒδΣΫτ͸

    ͍ͭͷGCαΠΫϧͰϚʔΩϯά͞Εͨʁ

    View full-size slide

  44. Concurrent-Mark/Remap
    Root
    Region Region Region Region
    Concurrent
    ৽͘͠௥Ճ͞Εͨࢀর͸ΧϥʔϙΠϯλͷ
    ϑϥά͕ҧ͏ͷͰɺ ͰϚʔΫ͠ͳ͓͠
    ϑΥϫʔσΟϯάɾςʔϒϧ
    ࢀর͕௥Ճ͞ΕͨͷͰ

    ϚʔΫ͠௚͠

    View full-size slide

  45. Concurrent-Mark/Remap
    Root
    Region Region Region Region
    Concurrent
    ΦϒδΣΫτͷࢀরΛߋ৽΍଴ආ.

    ϦʔδϣϯΛ׬શʹഇغ͢Δ
    ۭʹͳͬͨʂ
    ଴ආ

    View full-size slide

  46. Epsilon GC
    • ΞϓϦέʔγϣϯεϨου͸ఀࢭ͠ͳ͍
    • CPUͷෛՙ͸΄ͱΜͲͳ͠
    • GCͷ࣌ؒ͸ݶΓͳ͘0ʹ͍ۙ

    View full-size slide

  47. ͳʹ΋͠ͳ͍GC

    View full-size slide

  48. ʋ(ŋωŋ)/ţƄŠŖ

    View full-size slide

  49. Epsilon GC
    • JVM։ൃ༻ͷGC
    • ύϑΥʔϚϯεଌఆ࣌ʹGCͰͷੑೳྼԽΛ

    ഉআ͢ΔͨΊ
    • ώʔϓ͕ຒ·Δͱ OutOfMemoryError
    • ຊ൪؀ڥͰ͸࢖Θͳ͍ͰͶ

    View full-size slide

  50. ·ͱΊ
    • ڊେώʔϓɾଟίΞલఏΞϓϦέʔγϣϯ༻GC

    ఀࢭ͕࣌ؒ໰୊ͳΒݕ౼ͷՁ஋͋Γ
    • Linux 64 bit OSͳΒ ZGC
    • ͦΕҎ֎ͳΒ Shenandoah GC
    • Epsilon GC͸Կ΋͠ͳ͍GC

    View full-size slide