[前][次][番号順一覧][スレッド一覧]

ruby-changes:31330

From: tmm1 <ko1@a...>
Date: Thu, 24 Oct 2013 07:47:36 +0900 (JST)
Subject: [ruby-changes:31330] tmm1:r43409 (trunk): * gc.c: add new initial_growth_max tuning parameter. [Bug #9035]

tmm1	2013-10-24 07:47:29 +0900 (Thu, 24 Oct 2013)

  New Revision: 43409

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43409

  Log:
    * gc.c: add new initial_growth_max tuning parameter.  [ruby-core:57928] [Bug #9035]

  Modified files:
    trunk/ChangeLog
    trunk/gc.c
    trunk/test/ruby/test_gc.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43408)
+++ ChangeLog	(revision 43409)
@@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Oct 24 07:41:42 2013  Aman Gupta <ruby@t...>
+
+	* gc.c: add new initial_growth_max tuning parameter.
+	  [ruby-core:57928] [Bug #9035]
+	* gc.c (heap_set_increment): when initial_growth_max is set,
+	  do not grow number of slots by more than growth_max at a time.
+	* gc.c (rb_gc_set_params): load optional new tuning value from
+	  RUBY_HEAP_SLOTS_GROWTH_MAX environment variable.
+	* test/ruby/test_gc.rb (class TestGc): test for above.
+
 Thu Oct 24 01:34:12 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* include/ruby/win32.h (rb_infinity_float): suppress overflow in
Index: gc.c
===================================================================
--- gc.c	(revision 43408)
+++ gc.c	(revision 43409)
@@ -86,6 +86,9 @@ rb_gc_guarded_ptr(volatile VALUE *ptr) https://github.com/ruby/ruby/blob/trunk/gc.c#L86
 #ifndef GC_HEAP_GROWTH_FACTOR
 #define GC_HEAP_GROWTH_FACTOR 1.8
 #endif
+#ifndef GC_HEAP_GROWTH_MAX
+#define GC_HEAP_GROWTH_MAX 0 /* 0 is disable */
+#endif
 #ifndef GC_MALLOC_LIMIT
 #define GC_MALLOC_LIMIT (8 /* 8 MB */ * 1024 * 1024 /* 1MB */)
 #endif
@@ -100,6 +103,7 @@ typedef struct { https://github.com/ruby/ruby/blob/trunk/gc.c#L103
     unsigned int initial_heap_min_slots;
     unsigned int initial_heap_min_free_slots;
     double initial_growth_factor;
+    unsigned int initial_growth_max;
     unsigned int initial_malloc_limit;
     unsigned int initial_malloc_limit_max;
     double initial_malloc_limit_growth_factor;
@@ -112,6 +116,7 @@ static ruby_gc_params_t initial_params = https://github.com/ruby/ruby/blob/trunk/gc.c#L116
     GC_HEAP_MIN_SLOTS,
     GC_HEAP_MIN_FREE_SLOTS,
     GC_HEAP_GROWTH_FACTOR,
+    GC_HEAP_GROWTH_MAX,
     GC_MALLOC_LIMIT,
     GC_MALLOC_LIMIT_MAX,
     GC_MALLOC_LIMIT_GROWTH_FACTOR,
@@ -536,6 +541,7 @@ VALUE *ruby_initial_gc_stress_ptr = &rb_ https://github.com/ruby/ruby/blob/trunk/gc.c#L541
 #define initial_heap_min_slots	           initial_params.initial_heap_min_slots
 #define initial_heap_min_free_slots	   initial_params.initial_heap_min_free_slots
 #define initial_growth_factor	           initial_params.initial_growth_factor
+#define initial_growth_max	           initial_params.initial_growth_max
 
 #define is_lazy_sweeping(heap) ((heap)->sweep_pages != 0)
 #if SIZEOF_LONG == SIZEOF_VOIDP
@@ -994,6 +1000,10 @@ heap_set_increment(rb_objspace_t *objspa https://github.com/ruby/ruby/blob/trunk/gc.c#L1000
 {
     size_t used = heap_pages_used - heap_tomb->used;
     size_t next_used_limit = (size_t)(used * initial_growth_factor);
+    if (initial_growth_max > 0) {
+	size_t max_used_limit = (size_t)(used + initial_growth_max/HEAP_OBJ_LIMIT);
+	if (next_used_limit > max_used_limit) next_used_limit = max_used_limit;
+    }
     if (next_used_limit == heap_pages_used) next_used_limit++;
     heap_pages_increment = next_used_limit - used;
     heap_pages_expand_sorted(objspace);
@@ -4813,6 +4823,7 @@ rb_gc_set_params(void) https://github.com/ruby/ruby/blob/trunk/gc.c#L4823
     get_envparam_int   ("RUBY_FREE_MIN", &initial_heap_min_free_slots, 0);
 
     get_envparam_double("RUBY_HEAP_SLOTS_GROWTH_FACTOR", &initial_growth_factor, 1.0);
+    get_envparam_int   ("RUBY_HEAP_SLOTS_GROWTH_MAX", &initial_growth_max, 0);
     if (get_envparam_int("RUBY_HEAP_MIN_SLOTS", &initial_heap_min_slots, 0)) {
 	size_t min_size;
 	rb_objspace_t *objspace = &rb_objspace;
Index: test/ruby/test_gc.rb
===================================================================
--- test/ruby/test_gc.rb	(revision 43408)
+++ test/ruby/test_gc.rb	(revision 43409)
@@ -123,10 +123,12 @@ class TestGc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_gc.rb#L123
     assert_in_out_err([env, "-w", "-e", "exit"], "", [], /HEAP_MIN_SLOTS=100000/, "[ruby-core:39795]")
 
     env = {
-      "RUBY_HEAP_SLOTS_GROWTH_FACTOR" => "2.0"
+      "RUBY_HEAP_SLOTS_GROWTH_FACTOR" => "2.0",
+      "RUBY_HEAP_SLOTS_GROWTH_MAX" => "10000"
     }
     assert_normal_exit("exit", "", :child_env => env)
     assert_in_out_err([env, "-w", "-e", "exit"], "", [], /HEAP_SLOTS_GROWTH_FACTOR=2.0/, "")
+    assert_in_out_err([env, "-w", "-e", "exit"], "", [], /HEAP_SLOTS_GROWTH_MAX=10000/, "[ruby-core:57928]")
 
     env = {
       "RUBY_GC_MALLOC_LIMIT"               => "60000000",

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]