@@ -109,6 +109,9 @@ rb_gc_guarded_ptr(volatile VALUE *ptr)
109109#ifndef GC_HEAP_GROWTH_MAX_SLOTS
110110#define GC_HEAP_GROWTH_MAX_SLOTS 0 /* 0 is disable */
111111#endif
112+ #ifndef GC_HEAP_OLDOBJECT_LIMIT_FACTOR
113+ #define GC_HEAP_OLDOBJECT_LIMIT_FACTOR 2.0
114+ #endif
112115
113116#ifndef GC_MALLOC_LIMIT_MIN
114117#define GC_MALLOC_LIMIT_MIN (16 * 1024 * 1024 /* 16MB */ )
@@ -135,6 +138,7 @@ typedef struct {
135138 unsigned int heap_free_slots ;
136139 double growth_factor ;
137140 unsigned int growth_max_slots ;
141+ double oldobject_limit_factor ;
138142 unsigned int malloc_limit_min ;
139143 unsigned int malloc_limit_max ;
140144 double malloc_limit_growth_factor ;
@@ -151,6 +155,7 @@ static ruby_gc_params_t gc_params = {
151155 GC_HEAP_INIT_SLOTS ,
152156 GC_HEAP_GROWTH_FACTOR ,
153157 GC_HEAP_GROWTH_MAX_SLOTS ,
158+ GC_HEAP_OLDOBJECT_LIMIT_FACTOR ,
154159 GC_MALLOC_LIMIT_MIN ,
155160 GC_MALLOC_LIMIT_MAX ,
156161 GC_MALLOC_LIMIT_GROWTH_FACTOR ,
@@ -4536,10 +4541,12 @@ gc_marks(rb_objspace_t *objspace, int full_mark)
45364541#endif
45374542
45384543 gc_marks_body (objspace , TRUE);
4539-
4540- /* Do full GC if old/remembered_shady object counts is greater than counts two times at last full GC counts */
4541- objspace -> rgengc .remembered_shady_object_limit = objspace -> rgengc .remembered_shady_object_count * 2 ;
4542- objspace -> rgengc .old_object_limit = objspace -> rgengc .old_object_count * 2 ;
4544+ {
4545+ /* See the comment about RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR */
4546+ const double r = gc_params .oldobject_limit_factor ;
4547+ objspace -> rgengc .remembered_shady_object_limit = objspace -> rgengc .remembered_shady_object_count * r ;
4548+ objspace -> rgengc .old_object_limit = objspace -> rgengc .old_object_count * r ;
4549+ }
45434550 }
45444551 else { /* minor GC */
45454552 gc_marks_body (objspace , FALSE);
@@ -5744,6 +5751,10 @@ gc_set_initial_pages(void)
57445751 * - (next slots number) = (current slots number) * (this factor)
57455752 * * RUBY_GC_HEAP_GROWTH_MAX_SLOTS (new from 2.1)
57465753 * - Allocation rate is limited to this factor.
5754+ * * RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR (new from 2.1.1)
5755+ * - Do full GC when the number of old objects is more than R * N
5756+ * where R is this factor and
5757+ * N is the number of old objects just after last full GC.
57475758 *
57485759 * * obsolete
57495760 * * RUBY_FREE_MIN -> RUBY_GC_HEAP_FREE_SLOTS (from 2.1)
@@ -5782,6 +5793,7 @@ ruby_gc_set_params(int safe_level)
57825793
57835794 get_envparam_double ("RUBY_GC_HEAP_GROWTH_FACTOR" , & gc_params .growth_factor , 1.0 );
57845795 get_envparam_int ("RUBY_GC_HEAP_GROWTH_MAX_SLOTS" , & gc_params .growth_max_slots , 0 );
5796+ get_envparam_double ("RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR" , & gc_params .oldobject_limit_factor , 0.0 );
57855797
57865798 get_envparam_int ("RUBY_GC_MALLOC_LIMIT" , & gc_params .malloc_limit_min , 0 );
57875799 get_envparam_int ("RUBY_GC_MALLOC_LIMIT_MAX" , & gc_params .malloc_limit_max , 0 );
0 commit comments