Skip to content

Commit 0af103b

Browse files
committed
merge revision(s) 45021,45022,45028: [Backport ruby#9524]
* gc.c: introduce new environment variable "RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR" to control major/minor GC frequency. Do full GC when the number of old objects is more than R * N where R is this factor and * test/ruby/test_gc.rb: add a test. * gc.c (get_envparam_double): fix a warning message. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@45044 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 7eaa356 commit 0af103b

4 files changed

Lines changed: 48 additions & 5 deletions

File tree

ChangeLog

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
Wed Feb 19 14:25:55 2014 Koichi Sasada <ko1@atdot.net>
2+
3+
* test/ruby/test_gc.rb: ignore warning messages for running with -w
4+
option such as chkbuild.
5+
6+
Wed Feb 19 14:25:55 2014 Koichi Sasada <ko1@atdot.net>
7+
8+
* gc.c (get_envparam_double): fix a warning message.
9+
10+
Wed Feb 19 14:25:55 2014 Koichi Sasada <ko1@atdot.net>
11+
12+
* gc.c: introduce new environment variable
13+
"RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR" to control major/minor GC
14+
frequency.
15+
16+
Do full GC when the number of old objects is more than R * N
17+
where R is this factor and
18+
N is the number of old objects just after last full GC.
19+
20+
* test/ruby/test_gc.rb: add a test.
21+
122
Wed Feb 19 07:51:02 2014 Eric Hodel <drbrain@segment7.net>
223

324
* lib/rinda/ring.rb (Rinda::RingFinger#make_socket): Use

gc.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ rb_gc_guarded_ptr(volatile VALUE *ptr)
108108
#ifndef GC_HEAP_GROWTH_MAX_SLOTS
109109
#define GC_HEAP_GROWTH_MAX_SLOTS 0 /* 0 is disable */
110110
#endif
111+
#ifndef GC_HEAP_OLDOBJECT_LIMIT_FACTOR
112+
#define GC_HEAP_OLDOBJECT_LIMIT_FACTOR 2.0
113+
#endif
111114

112115
#ifndef GC_MALLOC_LIMIT_MIN
113116
#define GC_MALLOC_LIMIT_MIN (16 * 1024 * 1024 /* 16MB */)
@@ -134,6 +137,7 @@ typedef struct {
134137
unsigned int heap_free_slots;
135138
double growth_factor;
136139
unsigned int growth_max_slots;
140+
double oldobject_limit_factor;
137141
unsigned int malloc_limit_min;
138142
unsigned int malloc_limit_max;
139143
double malloc_limit_growth_factor;
@@ -150,6 +154,7 @@ static ruby_gc_params_t gc_params = {
150154
GC_HEAP_INIT_SLOTS,
151155
GC_HEAP_GROWTH_FACTOR,
152156
GC_HEAP_GROWTH_MAX_SLOTS,
157+
GC_HEAP_OLDOBJECT_LIMIT_FACTOR,
153158
GC_MALLOC_LIMIT_MIN,
154159
GC_MALLOC_LIMIT_MAX,
155160
GC_MALLOC_LIMIT_GROWTH_FACTOR,
@@ -4498,10 +4503,12 @@ gc_marks(rb_objspace_t *objspace, int full_mark)
44984503
#endif
44994504

45004505
gc_marks_body(objspace, TRUE);
4501-
4502-
/* Do full GC if old/remembered_shady object counts is greater than counts two times at last full GC counts */
4503-
objspace->rgengc.remembered_shady_object_limit = objspace->rgengc.remembered_shady_object_count * 2;
4504-
objspace->rgengc.old_object_limit = objspace->rgengc.old_object_count * 2;
4506+
{
4507+
/* See the comment about RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR */
4508+
const double r = gc_params.oldobject_limit_factor;
4509+
objspace->rgengc.remembered_shady_object_limit = objspace->rgengc.remembered_shady_object_count * r;
4510+
objspace->rgengc.old_object_limit = objspace->rgengc.old_object_count * r;
4511+
}
45054512
}
45064513
else { /* minor GC */
45074514
gc_marks_body(objspace, FALSE);
@@ -5706,6 +5713,10 @@ gc_set_initial_pages(void)
57065713
* - (next slots number) = (current slots number) * (this factor)
57075714
* * RUBY_GC_HEAP_GROWTH_MAX_SLOTS (new from 2.1)
57085715
* - Allocation rate is limited to this factor.
5716+
* * RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR (new from 2.1.1)
5717+
* - Do full GC when the number of old objects is more than R * N
5718+
* where R is this factor and
5719+
* N is the number of old objects just after last full GC.
57095720
*
57105721
* * obsolete
57115722
* * RUBY_FREE_MIN -> RUBY_GC_HEAP_FREE_SLOTS (from 2.1)
@@ -5742,6 +5753,7 @@ ruby_gc_set_params(int safe_level)
57425753

57435754
get_envparam_double("RUBY_GC_HEAP_GROWTH_FACTOR", &gc_params.growth_factor, 1.0);
57445755
get_envparam_int ("RUBY_GC_HEAP_GROWTH_MAX_SLOTS", &gc_params.growth_max_slots, 0);
5756+
get_envparam_double("RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR", &gc_params.oldobject_limit_factor, 0.0);
57455757

57465758
get_envparam_int("RUBY_GC_MALLOC_LIMIT", &gc_params.malloc_limit_min, 0);
57475759
get_envparam_int("RUBY_GC_MALLOC_LIMIT_MAX", &gc_params.malloc_limit_max, 0);

test/ruby/test_gc.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,16 @@ def test_gc_parameter
177177
assert_in_out_err([env, "-w", "-e", "exit"], "", [], /RUBY_GC_HEAP_GROWTH_FACTOR=2.0/, "")
178178
assert_in_out_err([env, "-w", "-e", "exit"], "", [], /RUBY_GC_HEAP_GROWTH_MAX_SLOTS=10000/, "[ruby-core:57928]")
179179

180+
env = {
181+
"RUBY_GC_HEAP_INIT_SLOTS" => "100000",
182+
"RUBY_GC_HEAP_FREE_SLOTS" => "10000",
183+
"RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR" => "0.9",
184+
}
185+
assert_normal_exit("exit", "", :child_env => env)
186+
assert_in_out_err([env, "-w", "-e", "exit"], "", [], /RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR=0\.9/, "")
187+
# always full GC when RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR < 1.0
188+
assert_in_out_err([env, "-e", "1000_000.times{Object.new}; p(GC.stat[:minor_gc_count] < GC.stat[:major_gc_count])"], "", ['true'], //, "")
189+
180190
# check obsolete
181191
assert_in_out_err([{'RUBY_FREE_MIN' => '100'}, '-w', '-eexit'], '', [],
182192
/RUBY_FREE_MIN is obsolete. Use RUBY_GC_HEAP_FREE_SLOTS instead/)

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#define RUBY_VERSION "2.1.1"
22
#define RUBY_RELEASE_DATE "2014-02-19"
3-
#define RUBY_PATCHLEVEL 33
3+
#define RUBY_PATCHLEVEL 34
44

55
#define RUBY_RELEASE_YEAR 2014
66
#define RUBY_RELEASE_MONTH 2

0 commit comments

Comments
 (0)