Bug #9687

Make a cap for malloc_limit adjustment

Added by Koichi Sasada 11 months ago. Updated 10 months ago.

[ruby-dev:48074]
Status:Closed
Priority:Normal
Assignee:Koichi Sasada
ruby -v:2.2 Backport:2.0.0: DONTNEED, 2.1: DONE

Description

The blog post Ruby Garbage Collection: Still Not Ready for Production pointed out that the following code consumes all of memory:

while true
  "a" * (1024 ** 2)
end

This is because `malloc_limit' grows and grows infinitely.

The following patch will solve this issue.

Index: gc.c
===================================================================
--- gc.c    (revision 45433)
+++ gc.c    (working copy)
@@ -2890,7 +2890,7 @@ gc_before_sweep(rb_objspace_t *objspace)
        malloc_limit = (size_t)(inc * gc_params.malloc_limit_growth_factor);
        if (gc_params.malloc_limit_max > 0 && /* ignore max-check if 0 */
        malloc_limit > gc_params.malloc_limit_max) {
-       malloc_limit = inc;
+       malloc_limit = gc_params.malloc_limit_max;
        }
    }
    else {

Maybe this patch should be applied for 2.1.x series.

Associated revisions

Revision 45468
Added by Koichi Sasada 11 months ago

Revision 45468
Added by Koichi Sasada 11 months ago

Revision 45817
Added by Tomoyuki Chikanaga 10 months ago

merge revision(s) r45468: [Backport #9687]

* gc.c (gc_before_sweep): cap `malloc_limit' to
  gc_params.malloc_limit_max.  It can grow and grow with such case:
    `loop{"a" * (1024 ** 2)}'
  [Bug #9687]
  This issue is pointed by Tim Robertson.
  http://www.omniref.com/blog/blog/2014/03/27/ruby-garbage-collection-still-not-ready-for-production/

History

#1 Updated by Koichi Sasada 11 months ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

Applied in changeset r45468.


#2 Updated by Koichi Sasada 11 months ago

  • Status changed from Closed to Open
  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN to 2.0.0: UNKNOWN, 2.1: REQUIRED

#3 Updated by Tomoyuki Chikanaga 11 months ago

  • Status changed from Open to Closed
  • Backport changed from 2.0.0: UNKNOWN, 2.1: REQUIRED to 2.0.0: REQUIRED, 2.1: REQUIRED

#4 Updated by Tomoyuki Chikanaga 11 months ago

  • Backport changed from 2.0.0: REQUIRED, 2.1: REQUIRED to 2.0.0: DONTNEED, 2.1: REQUIRED

#5 Updated by Tomoyuki Chikanaga 10 months ago

  • Backport changed from 2.0.0: DONTNEED, 2.1: REQUIRED to 2.0.0: DONTNEED, 2.1: DONE

r45468 was backported into ruby_2_1 branch at r45817.

Also available in: Atom PDF