[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-core
Subject:    [ruby-core:70923] [Ruby trunk - Bug #10686] Memory leaking from torture test of symbol GC
From:       Rei.Odaira () gmail ! com
Date:       2015-09-27 5:52:56
Message-ID: redmine.journal-54284.20150927055255.1618c1e70b13168d () ruby-lang ! org
[Download RAW message or body]

Issue #10686 has been updated by Rei Odaira.

File test_symbol.patch added

I would like to propose two changes in `test/ruby/test_symbol.rb \
(TestSymbol#test_symbol_fstr_leak)`.

First, this test checks only the increase in the virtual size, but it should check \
the rss as well. On Mac OS X, the memory leak of the symbols increases the rss, not \
the virtual size. The following example demonstrates the increase in the rss when the \
fix in symbol.c is not applied. Therefore, `test_symbol_fstr_leak` should specify \
"rss: true" as an argument to `assert_no_memory_leak()`.

~~~
$ ruby --disable=gems -I test/lib -r memory_status -e 'p Memory::Status.new; \
200_000.times { |i| i.to_s.to_sym }; GC.start; p Memory::Status.new' #<struct \
Memory::Status size=2505801728, rss=4321280> #<struct Memory::Status size=2563211264, \
rss=47579136> ~~~

The second change I am proposing is to add a warm-up phase before measuring the \
actual memory size increase. On a certain AIX machine, `test_symbol_fstr_leak` causes \
2.6x increase in the virtual size, even after applying the fix in symbol.c.

~~~
$ ruby --disable=gems -I test/lib -r memory_status -e 'p Memory::Status.new; \
200_000.times { |i| i.to_s.to_sym }; GC.start; p Memory::Status.new' #<struct \
Memory::Status size=1646592, rss=4091904> #<struct Memory::Status size=4263936, \
rss=6725632> ~~~

However, I don't think this is a leak, because if you sequentially run a similar test \
twice and only measure the second run, neither the virtual size or the rss increases \
so much, as follows.

~~~
$ ruby --disable=gems -I test/lib -r memory_status -e '200_000.times { |i| \
i.to_s.to_sym }; GC.start; p Memory::Status.new; 200_000.times { |i| \
(i+200_000).to_s.to_sym }; GC.start; p Memory::Status.new' #<struct Memory::Status \
size=4276224, rss=6758400> #<struct Memory::Status size=4321280, rss=6803456>
~~~

Because the warm-up phase inevitably increases memory usage, we should measure the \
steady state after the warm-up phase when detecting a memory leak.

The attached patch includes these two changes. I confirmed my patch on Mac OS X, \
POWER Linux, and AIX.  Without the fix in symbol.c, `test_symbol_fstr_leak` correctly \
fails on every environment, and with the fix in symbol.c, it succeeds.

----------------------------------------
Bug #10686: Memory leaking from torture test of symbol GC
https://bugs.ruby-lang.org/issues/10686#change-54284

* Author: Charles Nutter
* Status: Closed
* Priority: Normal
* Assignee: 
* ruby -v: 2.2p0
* Backport: 2.0.0: DONTNEED, 2.1: DONTNEED, 2.2: DONE
----------------------------------------
The following code appears to grow without bounds when running on MRI 2.2p0 (and \
grows *very* fast...hold on to your RAM):

```ruby
x = 0; loop { (x += 1).to_s.to_sym }
```

I asked ko1 about this on Twitter and he said it appears to be leaking strings \
somewhere.

---Files--------------------------------
test_symbol.patch (610 Bytes)


-- 
https://bugs.ruby-lang.org/


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic