@@ -653,9 +653,8 @@ static int prev_sweep_full = 1;
653
653
// Full collection heuristics
654
654
static int64_t live_bytes = 0 ;
655
655
static int64_t promoted_bytes = 0 ;
656
- static int64_t last_full_live = 0 ; // live_bytes after last full collection
657
656
static int64_t last_live_bytes = 0 ; // live_bytes at last collection
658
- static int64_t grown_heap_age = 0 ; // # of collects since live_bytes grew and remained
657
+ static int64_t t_start = 0 ; // Time GC starts;
659
658
#ifdef __GLIBC__
660
659
// maxrss at last malloc_trim
661
660
static int64_t last_trim_maxrss = 0 ;
@@ -3140,43 +3139,23 @@ static int _jl_gc_collect(jl_ptls_t ptls, jl_gc_collection_t collection)
3140
3139
int nptr = 0 ;
3141
3140
for (int i = 0 ;i < jl_n_threads ;i ++ )
3142
3141
nptr += jl_all_tls_states [i ]-> heap .remset_nptr ;
3143
- int large_frontier = nptr * sizeof (void * ) >= default_collect_interval ; // many pointers in the intergen frontier => "quick" mark is not quick
3144
- // trigger a full collection if the number of live bytes doubles since the last full
3145
- // collection and then remains at least that high for a while.
3146
- if (grown_heap_age == 0 ) {
3147
- if (live_bytes > 2 * last_full_live )
3148
- grown_heap_age = 1 ;
3149
- }
3150
- else if (live_bytes >= last_live_bytes ) {
3151
- grown_heap_age ++ ;
3152
- }
3142
+
3143
+ // many pointers in the intergen frontier => "quick" mark is not quick
3144
+ int large_frontier = nptr * sizeof (void * ) >= default_collect_interval ;
3153
3145
int sweep_full = 0 ;
3154
3146
int recollect = 0 ;
3155
- if ((large_frontier ||
3156
- ((not_freed_enough || promoted_bytes >= gc_num .interval ) &&
3157
- (promoted_bytes >= default_collect_interval || prev_sweep_full )) ||
3158
- grown_heap_age > 1 ) && gc_num .pause > 1 ) {
3159
- sweep_full = 1 ;
3160
- }
3147
+
3161
3148
// update heuristics only if this GC was automatically triggered
3162
3149
if (collection == JL_GC_AUTO ) {
3163
- if (sweep_full ) {
3164
- if (large_frontier )
3165
- gc_num .interval = last_long_collect_interval ;
3166
- if (not_freed_enough || large_frontier ) {
3167
- if (gc_num .interval <= 2 * (max_collect_interval /5 )) {
3168
- gc_num .interval = 5 * (gc_num .interval / 2 );
3169
- }
3170
- }
3171
- last_long_collect_interval = gc_num .interval ;
3150
+ if (not_freed_enough ) {
3151
+ gc_num .interval = gc_num .interval * 2 ;
3172
3152
}
3173
- else {
3174
- // reset interval to default, or at least half of live_bytes
3175
- int64_t half = live_bytes /2 ;
3176
- if (default_collect_interval < half && half <= max_collect_interval )
3177
- gc_num .interval = half ;
3178
- else
3179
- gc_num .interval = default_collect_interval ;
3153
+ if (large_frontier ) {
3154
+ sweep_full = 1 ;
3155
+ }
3156
+ if (gc_num .interval > max_collect_interval ) {
3157
+ sweep_full = 1 ;
3158
+ gc_num .interval = max_collect_interval ;
3180
3159
}
3181
3160
}
3182
3161
if (gc_sweep_always_full ) {
@@ -3249,10 +3228,17 @@ static int _jl_gc_collect(jl_ptls_t ptls, jl_gc_collection_t collection)
3249
3228
gc_num .allocd = 0 ;
3250
3229
last_live_bytes = live_bytes ;
3251
3230
live_bytes += - gc_num .freed + gc_num .since_sweep ;
3252
- if (prev_sweep_full ) {
3253
- last_full_live = live_bytes ;
3254
- grown_heap_age = 0 ;
3231
+
3232
+ if (collection == JL_GC_AUTO ) {
3233
+ // If the current interval is larger than half the live data decrease the interval
3234
+ int64_t half = live_bytes /2 ;
3235
+ if (gc_num .interval > half ) gc_num .interval = half ;
3236
+ // But never go below default
3237
+ if (gc_num .interval < default_collect_interval ) gc_num .interval = default_collect_interval ;
3255
3238
}
3239
+
3240
+ gc_time_summary (sweep_full , t_start , gc_end_t , gc_num .freed , live_bytes , gc_num .interval , pause );
3241
+
3256
3242
prev_sweep_full = sweep_full ;
3257
3243
gc_num .pause += !recollect ;
3258
3244
gc_num .total_time += pause ;
@@ -3420,6 +3406,7 @@ void jl_gc_init(void)
3420
3406
#endif
3421
3407
jl_gc_mark_sp_t sp = {NULL , NULL , NULL , NULL };
3422
3408
gc_mark_loop (NULL , sp );
3409
+ t_start = jl_hrtime ();
3423
3410
}
3424
3411
3425
3412
// callback for passing OOM errors from gmp
0 commit comments