Project

General

Profile

Actions

Bug #9687

closed

Make a cap for malloc_limit adjustment

Added by ko1 (Koichi Sasada) over 10 years ago. Updated over 10 years ago.

Status:
Closed
Target version:
ruby -v:
2.2
[ruby-dev:48074]

Description

The blog post [Ruby Garbage Collection: Still Not Ready for Production] (http://www.omniref.com/blog/blog/2014/03/27/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.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0