orca ownership and reference counting based garbage
play

ORCA: Ownership and Reference Counting based Garbage Collection in - PowerPoint PPT Presentation

ORCA: Ownership and Reference Counting based Garbage Collection in the Actor World Sylvan Clebsch, Sebastian Blessing, Juliana Franco, Sophia Drossopoulou Motivation Motivation - 2 ORCA - idea The actor which created an


  1. ORCA: 
 Ownership and 
 Reference Counting based 
 Garbage Collection in the 
 Actor World Sylvan Clebsch, Sebastian Blessing, Juliana Franco, Sophia Drossopoulou

  2. Motivation

  3. Motivation - 2

  4. ORCA - idea • The actor which created an object is its owner . • Owning actor is responsible for GC-ing its objects. Challenges & Solutions • An actor may have no path to an object it owns, while other actors have. • Actor keeps a Reference Count for some objects; it represents the foreign references to that object held by the other actors. • The number of foreign references to an owned object may change (actor’s view of its owned objects may be inconsistent with world). • ORCA-specific messages reconcile an actor’s view of its object with the real world view.

  5. Orca - configurations

  6. Runtime configuration Ownership diagram: a1 a2 An actor a has: - references to objects and actors, o2 o1 - queue of messages Queue(a) , o3 o4 - a working set WS(a) , a superset of addresses reachable by actor a Queues: APP(o1) :: INC(o1,1) APP(o3) - a ref-count table for some addresses from WS(a) , 
 Working Sets: e.g. RC(a1,a2) = 5 
 a1, a2, o1, o2, o4 a1, a2, o1, o2, o3 Note, no RC(a2,o4 ) entry Reference Count Tables: Each object is owned by an a1 a2 o1 o2 o3 a1 a2 o1 o2 o3 actor; each actor owns itself. 
 12 5 1 3 1 10 6 1 4 0 e.g. Owner(o1) = a1 *Grey cells represent owned objects Mssg(a, j): j-th message in a 's queue 
 e.g. Mssg(a1,2) = INC(o1,1) Actor Object

  7. Orca - derived properties

  8. Derived Counts - 1 a1 a2 Local Reference Count: o2 o1 LRC( 𝛽 ) = RC( 𝛽 , Owner ( 𝛽 )) the entry for address 𝛽 in the o3 o4 ref-cnt table of its owner. Queues: APP(o1) :: INC(o1,1) APP(o3) LRC(a1) = 12 Working Sets: a1, a2, o1, o2, o4 a1, a2, o1, o2, o3 LRC(o2) = 4 Reference Count Tables: a1 a2 a1 a2 o1 o2 o3 o1 o2 o3 12 5 1 3 1 10 6 1 4 0

  9. Derived Counts - 2 a1 a2 Foreign Reference Count: o2 FRC( 𝛽 ) o1 the sum of entries for address 𝛽 o3 o4 in the ref-cnt table of all non- owning actors Queues: APP(o1) :: INC(o1,1) APP(o3) Working Sets: a1, a2, o1, o2, o4 a1, a2, o1, o2, o3 FRC(a2) = 5 Reference Count Tables: a1 a2 a1 a2 o1 o2 o3 o1 o2 o3 12 5 1 3 1 10 6 1 4 0 FRC(a1) = 10

  10. Ownership diagram: Derived Counts - 3 a1 a2 Incr/decrement Count: o2 IDC( 𝛽 ) o1 sum of weighted references to o3 o4 address 𝛽 in INC and DEC messages in 𝛽 's owner queue. Queues: APP(o1) :: INC(o1,1) APP(o3) Working Sets: a1, a2, o1, o2, o4 a1, a2, o1, o2, o3 IDC(o1) = 1 Reference Count Tables: a1 a2 a1 a2 o1 o2 o3 o1 o2 o3 12 5 1 3 1 10 6 1 4 0

  11. Derived Counts - 4 a1 a2 Application Message Count: o2 AMC( 𝛽 ) o1 number of APP messages in o3 o4 all queues which contain 𝛽 , addresses owned by 𝛽 or Queues: reachable from 𝛽 . APP(o1) :: INC(o1,1) APP(o3) Working Sets: a1, a2, o1, o2, o4 a1, a2, o1, o2, o3 AMC(o1) = 1 Reference Count Tables: a1 a2 a1 a2 o1 o2 o3 o1 o2 o3 12 5 1 3 1 10 6 1 4 0 AMC(o2) = 1 AMC(a2) = 1 AMC(a1) = 2

  12. Ownership diagram: Derived Counts - 5 a1 a2 Pending Changes Count: o2 PCC( 𝛽 , a , q ) o1 sum of weights of INC & o3 o4 DEC messages in q minus number of APP messages Queues: containing address 𝛽 , in APP(o1) :: INC(o1,1) APP(o3) actor a . Working Sets: a1, a2, o1, o2, o4 a1, a2, o1, o2, o3 Reference Count Tables: T ake a1 a2 a1 a2 o1 o2 o3 o1 o2 o3 q1=APP(o1) 12 5 1 3 1 10 6 1 4 0 q2=INC(o1,1) *Grey cells represent owned objects then PCC(o1,a1,q1) = -1 PCC(o1,a1,q1:q2) = 0

  13. Wellformed Configurations

  14. Well-formedness a1 a2 WF0: LRC( 𝛽 )+IDC( 𝛽 ) = o2 FRC( 𝛽 )+AMC( 𝛽 ) o1 o3 o4 WF1: RC(a, 𝛽 ) ≥ 0 Queues: WF2: 𝛽 reachable from a 
 APP(o1) :: INC(o1,1) APP(o3) ⟹ 𝛽 ∈ WS(a) Working Sets: a1, a2, o1, o2, o4 WF3: 𝛽 reachable from Msg(_,_) 
 a1, a2, o1, o2, o3 ⟹ LRC( 𝛽 )>0 Reference Count Tables: a1 a2 a1 a2 o1 o2 o3 o1 o2 o3 WF4: 𝛽 ∈ WS(a) ⋀ a ≠ Owner( 𝛽 ) 
 12 5 1 3 1 10 6 1 4 0 ⟹ RC(a, 𝛽 )>0 ⋀ LRC( 𝛽 )>0 Consequence: WF5: q::_ = Queue(a) 
 𝛽 unreachable from Owner( 𝛽 ) ⋀ LRC( 𝛽 )=0 ⟹ LRC( 𝛽 )+PCC( 𝛽 , a,q)>0 ⟹ 𝛽 globally unreachable

  15. Garbage Collection

  16. Garbage Collection 
 the recipe 1. Mark owned objects as U . 
 2. Mark unowned addresses with RC>0 as U . 
 3. Trace from the actor's fields, marking as R . 
 4. Mark owned objects with LRC>0 as R . 
 5. Collect U , owned objects 7. Send DEC messages for U unowned addresses; set their RC to 0.

  17. Garbage Collection U U R R a1 a2 a2 is doing Garbage Collection U R 1. Mark owned objects as U . 
 U R o2 o1 a2, o2 U 2. Mark unowned addresses o3 with RC>0 as U . 
 a1, o1, o3 Queues: 3. Trace from the actor's fields, APP(o1) :: INC(o1,1) DEC(o3, 1) APP(o1) marking as R . 
 Working Sets: o2, a2, o1, a1 a1, a2, o1, o2, o3 a1, a2, o1, o2, o3 4. Mark owned objects with LRC>0 as R . 
 Reference Count Tables: a2, o2 a1 a2 a1 a2 o1 o2 o3 o1 o2 o3 5. Collect U , owned objects 
 13 5 2 2 1 11 6 1 4 1 0 6. Send DEC messages for U unowned addresses; set their RC to 0. 
 o3

  18. Collecting Objects: 
 the recipe U U R R a1 a2 a1 is doing Garbage Collection U R 1. Mark owned objects as U . 
 U R o2 o1 a1, o1, o3 U 2. Mark unowned addresses o3 with RC>0 as U . 
 Queues: a2, o2 3. Trace from the actor's APP(o1) The queue is empty fields, marking as R . 
 Working Sets: o1, o2, a2 a1, a2, o1, o2 a1, a2, o1, o2, o3 4. Mark owned objects with Reference Count Tables: LRC>0 as R . 
 a1 a2 a1 a2 o1 o2 o3 o1 o2 o3 a1, o1 13 5 2 2 0 11 6 1 4 0 5. Collect U , owned objects 
 o3 6. Send DEC messages for U unowned addresses; set their RC to 0.

  19. Maintaining 
 Well-formedness

  20. WF0: LRC( 𝛽 ) + IDC( 𝛽 ) = FRC( 𝛽 )+AMC( 𝛽 ) WF1: RC(a, 𝛽 ) ≥ 0 WF2: 𝛽 reachable from a ⟹ 𝛽 ∈ WS(a) WF3: 𝛽 reachable from Msg(_,_) ⟹ LRC( 𝛽 )>0 WF4: 𝛽 ∈ WS(a) ⋀ a ≠ Owner( 𝛽 ) ⟹ RC(a, 𝛽 )>0 ⋀ LRC( 𝛽 )>0 WF5: q::_ = Queue(a) ⟹ LRC( 𝛽 )+PCC( 𝛽 , a,q)>0 Which actor actions affect WF1-5? WF0, WF3, WF5 • actor sends a Pony message WF0, WF2, WF3 • actor receives a Pony message • actor receives an ORCA message (INC or DEC) WF2, WF0, WF5 • actor garbage collects WF3? No! Pony’s types • heap topology changes • call/execute synchronous method

  21. Maintaining wellformedness a1 a2 f Action: heap mutation o2 o1 a1.f = null o3 Which WF invariant is affected? Queues: APP(o1) :: INC(o1,1) APP(o1) None! Working Sets: a1, a2, o1, o2, o3 a1, a2, o1, o2, o3 However o3 is in the working set of Reference Count Tables: a1… at least until the next a1 a2 a1 a2 o1 o2 o3 o1 o2 o3 Garbage Collection cycle! 13 5 2 2 1 11 6 1 4 1

  22. Maintaining wellformedness a1 a2 Action: actor sends message o2 a1 sends to a2 APP(o1) o1 o3 WFO: 
 LRC(o1) + IDC(o1) = FRC(o1) + AMC(o1) Queues: +1 APP(o3) :: APP(o1) APP(o1) :: INC(o1,1) Working Sets: a1, a2, o1, o2 How can a1 preserve WF0? a1, a2, o1, o2, o3 RC(a1,o1) += 1 Reference Count Tables: RC(a1,a1) += 1 a1 a2 a1 a2 o1 o2 o3 o1 o2 o3 12 5 1 3 1 10 6 1 4 0 12+1 1+1 3-1 5 -1 RC(a1,o2) -= 1 RC(a1,a2) -= 1

  23. Why Causality?

  24. Causality required because … WF0: LRC( 𝛽 ) + IDC( 𝛽 ) = FRC( 𝛽 )+AMC( 𝛽 ) WF1: RC(a, 𝛽 ) ≥ 0 WF2: 𝛽 reachable from a ⟹ 𝛽 ∈ WS(a) WF3: 𝛽 reachable from Msg(_,_) ⟹ LRC( 𝛽 )>0 WF4: 𝛽 ∈ WS(a) ⋀ a ≠ Owner( 𝛽 ) ⟹ RC(a, 𝛽 )>0 ⋀ LRC( 𝛽 )>0 WF5: q::_ = Queue(a) ⟹ LRC( 𝛽 )+PCC( 𝛽 , a,q)>0

  25. Race Conditions?

  26. Race Conditions? Source language level Can an actor read an object mutated by another actor? Can an actor mutate an object mutated by another actor? Source language and GC level Can an actor trace an object mutated by another actor? Can an actor read an object garbage collected by another actor? Can an actor trace an object garbage collected by another actor?

  27. How efficient is ORCA?

  28. Benchmark - creating 1M actors

  29. Benchmark - mailbox 100,000,000 msgs

  30. Benchmark - mixed

  31. Benchmarks - GUPS linpack

  32. Summary • Fully concurrent (other actors may run while an actor is GCing) • No synchronisation mechanism needed, no stop-the world, no barrier • Owning actor responsible for GC-ing its objects • Application of the actor paradigm into the design of the protocol • Further Work: • complete the formal model • weaken the WF-conditions and Causality requirement • HOMEWORK : apply to Encore more about it: OOPSLA’13, ICOOOLPS’15

  33. More about Pony at http://www.ponylang.org/ Thank you!

Recommend


More recommend