Forum: Ruby-core [Ruby 1.8 - Bug #216] (Open) Memory leaks in 1.8.6p230 and p238

Posted by Igal Koshevoy (Guest)
on 2008-07-03 00:33
(Received via mailing list)
Issue #216 has been reported by Igal Koshevoy.

----------------------------------------
Bug #216: Memory leaks in 1.8.6p230 and p238
http://redmine.ruby-lang.org/issues/show/216

Author: Igal Koshevoy
Status: Open
Priority: Urgent
Assigned to:
Category:
Target version:


WARNING: Do not use Ruby 1.8.6 releases p230 through p238 in production! 
There are bugs in the Ruby interpreter that cause it leak memory. Please 
use a Ruby release that's based on a patched version of the p111 or p114 
code until this is resolved.

I've put together code which demonstrates this at: 
http://pastie.org/226715

-igal
Posted by Rolando Abarca (Guest)
on 2008-07-03 16:39
(Received via mailing list)
Issue #216 has been updated by Rolando Abarca.


do you have a more specific test?
----------------------------------------
http://redmine.ruby-lang.org/issues/show/216
Posted by Igal Koshevoy (Guest)
on 2008-07-03 16:54
(Received via mailing list)
Issue #216 has been updated by Igal Koshevoy.


Rolando Abarca: No, my test merely proves that a memory leak exists, but 
doesn't identify where. If you or someone else has time to try to build 
a more specific test, it'd be much appreciated because it'll be much 
easier for the developers to identify the actual cause of the memory 
leak and address it.
----------------------------------------
http://redmine.ruby-lang.org/issues/show/216
Posted by Anonymous (Guest)
on 2008-07-03 23:07
(Received via mailing list)
Issue #216 has been updated by Anonymous.


For what it's worth:

I seem to be experiencing the memory leak in p256 as well:

ruby 1.8.6 (2008-06-30 patchlevel 256) [i686-linux]

I don't know much about it yet, but I'm seeing the leak in two
completely different long-running processes, neither of which
is based on anything Rails-related.  (One is a server running
nitro/og/webrick, the other is a home-grown game admin system.)

Regards,

Bill

----------------------------------------
http://redmine.ruby-lang.org/issues/show/216
Posted by Anonymous (Guest)
on 2008-07-03 23:32
(Received via mailing list)
Issue #216 has been updated by Anonymous.


I can also confirm memory leaks running a bunch of different ruby code 
including rails, merb and various daemons.

-Ezra
----------------------------------------
http://redmine.ruby-lang.org/issues/show/216
Posted by Rolando Abarca (Guest)
on 2008-07-04 22:46
(Received via mailing list)
Issue #216 has been updated by Rolando Abarca.


Here are some other tests, and here are my results. VmSize is displayed 
before and after running the main loop (check the test files).
Test files are here: http://pastie.org/227949
test04.rb is the only one not leaking.

rolando@dev02:~/sandbox/ruby_memory_test$ ruby run_tests.rb
test01.rb
ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-linux]
VmSize:      3108 kB
VmSize:      3240 kB
ruby 1.8.6 (2008-07-03 patchlevel 265) [i686-linux]
VmSize:      3116 kB
VmSize:     96968 kB
====
test02.rb
ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-linux]
VmSize:      2972 kB
VmSize:      3104 kB
ruby 1.8.6 (2008-07-03 patchlevel 265) [i686-linux]
VmSize:      2984 kB
VmSize:    115580 kB
====
test03.rb
ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-linux]
VmSize:      2972 kB
VmSize:      3104 kB
ruby 1.8.6 (2008-07-03 patchlevel 265) [i686-linux]
VmSize:      2984 kB
VmSize:    115580 kB
====
test04.rb
ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-linux]
VmSize:      2976 kB
VmSize:      2976 kB
ruby 1.8.6 (2008-07-03 patchlevel 265) [i686-linux]
VmSize:      2984 kB
VmSize:      2984 kB

regards,
rolando./
----------------------------------------
http://redmine.ruby-lang.org/issues/show/216
Posted by Igal Koshevoy (Guest)
on 2008-07-05 01:57
(Received via mailing list)
Issue #216 has been updated by Igal Koshevoy.


Rolando Abarca,

Excellent work, your sample code clearly demonstrates the memory leak 
and narrows its location. I can confirm that p238 and p265 leak memory 
on the first three tests, while p111ubuntu is fine.

I've played with this further and provided a broader series of Regexp 
related methods that are affected: http://pastie.org/228006

-igal
----------------------------------------
http://redmine.ruby-lang.org/issues/show/216
Posted by Yukihiro Matsumoto (Guest)
on 2008-07-05 08:50
(Received via mailing list)
Hi,

In message "Re: [ruby-core:17608] [Ruby 1.8 - Bug #216] Memory leaks in 
1.8.6p230 and p238"
    on Sat, 5 Jul 2008 08:53:17 +0900, Igal Koshevoy 
<redmine@ruby-lang.org> writes:

|Excellent work, your sample code clearly demonstrates the memory leak and narrows its location. I can confirm that p238 and p265 leak memory on the first three tests, while p111ubuntu is fine.

The following patch from ruby_1_8 should fix the leak.  Could you try?

              matz.
Index: re.c
===================================================================
--- re.c  (revision 16437)
+++ re.c  (revision 16438)
@@ -927,6 +927,7 @@
     }

     if (result < 0) {
+  re_free_registers(&regs);
   rb_backref_set(Qnil);
   return result;
     }
@@ -943,6 +944,7 @@
     }

     re_copy_registers(RMATCH(match)->regs, &regs);
+    re_free_registers(&regs);
     RMATCH(match)->str = rb_str_new4(str);
     rb_backref_set(match);
Posted by Igal Koshevoy (Guest)
on 2008-07-05 19:24
(Received via mailing list)
Issue #216 has been updated by Igal Koshevoy.


Good news, I think the memory leak problem is fixed.

I've applied Matz's re.c patch to my copy of p265 (head of ruby_1_8_6) 
and ran it against (1) my earlier test which used a complete Rails 
stack, (2) Rolando Abarca's contributed tests, and (3) my later tests 
for String/Regexp. Memory usage for all these is now stable.

Matz, thank you so much for resolving this. And thank you Rolando for 
contributing the specific test case that helped isolate the leak.

-igal
----------------------------------------
http://redmine.ruby-lang.org/issues/show/216
Posted by Rolando Abarca (Guest)
on 2008-07-05 21:19
(Received via mailing list)
Hi,

On Jul 5, 2008, at 2:46 AM, Yukihiro Matsumoto wrote:

> The following patch from ruby_1_8 should fix the leak.  Could you try?
>
>               matz.

yes, it works fine :-)
Here are the results from my tests:

test01.rb
ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-linux]
VmSize:      3108 kB
VmSize:      3240 kB
ruby 1.8.6 (2008-07-03 patchlevel 265) [i686-linux]
VmSize:      3116 kB
VmSize:      3248 kB
====
test02.rb
ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-linux]
VmSize:      2972 kB
VmSize:      3104 kB
ruby 1.8.6 (2008-07-03 patchlevel 265) [i686-linux]
VmSize:      2988 kB
VmSize:      3120 kB
====
test03.rb
ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-linux]
VmSize:      2972 kB
VmSize:      3104 kB
ruby 1.8.6 (2008-07-03 patchlevel 265) [i686-linux]
VmSize:      2984 kB
VmSize:      3116 kB
====
test04.rb
ruby 1.8.6 (2007-09-24 patchlevel 111) [i686-linux]
VmSize:      2976 kB
VmSize:      2976 kB
ruby 1.8.6 (2008-07-03 patchlevel 265) [i686-linux]
VmSize:      2988 kB
VmSize:      2988 kB

meaning HEAD from ruby_1_8_6 does not leak after applying your patch.
thanks!
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.