From 7ec73b9ccdeaed30e813884f7765281be422bc21 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 20 Aug 2022 21:35:22 +0000 Subject: support Ruby 3.0.x HEAP_PAGE_SIZE no longer estimates malloc overhead in Ruby 3.0.x, but we can now rely on the GC::INTERNAL_CONSTANTS hash to access the true value. We also need to account for Ractors in 3.0+, and thus we need to rely on thread-specific `ruby_current_ec' instead of process-wide `ruby_current_execution_context_ptr' (which no longer exists in 3.0+). Finally, the VM seems prone to making some small immortal allocations in a few places we were not expecting in 2.7 and earlier. Account for that and loosen some exact checks to account for it. Tested on Ruby 3.0.3 and 3.0.4 --- test/test_mwrap.rb | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'test/test_mwrap.rb') diff --git a/test/test_mwrap.rb b/test/test_mwrap.rb index 48fba23..fadaef6 100644 --- a/test/test_mwrap.rb +++ b/test/test_mwrap.rb @@ -29,7 +29,8 @@ class TestMwrap < Test::Unit::TestCase tmp.rewind lines = tmp.readlines line_1 = lines.grep(/\s-e:1\b/)[0].strip - assert_equal '10001', line_1.split(/\s+/)[0] + bytes = line_1.split(/\s+/)[0].to_i + assert_operator bytes, :>=, 10001 end end @@ -42,7 +43,7 @@ class TestMwrap < Test::Unit::TestCase res = system(env, *cmd, { 5 => tmp }) assert res, $?.inspect tmp.rewind - assert_match(/\b10001\s+1\s+-e:1$/, tmp.read) + assert_match(/\b1\d{4}\s+[1-9]\d*\s+-e:1$/, tmp.read) env['MWRAP'] = 'dump_fd:1,dump_min:10000' tmp.rewind @@ -50,14 +51,14 @@ class TestMwrap < Test::Unit::TestCase res = system(env, *cmd, { 1 => tmp }) assert res, $?.inspect tmp.rewind - assert_match(/\b10001\s+1\s+-e:1$/, tmp.read) + assert_match(/\b1\d{4}\s+[1-9]\d*\s+-e:1$/, tmp.read) tmp.rewind tmp.truncate(0) env['MWRAP'] = "dump_path:#{tmp.path},dump_min:10000" res = system(env, *cmd) assert res, $?.inspect - assert_match(/\b10001\s+1\s+-e:1$/, tmp.read) + assert_match(/\b1\d{4}\s+[1-9]\d*\s+-e:1$/, tmp.read) tmp.rewind tmp.truncate(0) @@ -98,7 +99,7 @@ class TestMwrap < Test::Unit::TestCase tmp.rewind buf = tmp.read assert_not_match(/\s+-e:1$/, buf) - assert_match(/\b20001\s+1\s+-e:3$/, buf) + assert_match(/\b2\d{4}\s+[0-9]\d*\s+-e:3$/, buf) end end @@ -176,8 +177,8 @@ class TestMwrap < Test::Unit::TestCase -e GC.disable -e keep=("0"*10000) -e loc=Mwrap["-e:3"] - -e loc.each{|size,gen|p([size,gen,count])} - ) + -e + ) + [ 'loc.each{|size,gen|p([size,gen,count]) if size > 10000}' ] buf = IO.popen(@@env, cmd, &:read) assert_predicate $?, :success? assert_match(/\A\[\s*\d+,\s*\d+,\s*\d+\]\s*\z/s, buf) @@ -230,7 +231,8 @@ class TestMwrap < Test::Unit::TestCase loc.name == k or abort 'SourceLocation#name broken' loc.total >= 10000 or abort 'SourceLocation#total broken' loc.frees == 0 or abort 'SourceLocation#frees broken' - loc.allocations == 1 or abort 'SourceLocation#allocations broken' + loc.allocations >= 1 or + abort "SourceLocation#allocations broken: #{loc.allocations}" seen = false loc.each do |*x| seen = x end seen[1] == loc.total or 'SourceLocation#each broken' @@ -240,7 +242,9 @@ class TestMwrap < Test::Unit::TestCase freed = false until freed freed = true - loc.each do freed = false end + loc.each do |size, gen| + freed = false if size >= 10000 + end end loc.frees == 1 or abort 'SourceLocation#frees broken (after free)' Float === loc.mean_lifespan or abort 'mean_lifespan broken' @@ -264,8 +268,9 @@ class TestMwrap < Test::Unit::TestCase assert_separately(+"#{<<~"begin;"}\n#{<<~'end;'}") begin; require 'mwrap' - before = __LINE__ + before = nil res = Mwrap.quiet do |depth| + before = __LINE__ depth == 1 or abort 'depth is not 1' ('a' * 10000).clear Mwrap.quiet { |d| d == 2 or abort 'depth is not 2' } @@ -304,7 +309,7 @@ class TestMwrap < Test::Unit::TestCase gen <= GC.count && gen >= 0 or abort "bad generation: #{gen}" (0 == (addr & 16383)) or abort "addr not aligned: #{'%x' % addr}" end - nr == ap or abort 'HeapPageBody.each missed page' + nr == ap or abort "HeapPageBody.each missed page #{nr} != #{ap}" 10.times { (1..20000).to_a.map(&:to_s) } 3.times { GC.start } Mwrap::HeapPageBody.stat(h) -- cgit v1.2.3-24-ge0c7 From aa82056594757a75aa0f0b629a8b4612f523c5b0 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 20 Aug 2022 21:35:23 +0000 Subject: disable HeapPageBody count test for Ruby 3.1 Ruby 3.1+ uses mmap on platforms relevant to us, so we currently can't account for it with various malloc wrappers. Tested on Ruby 3.1.2, this is the only change necessary to support 3.1.x so far; but the functionality is gone unless we decide to wrap mmap, as well. --- test/test_mwrap.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'test/test_mwrap.rb') diff --git a/test/test_mwrap.rb b/test/test_mwrap.rb index fadaef6..c506554 100644 --- a/test/test_mwrap.rb +++ b/test/test_mwrap.rb @@ -309,7 +309,9 @@ class TestMwrap < Test::Unit::TestCase gen <= GC.count && gen >= 0 or abort "bad generation: #{gen}" (0 == (addr & 16383)) or abort "addr not aligned: #{'%x' % addr}" end - nr == ap or abort "HeapPageBody.each missed page #{nr} != #{ap}" + if RUBY_VERSION.to_f < 3.1 # 3.1+ uses mmap on platforms we care about + nr == ap or abort "HeapPageBody.each missed page #{nr} != #{ap}" + end 10.times { (1..20000).to_a.map(&:to_s) } 3.times { GC.start } Mwrap::HeapPageBody.stat(h) -- cgit v1.2.3-24-ge0c7 From 61f9d94e11e046094c607bdf56c9633938e074b2 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 22 Aug 2022 17:17:57 +0000 Subject: various doc updates Copyright years are unnecessary churn and probably aren't necessary: https://www.linuxfoundation.org/blog/copyright-notices-in-open-source-software-projects/ add POP3 and IMAP archive info, and drop the outdated link to the live demo since I no longer have the resources to run it. Finally, add rdoc (olddoc) + rsync support --- test/test_mwrap.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/test_mwrap.rb') diff --git a/test/test_mwrap.rb b/test/test_mwrap.rb index c506554..eaa65cb 100644 --- a/test/test_mwrap.rb +++ b/test/test_mwrap.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -# Copyright (C) 2018 mwrap hackers +# Copyright (C) mwrap hackers # License: GPL-2.0+ require 'test/unit' require 'mwrap' -- cgit v1.2.3-24-ge0c7 From a03b72e85011b71e031447b9c8c917e6f2c08c81 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 7 Jan 2023 21:51:14 +0000 Subject: drop heap page support for Ruby <= 3.0 Ruby 3.1 uses mmap, nowadays, and I don't think it's worth the effort to suport it since mmap and munmap don't require the symmetry *memalign + free do. --- test/test_mwrap.rb | 38 -------------------------------------- 1 file changed, 38 deletions(-) (limited to 'test/test_mwrap.rb') diff --git a/test/test_mwrap.rb b/test/test_mwrap.rb index eaa65cb..6522167 100644 --- a/test/test_mwrap.rb +++ b/test/test_mwrap.rb @@ -59,13 +59,6 @@ class TestMwrap < Test::Unit::TestCase res = system(env, *cmd) assert res, $?.inspect assert_match(/\b1\d{4}\s+[1-9]\d*\s+-e:1$/, tmp.read) - - tmp.rewind - tmp.truncate(0) - env['MWRAP'] = "dump_path:#{tmp.path},dump_heap:5" - res = system(env, *cmd) - assert res, $?.inspect - assert_match %r{lifespan_stddev}, tmp.read end end @@ -295,35 +288,4 @@ class TestMwrap < Test::Unit::TestCase abort 'freed more than allocated' end; end - - def test_heap_page_body - assert_separately(+"#{<<~"begin;"}\n#{<<~'end;'}") - begin; - require 'mwrap' - require 'rubygems' # use up some memory - ap = GC.stat(:heap_allocated_pages) - h = {} - nr = 0 - Mwrap::HeapPageBody.each do |addr, gen| - nr += 1 - gen <= GC.count && gen >= 0 or abort "bad generation: #{gen}" - (0 == (addr & 16383)) or abort "addr not aligned: #{'%x' % addr}" - end - if RUBY_VERSION.to_f < 3.1 # 3.1+ uses mmap on platforms we care about - nr == ap or abort "HeapPageBody.each missed page #{nr} != #{ap}" - end - 10.times { (1..20000).to_a.map(&:to_s) } - 3.times { GC.start } - Mwrap::HeapPageBody.stat(h) - Integer === h[:lifespan_max] or abort 'lifespan_max not recorded' - Integer === h[:lifespan_min] or abort 'lifespan_min not recorded' - Float === h[:lifespan_mean] or abort 'lifespan_mean not recorded' - 3.times { GC.start } - 10.times { (1..20000).to_a.map(&:to_s) } - Mwrap::HeapPageBody.stat(h) - h[:deathspan_min] <= h[:deathspan_max] or - abort 'wrong min/max deathtime' - Float === h[:deathspan_mean] or abort 'deathspan_mean not recorded' - end; - end end -- cgit v1.2.3-24-ge0c7