There was a condition that only a heap with > 1 page can move an empty page from free_pages to empty_pages. This was even true during a retire GC (Ractor#join), so running a retire GC couldn't release these actually empty pages back to the page pool. This meant that when a terminated Ractor got absorbed, 768KB (12 heap pages) came with it, even if those pages were empty (this assumes the Ractor had a page for every heap). Since Ractors can now have 0 pages and the main global GC trigger is zombie pages (and not retired Ractors), we need to count retired Ractors with 0 pages towards this zombie pages limit. For now, the floor is HEAP_COUNT (12 pages), but this can be changed if it's too high.
Ruby's Garbage Collectors
This directory contains implementations for Ruby's garbage collector (GC). The GC implementations use the Modular GC API to interact with Ruby. For more details about this API, see the Modular GC API section.
Two GC implementations are included in Ruby:
- Default: The GC implementation that is used by default in Ruby. This GC is stable and production ready. The implementation uses a mark-sweep-compact algorithm.
- MMTk: An experimental implementation using the MMTk framework. The code lives in the ruby/mmtk repository and is synchronized here. MMTk provides a wide variety of GC algorithms to choose from. For usage instructions and current progress, refer to the ruby/mmtk repository.
Building guide
Tip
If you are not sure how to build Ruby, follow the Building Ruby guide.
Important
Ruby's modular GC feature is experimental and subject to change. There may be bugs or performance impacts. Use at your own risk.
Building Ruby with Modular GC
- Configure Ruby with the
--with-modular-gc=<dir>option, wherediris the directory you want to place the built GC libraries into. - Build Ruby as usual.
Building GC implementations shipped with Ruby
- Build your desired GC implementation with
make install-modular-gc MODULAR_GC=<impl>. This will build the GC implementation and place the built library into thedirspecified in step 1.implcan be one of: - Run your desired GC implementation by setting the
RUBY_GC_LIBRARY=<lib>environment variable, wherelibcould bedefault,mmtk, or your own implementation (as long as you place it in thedirspecified in step 1).
Modular GC API
Warning
The Modular GC API is experimental and subject to change without notice.
GC implementations interact with Ruby via the Modular GC API. All implementations must provide the functions in gc/gc_impl.h for Ruby to hook into. GC implementations can use any public C API in Ruby, along with additional APIs defined in gc/gc.h.
Additionally, create an extconf.rb file to build the GC library. This file must use gc/extconf_base.rb and the create_gc_makefile method.