summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--gc.c11
-rw-r--r--test/ruby/test_gc.rb4
3 files changed, 24 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index e0cba8eb81..7d673bbdf7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Thu Oct 24 07:41:42 2013 Aman Gupta <ruby@tmm1.net>
+
+ * 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@ruby-lang.org>
* include/ruby/win32.h (rb_infinity_float): suppress overflow in
diff --git a/gc.c b/gc.c
index 46b13219b5..6091da5632 100644
--- a/gc.c
+++ b/gc.c
@@ -86,6 +86,9 @@ rb_gc_guarded_ptr(volatile VALUE *ptr)
#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 {
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 = {
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_objspace.gc_stress;
#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 *objspace)
{
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)
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;
diff --git a/test/ruby/test_gc.rb b/test/ruby/test_gc.rb
index 30baebb67a..dfe5e31cfb 100644
--- a/test/ruby/test_gc.rb
+++ b/test/ruby/test_gc.rb
@@ -123,10 +123,12 @@ class TestGc < Test::Unit::TestCase
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",