@@ -3279,7 +3279,8 @@ static int _jl_gc_collect(jl_ptls_t ptls, jl_gc_collection_t collection)
3279
3279
if (sweep_full ) {
3280
3280
gc_num .last_full_sweep = gc_end_time ;
3281
3281
}
3282
-
3282
+
3283
+ int thrashing = 0 ; // maybe we should report this to the user or error out?
3283
3284
size_t heap_size = jl_atomic_load_relaxed (& gc_heap_stats .heap_size );
3284
3285
double target_allocs = 0.0 ;
3285
3286
double min_interval = default_collect_interval ;
@@ -3298,17 +3299,18 @@ static int _jl_gc_collect(jl_ptls_t ptls, jl_gc_collection_t collection)
3298
3299
old_freed_diff = freed_diff ;
3299
3300
old_pause_time = pause ;
3300
3301
old_heap_size = heap_size ;
3302
+ thrashing = gc_time > mutator_time * 98 ? 1 : 0 ;
3301
3303
if (alloc_mem != 0 && alloc_time != 0 && gc_mem != 0 && gc_time != 0 ) {
3302
3304
double alloc_rate = alloc_mem /alloc_time ;
3303
3305
double gc_rate = gc_mem /gc_time ;
3304
3306
target_allocs = sqrt (((double )heap_size /min_interval * alloc_rate )/(gc_rate * tuning_factor )); // work on multiples of min interval
3305
3307
}
3306
3308
}
3307
- if (target_allocs == 0.0 )
3309
+ if (target_allocs == 0.0 || thrashing ) // If we are thrashing go back to default
3308
3310
target_allocs = 2 * sqrt ((double )heap_size /min_interval );
3309
3311
3310
3312
uint64_t target_heap = (uint64_t )target_allocs * min_interval + heap_size ;
3311
- if (target_heap > max_total_memory )
3313
+ if (target_heap > max_total_memory && ! thrashing ) // Allow it to go over if we are thrashing if we die we die
3312
3314
target_heap = max_total_memory ;
3313
3315
else if (target_heap < default_collect_interval )
3314
3316
target_heap = default_collect_interval ;
0 commit comments