Backport Ruby ISEQ and imemo_env Copy-on-Write GC fixes for 3.3

What does this MR do?

Backports both commits of ruby/ruby#10899 to Ruby 3.3:

  1. ruby/ruby@9d6b8806 — avoid unnecessary writes to iseq call caches during GC.
  2. ruby/ruby@520ab222 — avoid the same unnecessary write to block environments (procs, lambdas, define_method) during GC.

On a major GC, Ruby 3.3 rewrites inactive iseq call caches with the shared empty cache even when they already hold it, and re-sets the WB_REQUIRED flag on block environments that already have it. Both writes force Copy-on-Write on the memory page, so each Puma worker copies private memory it would otherwise share with the master on its first major GC (~115 MiB from the call-cache write plus the remainder from the env write).

The first write is a Ruby 3.3 regression; the second predates 3.2. Both are included upstream in Ruby 3.4, so these patches are only needed for 3.3 until the upgrade in &16601 ships.

In Ruby 3.4 the env marking moved to imemo.c; in 3.3 it is still in gc.c (gc_mark_imemo), so the second patch applies the same change there.

See gitlab#634879 (closed) for the full analysis and measurements.

Edited by Stan Hu

Merge request reports

Loading
Loading