retrofitting parallelism onto ocaml
play

Retrofitting Parallelism onto OCaml KC Sivaramakrishnan , Stephen - PowerPoint PPT Presentation

Retrofitting Parallelism onto OCaml KC Sivaramakrishnan , Stephen Dolan, Leo white, Sadiq Jaffer, Tom Kelly, Anmol Sahoo, Sudha Parimala, Atul Dhiman, Anil Madhavapeddy OCaml Labs Industry Projects The Astre Static Analyzer Industry


  1. Retrofitting Parallelism onto OCaml KC Sivaramakrishnan , Stephen Dolan, Leo white, Sadiq Jaffer, Tom Kelly, Anmol Sahoo, Sudha Parimala, Atul Dhiman, Anil Madhavapeddy OCaml Labs

  2. Industry Projects The Astrée Static Analyzer

  3. Industry Projects No multicore support! The Astrée Static Analyzer

  4. Multicore OCaml • Adds native support for concurrency and shared-memory parallelism to OCaml

  5. Multicore OCaml • Adds native support for concurrency and shared-memory parallelism to OCaml • Focus of this work is parallelism ✦ Building a multicore GC for OCaml

  6. Multicore OCaml • Adds native support for concurrency and shared-memory parallelism to OCaml • Focus of this work is parallelism ✦ Building a multicore GC for OCaml • Key parallel GC design principle ✦ Backwards compatibility before parallel scalability

  7. Challenges • Millions of lines of legacy code ✦ Weak references, ephemerons, lazy values, finalisers ✦ Low-level C API that bakes in GC invariants ✦ Cost of refactoring sequential code itself is prohibitive

  8. Challenges • Millions of lines of legacy code ✦ Weak references, ephemerons, lazy values, finalisers ✦ Low-level C API that bakes in GC invariants ✦ Cost of refactoring sequential code itself is prohibitive • Type safety ✦ Dolan et al, “ Bounding Data Races in Space and Time ”, PLDI’18 ✦ Strong guarantees (including type safety) under data races

  9. Challenges • Millions of lines of legacy code ✦ Weak references, ephemerons, lazy values, finalisers ✦ Low-level C API that bakes in GC invariants ✦ Cost of refactoring sequential code itself is prohibitive • Type safety ✦ Dolan et al, “ Bounding Data Races in Space and Time ”, PLDI’18 ✦ Strong guarantees (including type safety) under data races • Low-latency and predictable performance ✦ Thanks to the GC design

  10. Stock OCaml GC • A generational, non-moving, incremental, mark-and-sweep GC Major Heap • Small (2 MB default) Incremental • Bump pointer allocation and non-moving • Survivors copied to major heap Minor Heap

  11. Stock OCaml GC • A generational, non-moving, incremental, mark-and-sweep GC Major Heap • Small (2 MB default) Incremental • Bump pointer allocation and non-moving • Survivors copied to major heap Minor Heap Idle Mutator Start of major cycle

  12. Stock OCaml GC • A generational, non-moving, incremental, mark-and-sweep GC Major Heap • Small (2 MB default) Incremental • Bump pointer allocation and non-moving • Survivors copied to major heap Minor Heap Idle mark roots Mark Mutator Roots Start of major cycle

  13. Stock OCaml GC • A generational, non-moving, incremental, mark-and-sweep GC Major Heap • Small (2 MB default) Incremental • Bump pointer allocation and non-moving • Survivors copied to major heap Minor Heap Idle mark roots mark main Mark Mutator Mark Roots Start of major cycle

  14. Stock OCaml GC • A generational, non-moving, incremental, mark-and-sweep GC Major Heap • Small (2 MB default) Incremental • Bump pointer allocation and non-moving • Survivors copied to major heap Minor Heap Idle mark roots mark main sweep Mark Mutator Mark Sweep Roots Start of major cycle

  15. Stock OCaml GC • A generational, non-moving, incremental, mark-and-sweep GC Major Heap • Small (2 MB default) Incremental • Bump pointer allocation and non-moving • Survivors copied to major heap Minor Heap Idle mark roots mark main sweep Mark Mutator Mark Sweep Roots Start of major cycle End of major cycle

  16. Stock OCaml GC • A generational, non-moving, incremental, mark-and-sweep GC Major Heap • Small (2 MB default) Incremental • Bump pointer allocation and non-moving • Survivors copied to major heap Minor Heap Idle mark roots mark main sweep Mark Mutator Mark Sweep Roots Start of major cycle End of major cycle • Fast allocations, no read barriers

  17. Stock OCaml GC • A generational, non-moving, incremental, mark-and-sweep GC Major Heap • Small (2 MB default) Incremental • Bump pointer allocation and non-moving • Survivors copied to major heap Minor Heap Idle mark roots mark main sweep Mark Mutator Mark Sweep Roots Start of major cycle End of major cycle • Fast allocations, no read barriers • Max GC latency < 10 ms , 99th percentile latency < 1 ms

  18. Requirements 1. Feature backwards compatibility • Serial programs do not break on parallel runtime • No separate serial and parallel modes

  19. Requirements 1. Feature backwards compatibility • Serial programs do not break on parallel runtime • No separate serial and parallel modes 2. Performance backwards compatibility • Serial programs behave similarly on parallel runtime in terms of running time, GC pausetime and memory usage.

  20. Requirements 1. Feature backwards compatibility • Serial programs do not break on parallel runtime • No separate serial and parallel modes 2. Performance backwards compatibility • Serial programs behave similarly on parallel runtime in terms of running time, GC pausetime and memory usage. 3. Parallel responsiveness and scalability • Parallel programs remain responsive • Parallel programs scale with additional cores

  21. Multicore OCaml: Major GC • Multicore-aware allocator ✦ Based on Streamflow [Schneider et al. 2006] ✦ Thread-local, size-segmented free lists for small objects + malloc for large allocations ✦ Sequential performance on par with OCaml’s allocators

  22. Multicore OCaml: Major GC • Multicore-aware allocator ✦ Based on Streamflow [Schneider et al. 2006] ✦ Thread-local, size-segmented free lists for small objects + malloc for large allocations ✦ Sequential performance on par with OCaml’s allocators • A mostly-concurrent, non-moving, mark-and-sweep collector ✦ Based on VCGC [Huelsbergen and Winterbottom 1998]

  23. Multicore OCaml: Major GC • Multicore-aware allocator ✦ Based on Streamflow [Schneider et al. 2006] ✦ Thread-local, size-segmented free lists for small objects + malloc for large allocations ✦ Sequential performance on par with OCaml’s allocators • A mostly-concurrent, non-moving, mark-and-sweep collector ✦ Based on VCGC [Huelsbergen and Winterbottom 1998] Mark Sweep Mark Domain 0 Roots Mark Domain 1 Sweep Mark Roots Start of major cycle End of major cycle

  24. Multicore OCaml: Major GC • Multicore-aware allocator ✦ Based on Streamflow [Schneider et al. 2006] ✦ Thread-local, size-segmented free lists for small objects + malloc for large allocations ✦ Sequential performance on par with OCaml’s allocators • A mostly-concurrent, non-moving, mark-and-sweep collector ✦ Based on VCGC [Huelsbergen and Winterbottom 1998] Mark Sweep Mark Domain 0 Roots mark and sweep phases may overlap Mark Domain 1 Sweep Mark Roots Start of major cycle End of major cycle

  25. Multicore OCaml: Major GC

  26. Multicore OCaml: Major GC • Extend support weak references, ephemerons, (2 different kinds of) finalizers, fibers, lazy values

  27. Multicore OCaml: Major GC • Extend support weak references, ephemerons, (2 different kinds of) finalizers, fibers, lazy values • Ephemerons are tricky in a concurrent multicore GC ✦ A generalisation of weak references ✦ Introduce conjunction in the reachability property ✦ Requires multiple rounds of ephemeron marking ✦ Cycle-delimited handshaking without global barrier

  28. Multicore OCaml: Major GC • Extend support weak references, ephemerons, (2 different kinds of) finalizers, fibers, lazy values • Ephemerons are tricky in a concurrent multicore GC ✦ A generalisation of weak references ✦ Introduce conjunction in the reachability property ✦ Requires multiple rounds of ephemeron marking ✦ Cycle-delimited handshaking without global barrier • A barrier each for the two kinds of finalisers ✦ 3 barriers / cycle worst case

  29. Multicore OCaml: Major GC • Extend support weak references, ephemerons, (2 different kinds of) finalizers, fibers, lazy values • Ephemerons are tricky in a concurrent multicore GC ✦ A generalisation of weak references ✦ Introduce conjunction in the reachability property ✦ Requires multiple rounds of ephemeron marking ✦ Cycle-delimited handshaking without global barrier • A barrier each for the two kinds of finalisers ✦ 3 barriers / cycle worst case • Verified in the SPIN model checker

  30. Concurrent Minor GC • Based on [Doligez and Leroy 1993] but lazier as in [Marlow and Peyton Jones 2011] collector for GHC Major Heap Minor Minor Minor Minor Heap Heap Heap Heap Domain 0 Domain 1 Domain 2 Domain 3

  31. Concurrent Minor GC • Based on [Doligez and Leroy 1993] but lazier as in [Marlow and Peyton Jones 2011] collector for GHC Major Heap Minor Minor Minor Minor Heap Heap Heap Heap Domain 0 Domain 1 Domain 2 Domain 3 • Each domain can independently collect its minor heap

  32. Concurrent Minor GC • Based on [Doligez and Leroy 1993] but lazier as in [Marlow and Peyton Jones 2011] collector for GHC Major Heap Minor Minor Minor Minor Heap Heap Heap Heap Domain 0 Domain 1 Domain 2 Domain 3 • Each domain can independently collect its minor heap • Major to minor pointers allowed ✦ Prevents early promotion & mirrors sequential behaviour ✦ Read barrier required for mutable field + promotion

  33. Read Barriers • Stock OCaml does not have read barriers ✦ Read barriers need to be efficient for performance backwards compatibility

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend