Papers We Love - Immix mark-region garbage collector

A8e44ce1b57c2689d5a7172d15df42b5?s=47 brixen
August 25, 2016

Papers We Love - Immix mark-region garbage collector

Papers We Love Portland, OR presentation 25 Aug 2016 on the Immix mark-region garbage collector.

A8e44ce1b57c2689d5a7172d15df42b5?s=128

brixen

August 25, 2016
Tweet

Transcript

  1. Immix: A Mark-Region Garbage Collector Brian Shirai · Portland ·

    25 Aug 2016 Portland
  2. None
  3. 1. Introduction to garbage collection 2. Immix mark-region collector 3.

    Experience with (Immix) in Rubinius Agenda
  4. 1. Qualifications 2. Exploration and experimentation 3. Ask questions Preface

  5. None
  6. What is garbage collection?

  7. Illusion of infinite space Memory management

  8. 1. Allocator 2. Mutator 3. Collector Software Components

  9. 1. Allocation 2. Identification 3. Reclamation MM Operations

  10. Manual vs automatic memory management

  11. void fun(Obj a) { Obj m = new Obj(a); work(m);

    delete(m); } Manual Automatic void fun(Obj a) { Obj m(a); work(m); } Managing memory is coupled with program meaning Is the object m garbage collected?
  12. Implicit vs explicit

  13. Stack allocation return addr reg N reg M local 0

    obj B obj A ... stack pointer (SP) what is the lifetime of A? does it exceed SF lifetime?
  14. 1. Allocation

  15. Bump-pointer allocation Obj m = new Obj(a); 0 N M

    M+S current pointer = start of free space new start of free space S = size of object T
  16. Obj m = new Obj(a); Free-list allocation ... new object

  17. 2. Identification

  18. Computing the transitive closure over the object graph

  19. Let be an object graph Let A, B, C be

    elements of a graph If A ∈ and A → B, then B ∈ If A ∈ and A → B and B → C, then C ∈
  20. Reference counting vs tracing Classification

  21. Reference counting illustrated A C B 1 N M

  22. Reference counting illustrated A C B 2 N M

  23. Reference counting illustrated A C B 2 N M+1

  24. Reference counting illustrated A C B 1 N M+1 reachable

    unreachable
  25. Tracing illustrated R1 A R2 C B D E F

  26. Tracing illustrated R1 A R2 C B D E F

  27. Tracing illustrated R1 A R2 C B D E F

  28. Tracing illustrated R1 A R2 C B D E F

  29. Tracing illustrated R1 A R2 C B D E F

  30. Tracing illustrated R1 A R2 C B D E F

  31. Tracing illustrated scanning marking header fields side table

  32. 3. Reclamation

  33. Family accurate conservative non-moving moving mark-sweep semi-space mark-compact mark-region

  34. generational Configurations full-heap multi-region nursery young mature

  35. Time 1 thread N threads separate interleaved stop-the-world incremental parallel

    concurrent
  36. 1. Space efficiency 2. Fast collection 3. Mutator performance Space-time

    tradeoff
  37. Space efficiency 1. Ratio of space used / space reserved

    close to 1 2. Percentage of space used by metadata as small as possible ( < 1-2%) Fragmentation is the biggest opponent
  38. Fast collection 1. Touch as few objects as possible 2.

    Perform as few operations per object as possible
  39. Mutator performance 1. Allocation must be fast 2. Identification must

    be fast 3. Reclamation must be fast
  40. Space efficiency Fast collection Mutator performance

  41. Semi-space from to

  42. Mark-sweep R1 A B D .

  43. Mark-compact R1 A B D

  44. Mark-region R1 A B D

  45. None
  46. Two lines define a point Two points define a line

    Duals Two X define a Y ^ intersecting ^ dissimilar
  47. Summary Space-time tradeoff Canonical collectors Software Components MM Operations

  48. Immix

  49. Heap structure Heap divided into blocks Block divided into lines

    Objects cannot span blocks Objects can span lines
  50. Initial allocation 0 N M M+S current pointer = start

    of free space new start of free space S = size of object
  51. Identification R1 A R2 C B D E F

  52. Reclamation completely free blocks can be reclaimed completely free lines

    can be reclaimed
  53. Steady-state allocation Block divided into lines previous current free new

    objects bump-allocated into holes
  54. Steady-state allocation X N M M+S a hole is free

    range between two pointers (found lazily) Y what happens when an object is too big to fit in the current hole?
  55. Defragmentation Opportunistic evacuation while marking R1 A B D fragmented

  56. Details and policies 1. When to recycle a block? F

    = 1 free object 2. Where to allocate "medium" objects? Overflow block 3. Parallelism - multiple allocator and collector threads, but not concurrent collection 4. Allocate into completely free blocks last
  57. Evaluation

  58. Space efficiency 1. Ratio of space reserved / space used

    close to 1 2. Percentage of space used by metadata as small as possible ( < 1-2%) Fragmentation is the biggest opponent
  59. Fast collection 1. Touch as few objects as possible 2.

    Perform as few operations per object as possible
  60. Mutator performance 1. Allocation must be fast 2. Identification must

    be fast 3. Reclamation must be fast
  61. Rubinius

  62. Difficulty with semi-space n t n t

  63. Complexity of multiple collectors

  64. Fragmentation 1. Bad: occupancy ~20% 2. No overflow allocation and

    bigger "medium" object size 3. No defragmentation
  65. Concurrent collection Hard

  66. Parallel collection Relatively easy No GIL

  67. Current work 1. Per-thread Immix region (generational and isolatable heaps)

    2. Two tenured regions 3. Large-object region
  68. Current work TLR Region 1 Region 2 LOR Overflow promotion

  69. 1. Method inline cache region 2. Constant inline cache region

    3. Machine code region 4. Symbol region 5. Variable scope region 6. Roots region 7. Object finalizer region 8. Inflated header region
  70. "Every system with a primary tracing collector has a poorly

    specified, buggy, slow, partial implementation of a reference counting collector."
  71. Reference counting class method table Compiled Code entry Machine Code

    InlineCache Constant Cache Memo
  72. Heterogeneous objects header Data Object ivars class fields header fields

  73. Allocation instructions

  74. $ rbx compile -B -e 'Array.new' ============= :__script__ ============== Arguments:

    0 required, 0 post, 0 total Arity: 0 Locals: 0 Stack size: 2 Literals: 4: :Array, :new, :allocate, :initialize Lines to IP: 1: 0..22 0000: push_const :Array 0002: dup 0003: check_serial :new, 47 0006: goto_if_false 0018: 0008: allow_private 0009: send_method :allocate 0011: dup 0012: allow_private 0013: send_method :initialize 0015: pop 0016: goto 0020: 0018: send_method :new 0020: pop 0021: push_true 0022: ret ----------------------------------------
  75. $ rbx compile -B -e 'Array.new' ============= :__script__ ============== Arguments:

    0 required, 0 post, 0 total Arity: 0 Locals: 0 Stack size: 1 Literals: 1: :Array Lines to IP: 1: 0..5 0000: push_const :Array 0002: allocate 0003: pop 0004: push_true 0005: ret ----------------------------------------
  76. rubinius.com/book

  77. rubinius.com/contribute

  78. Thanks!