This repository holds the MMTk bindings for Ruby. The binding plugs into Ruby using the garbage collector API implemented in [Feature #20470]. This API allows Ruby to use alternative garbage collector implementations such as MMTk.
Note
This repository is synchronized into ruby/ruby, you can choose to either build it in this repository or build it in ruby/ruby. If you're building it in this repository, note that it is only expected to work on the latest commit of Ruby master.
- Ensure you have the Rust toolchain installed. You can follow these instructions to install it.
- Ensure that you are running with Ruby from the latest commit of Ruby master and your Ruby is configured with
--with-modular-gc. If you're unsure how to do this, refer to the "building guide" for modular GC. - Run
bundle install. - Run
bundle exec rake install:debugorbundle exec rake install:releaseto compile and install MMTk as a modular GC. - You can now run Ruby with environment variable
RUBY_GC_LIBRARY=mmtkto use MMTk.
After building Ruby and the MMTk bindings, run Ruby with RUBY_GC_LIBRARY=mmtk environment variable. You can also configure the following environment variables:
MMTK_PLAN=<NoGC|MarkSweep|Immix>: Configures the GC algorithm used by MMTk. Defaults toImmix.MMTK_HEAP_MODE=<fixed|dynamic|ruby|cpu>: Configures the MMTk heap used. Defaults todynamic.fixed: a fixed size heap.dynamic: a dynamic sized heap that will grow and shrink in size based on heuristics using the MemBalancer algorithm.ruby: a dynamic sized heap that grows and shrinks based on the ratio of free to used slots, using the sameRUBY_GC_HEAP_FREE_SLOTS_*_RATIOenv vars as the default Ruby GC.cpu: a dynamic sized heap that adjusts itself to hit a target GC CPU overhead, using the algorithm from Tavakolisomeh et al., "Heap Size Adjustment with CPU Control" (MPLR '23). Tunable viaMMTK_GC_CPU_TARGETandMMTK_GC_CPU_WINDOW(see below).
MMTK_HEAP_MIN=<size>: Configures the lower bound in heap memory usage by MMTk. Only valid whenMMTK_HEAP_MODEisdynamic,ruby, orcpu.sizeis in bytes, but you can also appendKiB,MiB,GiBfor larger sizes. Defaults to 1MiB.MMTK_HEAP_MAX=<size>: Configures the upper bound in heap memory usage by MMTk. Once this limit is reached and no objects can be garbage collected, it will crash with an out-of-memory.sizeis in bytes, but you can also appendKiB,MiB,GiBfor larger sizes. Defaults to 80% of your system RAM.MMTK_GC_CPU_TARGET=<percent>: Target GC CPU overhead, as a percentage, whenMMTK_HEAP_MODE=cpu. After each GC cycle, the heap is grown if the measured GC CPU overhead exceeds this target and shrunk if it falls below. Defaults to5. The paper recommends15for the concurrent collector it targets (ZGC), but on MMTk-Ruby's stop-the-world Immix every percent of GC CPU also blocks the mutator, so a smaller budget gives better throughput. Empirical sweeps across ruby-bench find 5 Pareto-optimal vs. therubyheap mode (~6% geomean speedup at essentially equal peak RSS).MMTK_GC_CPU_WINDOW=<n>: Number of recent GC cycles averaged when measuring GC CPU overhead forMMTK_HEAP_MODE=cpu. Larger values smooth the signal at the cost of responsiveness. Defaults to3.