| 77 |
77 |
#ifndef GC_MALLOC_LIMIT
|
| 78 |
78 |
#define GC_MALLOC_LIMIT 8000000
|
| 79 |
79 |
#endif
|
|
80 |
#define HEAP_MIN_SLOTS 10000
|
|
81 |
#define FREE_MIN 4096
|
|
82 |
|
|
83 |
static unsigned int initial_malloc_limit = GC_MALLOC_LIMIT;
|
|
84 |
static unsigned int initial_heap_min_slots = HEAP_MIN_SLOTS;
|
|
85 |
static unsigned int initial_free_min = FREE_MIN;
|
|
86 |
|
|
87 |
static void set_gc_parameters()
|
|
88 |
{
|
|
89 |
char *malloc_limit_ptr, *heap_min_slots_ptr, *free_min_ptr;
|
|
90 |
|
|
91 |
malloc_limit_ptr = getenv("RUBY_GC_MALLOC_LIMIT");
|
|
92 |
if ( malloc_limit_ptr != NULL ) {
|
|
93 |
int malloc_limit_i = atoi(malloc_limit_ptr);
|
|
94 |
if ( malloc_limit_i > 0 ) {
|
|
95 |
initial_malloc_limit = malloc_limit_i;
|
|
96 |
}
|
|
97 |
}
|
|
98 |
|
|
99 |
heap_min_slots_ptr = getenv("RUBY_HEAP_MIN_SLOTS");
|
|
100 |
if ( heap_min_slots_ptr != NULL ) {
|
|
101 |
int heap_min_slots_i = atoi(heap_min_slots_ptr);
|
|
102 |
if ( heap_min_slots_i > 0 ) {
|
|
103 |
initial_heap_min_slots = heap_min_slots_i;
|
|
104 |
}
|
|
105 |
}
|
|
106 |
|
|
107 |
free_min_ptr = getenv("RUBY_FREE_MIN");
|
|
108 |
if ( free_min_ptr != NULL ) {
|
|
109 |
int free_min_i = atoi(free_min_ptr);
|
|
110 |
if ( free_min_i > 0 ) {
|
|
111 |
initial_free_min = free_min_i;
|
|
112 |
}
|
|
113 |
}
|
|
114 |
}
|
| 80 |
115 |
|
| 81 |
116 |
#define nomem_error GET_VM()->special_exceptions[ruby_error_nomemory]
|
| 82 |
117 |
|
| ... | ... | |
| 283 |
318 |
int finalize_flag;
|
| 284 |
319 |
};
|
| 285 |
320 |
|
| 286 |
|
#define HEAP_MIN_SLOTS 10000
|
| 287 |
|
#define FREE_MIN 4096
|
| 288 |
|
|
| 289 |
321 |
struct gc_list {
|
| 290 |
322 |
VALUE *varptr;
|
| 291 |
323 |
struct gc_list *next;
|
| ... | ... | |
| 341 |
373 |
static int ruby_initial_gc_stress = 0;
|
| 342 |
374 |
int *ruby_initial_gc_stress_ptr = &ruby_initial_gc_stress;
|
| 343 |
375 |
#else
|
| 344 |
|
static rb_objspace_t rb_objspace = {{GC_MALLOC_LIMIT}, {HEAP_MIN_SLOTS}};
|
|
376 |
static rb_objspace_t rb_objspace = {{initial_malloc_limit}, {initial_heap_min_slots}};
|
| 345 |
377 |
int *ruby_initial_gc_stress_ptr = &rb_objspace.gc_stress;
|
| 346 |
378 |
#endif
|
| 347 |
379 |
#define malloc_limit objspace->malloc_params.limit
|
| ... | ... | |
| 375 |
407 |
{
|
| 376 |
408 |
rb_objspace_t *objspace = malloc(sizeof(rb_objspace_t));
|
| 377 |
409 |
memset(objspace, 0, sizeof(*objspace));
|
| 378 |
|
malloc_limit = GC_MALLOC_LIMIT;
|
|
410 |
malloc_limit = initial_malloc_limit;
|
| 379 |
411 |
ruby_gc_stress = ruby_initial_gc_stress;
|
| 380 |
412 |
|
| 381 |
413 |
return objspace;
|
| ... | ... | |
| 958 |
990 |
{
|
| 959 |
991 |
size_t add, i;
|
| 960 |
992 |
|
| 961 |
|
add = HEAP_MIN_SLOTS / HEAP_OBJ_LIMIT;
|
|
993 |
add = initial_heap_min_slots / HEAP_OBJ_LIMIT;
|
| 962 |
994 |
|
| 963 |
995 |
if (!add) {
|
| 964 |
996 |
add = 1;
|
| ... | ... | |
| 1862 |
1894 |
do_heap_free = (size_t)((heaps_used * HEAP_OBJ_LIMIT) * 0.65);
|
| 1863 |
1895 |
free_min = (size_t)((heaps_used * HEAP_OBJ_LIMIT) * 0.2);
|
| 1864 |
1896 |
|
| 1865 |
|
if (free_min < FREE_MIN) {
|
|
1897 |
if (free_min < initial_free_min) {
|
| 1866 |
1898 |
do_heap_free = heaps_used * HEAP_OBJ_LIMIT;
|
| 1867 |
|
free_min = FREE_MIN;
|
|
1899 |
free_min = initial_free_min;
|
| 1868 |
1900 |
}
|
| 1869 |
1901 |
|
| 1870 |
1902 |
freelist = 0;
|
| ... | ... | |
| 1926 |
1958 |
GC_PROF_SET_MALLOC_INFO;
|
| 1927 |
1959 |
if (malloc_increase > malloc_limit) {
|
| 1928 |
1960 |
malloc_limit += (size_t)((malloc_increase - malloc_limit) * (double)live / (live + freed));
|
| 1929 |
|
if (malloc_limit < GC_MALLOC_LIMIT) malloc_limit = GC_MALLOC_LIMIT;
|
|
1961 |
if (malloc_limit < initial_malloc_limit) malloc_limit = initial_malloc_limit;
|
| 1930 |
1962 |
}
|
| 1931 |
1963 |
malloc_increase = 0;
|
| 1932 |
1964 |
if (freed < free_min) {
|
| ... | ... | |
| 2298 |
2330 |
void
|
| 2299 |
2331 |
Init_heap(void)
|
| 2300 |
2332 |
{
|
|
2333 |
set_gc_parameters();
|
| 2301 |
2334 |
init_heap(&rb_objspace);
|
| 2302 |
2335 |
}
|
| 2303 |
2336 |
|