From: "jaruga (Jun Aruga)" Date: 2022-06-22T07:06:11+00:00 Subject: [ruby-core:109039] [Ruby master Bug#18829] GC_COMPACTION_SUPPORTED macro should be set and detected automatically. Issue #18829 has been updated by jaruga (Jun Aruga). I think the backport is to apply the 3 commits on the master branch in the chronological order below to a stable branch. https://github.com/ruby/ruby/commit/52d42e702375446746164a0251e1a10bce813b78 https://github.com/ruby/ruby/commit/79eaaf2d0b641710613f16525e4b4c439dfe854e https://github.com/ruby/ruby/commit/2c190863239bee3f54cfb74b16bb6ea4cae6ed20 ---------------------------------------- Bug #18829: GC_COMPACTION_SUPPORTED macro should be set and detected automatically. https://bugs.ruby-lang.org/issues/18829#change-98156 * Author: jprokop (Jarek Prokop) * Status: Closed * Priority: Normal * ruby -v: ruby 3.2.0dev (2022-06-14T01:21:55Z master 048f14221c) [powerpc64le-linux] * Backport: 2.7: DONTNEED, 3.0: REQUIRED, 3.1: REQUIRED ---------------------------------------- After backporting the patch [0] for GC compaction support from https://github.com/ruby/ruby/pull/5934 (for bug https://bugs.ruby-lang.org/issues/18779), I found that there is no mechanism to automatically define the GC_COMPACTION_SUPPORTED based on the platform. This does not seem to be a major issue with the Ruby master branch as the Ruby GC page size is bumped up to 64K so platforms like ppc64le do not struggle anymore, however, if the Ruby GC page size is set to 16K as is the case with Ruby 3.1 for example, then the compaction is enabled even in cases when it should not be. For master I can reach a failure if I set the Ruby GC page size to 16K by editing macro in gc.c (https://github.com/ruby/ruby/blob/master/gc.c#L863) to: ``` c #define HEAP_PAGE_ALIGN_LOG 14 ``` As there are no compile-time checks around this, after compiling ruby and using the following script I get an exception. script: ``` ruby if GC.respond_to?(:compact) GC.verify_compaction_references(double_heap: true, toward: :empty) end 100_000.times do |i| puts "i: #{i}, count: #{count}" end ``` Running it raises an exception even though the code is in a guard clause that should prevent this: ``` ~/.rubies/ruby-master/bin/ruby ./reproducer.rb :251:in `verify_compaction_references': Compaction isn't available on this platform (NotImplementedError) from ./reproducer.rb:4:in `
' ``` Right now, our workaround is to define the macro `GC_COMPACTION_SUPPORTED` only on platforms that we know do support compaction. Ideally, this should not be required and the configuration script or the gc.c file should take care of defining the macro correctly. [0] https://src.fedoraproject.org/fork/jackorp/rpms/ruby/blob/1e34def591d4615bde83a28ff6cd336aa5879a80/f/ruby-3.2.0-define-unsupported-gc-compaction-methods-as-rb_f_notimplement.patch -- https://bugs.ruby-lang.org/ Unsubscribe: