Save 37% off PRO during our Black Friday Sale! »

introduction-to-modern-gc

 introduction-to-modern-gc

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

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

49b08973c143dc1424a05364e518d361?s=128

tomoya yokota

May 26, 2018
Tweet

Transcript

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

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

    GC
  3. ͜Ε·ͰͷGC

  4. GCͱΞϓϦఀࢭ(STW) Compaction GC Parallel GC young gc old gc GC

    = ΞϓϦέʔγϣϯεϨουఀࢭ ϝϞϦ͕ϑϥάϝϯτ͠ͳ͍ CPUෛՙ͸খ͍͞ Stop The world = ΞϓϦέʔγϣϯεϨουͷఀࢭ Mark Compaction GC Noop
  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 = ΞϓϦέʔγϣϯεϨουͱฒྻ
  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 = ΞϓϦέʔγϣϯεϨουͱฒྻ
  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
  8. GCͱΞϓϦͷఀࢭ(STW) • ίϯύΫγϣϯGCͰఀࢭ
 ੈ୅ܕGC͸Young GCͰఀࢭ
 ੜଘͷΦϒδΣΫτͷ଴ආͰఀࢭ • ίϯύΫγϣϯ͠ͳ͍ͱϝϞϦ͕
 ϑϥάϝϯτͯ͠͠·͏

  9. ͳͥ৽GCͳͷ͔

  10. ৽͍͠GCͷඞཁੑ • ڊେώʔϓΛ࢖͏ΞϓϦέʔγϣϯͷ୆಄
 ElasticsearchͳͲ • ίϯύΫγϣϯܕGCͷఀࢭΛ΍Ί͍ͨ
 Young GC / G1GCͷίϯύΫγϣϯ

    • ώʔϓྖҬͷେ͖͞ͱGCͰͷఀࢭ͕࣌ؒൺྫ
  11. Shenandoah GC

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

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

  14. ฒྻίϯύΫγϣϯͷ໰୊఺ Pointer x = 1 y = 2 z= 3

    Pointer x = 1 y= 2 z= 3 GCεϨου͕Ҡಈத • GCεϨου͕ΦϒδΣΫτͷҠಈதʹ
 ϦϑΝϨϯεͷॻ͖׵͕͑ى͖ΔՄೳੑ Ͳ͕ͬͪຊ෺ʁ
  15. ΦϒδΣΫτͷϔομ͕ΩϞ Pointer Header ͜ΕΛղܾ͢ΔͨΊʹBrooks pointerΛಋೖ
 ϙΠϯλ͕ࣗ෼Ҏ֎ͷϔομΛࢦ͍ͯ͠Δ৔߹
 ͦͷઌͷΦϒδΣΫτΛࢀর͢Δ x = 1

    y = 2 z = 3 Pointer Header x = 1 y= 2 z= 3 ຊ෺ ผͷ৔ॴʹ଴ආ
  16. Brooks pointer Pointer Header x = 1 y = 2

    z= 3 Pointer Header x = 1 y= 2 z= 3 ࢀরઌ͕ίϯύΫγϣϯ͞Εͨݹ͍ΦϒδΣΫτͳΒ ϔομʔΛͨͲͬͯɺ৽͍͠ΦϒδΣΫτΛࢀর͢Δ
  17. GC શମΛோΊͯΈΔ Region Region Region Region Root

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

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

    ࡟আ͞Εͨࢀর
  20. Final-Remark Root Region Region Region Region Concurrent-Markதʹൃੜͨ͠
 ࢀরͷมߋ൓өɾΰϛΦϒδΣΫτͷ֬ఆ Stop the

    world
  21. Concurrent-Compaction Root Region Region Region Region ίϯύΫγϣϯ͢ΔϦʔδϣϯΛܾఆͯ͠
 ΦϒδΣΫτΛୀආ͢Δ ୀආ͢ΔϦʔδϣϯ Concurrent

  22. Concurrent-Compaction Root Region Region Region Region ίϯύΫγϣϯ͢ΔϦʔδϣϯΛܾఆͯ͠
 ΦϒδΣΫτΛୀආ͢Δ Concurrent

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

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

    ۭʹͳͬͨʂ
  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
  26. ZGC

  27. ZGC • OracleͰ։ൃ͞ΕͨGC • ਺TBͷώʔϓͰ΋GCʹΑΔఀࢭ࣌ؒ͸
 ୯ௐ૿Ճ͠ͳ͍ • 2018/05ɺόοΫϙʔτ͕ඞཁ • Linux

    64bit ͷΈಈ࡞
  28. Shenandoah GCͱࣅ͍ͯΔ • ίϯηϓτ͸ Shenandoah GCͱಉ͡
 ੈ୅؅ཧͳ͠ɾϦʔδϣϯܕͷϝϞϦ؅ཧ
 ฒྻίϯύΫγϣϯ • Linux

    64 bit OSͰ͔͠ར༻Ͱ͖ͳ͍
  29. ZGCͰಛ௃తͳ΋ͷ • ΧϥʔɾϙΠϯλ • Linux Ծ૝ϝϞϦͷ׆༻
 64bitͷΞυϨεදݱΛϑϧ׆༻͢Δ • ϑΥϫʔσΟϯάɾςʔϒϧ

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

    ޙͰৄ͘͠ • ΦϒδΣΫτ଴ආࡁ (remapped)
  31. ΦϒδΣΫτͷΞυϨεදݱ 42 bit ࠷େ4TBͷΞυϨεΛදݱͰ͖Δ 4 1 17 bit ະ࢖༻ ΧϥʔϙΠϯλΛදݱ

    1. 64bitͷΞυϨεۭؒશ෦࢖͏ 2. ώʔϓΞυϨε͸ԼҐ42bitΛར༻ 3. 4bitͰΧϥʔϙΠϯλͷ৭Λදݱ
  32. 64bitΞυϨεΛ࠷େݶར༻ Heap(4TB) marked0 marked1 remapped 0x0000040000000000 0x0000000000000000 0x0000080000000000 0x00000C0000000000 0x0000100000000000

    0x0000140000000000 0x000010001234abcdef 1. ΦϒδΣΫτ͸଴ආࡁΈ 2. 001234abcdefʹ࣮ମ ZGCͰ͸64bitͷΞυϨεΛ࢖͏.ϝϞϦ͕128TBඞཁ
  33. ڊେϝϞϦͷਖ਼ମ͸Ծ૝Խ • ZGCͰ͸64bitΛ͢΂ͯ࢖͏ͷͰ128TBඞཁ • ͦΜͳڊେͳϝϞϦͳ͍ΜͰ͕͢…
 ͦ͜ͰԾ૝ϝϞϦΛ࢖ͬͯղܾ͢Δ Linuxͷ͍͍ຊ͕࠷ۙͰͨΒ͍͠Ͱ͢Α

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

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

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

    ࡟আ͞Εͨࢀর
  37. Final-Remark Root Region Region Region Region Concurrent-Markதʹൃੜͨ͠ࢀরͷมߋ൓өͱ
 ΰϛΦϒδΣΫτͷ֬ఆ Stop the

    world
  38. Concurrent-Compaction Root Region Region Region Region ίϯύΫγϣϯ͢ΔϦʔδϣϯΛܾఆ.
 ΦϒδΣΫτΛ଴ආࡁΈͷ ͰϚʔΫͯ͠ɺୀආ͍ͯ͘͠ɻ ୀආ͢ΔϦʔδϣϯ

    Concurrent
  39. Concurrent-Compaction Root Region Region Region Region Concurrent ଴ආͨ͠ΦϒδΣΫτ͸
 ϑΥϫʔσΟϯάςʔϒϧʹϙΠϯλΛه࿥ ϑΥϫʔσΟϯάɾςʔϒϧ

  40. ϑΥϫʔσΟϯάɾςʔϒϧ • Shenandoah GCͩͱΦϒδΣΫτ͝ͱʹ
 ϔομʔΛ෇͚Δ෼ɺΦʔόʔϔου͕େ͖͍ • ΧϥʔϙΠϯλͷ͓͔͛ͰΦϒδΣΫτ͕
 ݹ͍ɾ৽͍͠Λ൑அՄೳ • ϑΥϫʔσΟϯάɾςʔϒϧͰϝϞϦઅ໿

  41. ࢀরͷߋ৽͸ʁ

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

    work Application work
  43. 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प໨
  44. ࢀরͷߋ৽͸࣍ͷGCαΠΫϧͰ • ࢀরͷߋ৽͸࣍ͷConcurrent-Markதʹ΍Δ • ਖ਼໊ࣜশ͸Concurrent-Mark/Remap • ࢀরΛͨͲΔճ਺Λઅ໿ • ϚʔΩϯά͞ΕͨΦϒδΣΫτ͸
 ͍ͭͷGCαΠΫϧͰϚʔΩϯά͞Εͨʁ

  45. Concurrent-Mark/Remap Root Region Region Region Region Concurrent ৽͘͠௥Ճ͞Εͨࢀর͸ΧϥʔϙΠϯλͷ ϑϥά͕ҧ͏ͷͰɺ ͰϚʔΫ͠ͳ͓͠

    ϑΥϫʔσΟϯάɾςʔϒϧ ࢀর͕௥Ճ͞ΕͨͷͰ
 ϚʔΫ͠௚͠
  46. Concurrent-Mark/Remap Root Region Region Region Region Concurrent ΦϒδΣΫτͷࢀরΛߋ৽΍଴ආ.
 ϦʔδϣϯΛ׬શʹഇغ͢Δ ۭʹͳͬͨʂ

    ଴ආ
  47. Epsilon GC

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

  49. ͳͥͳΒ

  50. ͳʹ΋͠ͳ͍GC

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

  52. Epsilon GC • JVM։ൃ༻ͷGC • ύϑΥʔϚϯεଌఆ࣌ʹGCͰͷੑೳྼԽΛ
 ഉআ͢ΔͨΊ • ώʔϓ͕ຒ·Δͱ OutOfMemoryError

    • ຊ൪؀ڥͰ͸࢖Θͳ͍ͰͶ
  53. ·ͱΊ • ڊେώʔϓɾଟίΞલఏΞϓϦέʔγϣϯ༻GC
 ఀࢭ͕࣌ؒ໰୊ͳΒݕ౼ͷՁ஋͋Γ • Linux 64 bit OSͳΒ ZGC

    • ͦΕҎ֎ͳΒ Shenandoah GC • Epsilon GC͸Կ΋͠ͳ͍GC