Compacting GC in MRI
summary
Implemented a mark‑compact GC for MRI with a new GC.compact API and a simple two‑finger compaction algorithm; introduces forwarding objects, pin bits, and a GC move routine in a GitHub fork of Ruby 2.5 trunk. Measurement uses object_space JSON dumps and /proc/smaps (RSS/PSS/shared dirty) and targets Unicorn forked workers (compact then fork). Current limitations pin RB_GC_marked objects, hash keys, C↔Ruby dual refs and bytecode literals, yet 46% movable objects are compacted and microbenchmarks show ~150 KB PSS savings so far.
AI-written summary · about
chapters (31)
- 0:00Start
- 6:28Exploring Memory in Ruby
- 8:23Ruby String
- 9:08Ruby Array
- 9:20Ruby Hash
- 10:18Ruby Fork
- 10:52OS Memory Copy
- 14:31Mark Phase
- 15:43Bitmap Marking
- 17:56Nakayoshi Fork Source
- 18:40Object Allocation
- 19:35Compact Before Fork
- 23:03Disadvantages
- 24:15Algorithm
- 24:26Object Movement
- 26:02Reference Updating
- 30:04Reference Update Helpers
- 31:15Pure Ruby References
- 31:46C References
- 34:20What can move?
- 34:49Hashing
- 35:50Dual References
- 37:24Global Variables (in C)
- 38:31String Literals
- 40:56Before Compaction
- 41:15After Compaction
- 42:30Measuring Rails Boot
- 42:46Output
- 44:07Heap Fragmentation
- 47:53Copying Memory
- 48:50Compaction Impact







