@@ -1010,7 +1010,6 @@ STATIC_INLINE jl_value_t *jl_gc_big_alloc_inner(jl_ptls_t ptls, size_t sz)
1010
1010
jl_atomic_load_relaxed (& ptls -> gc_num .allocd ) + allocsz );
1011
1011
jl_atomic_store_relaxed (& ptls -> gc_num .bigalloc ,
1012
1012
jl_atomic_load_relaxed (& ptls -> gc_num .bigalloc ) + 1 );
1013
- jl_atomic_fetch_add_relaxed (& gc_heap_stats .bytes_mallocd , allocsz );
1014
1013
jl_atomic_fetch_add_relaxed (& gc_heap_stats .heap_size , allocsz );
1015
1014
#ifdef MEMDEBUG
1016
1015
memset (v , 0xee , allocsz );
@@ -1057,8 +1056,6 @@ static bigval_t **sweep_big_list(int sweep_full, bigval_t **pv) JL_NOTSAFEPOINT
1057
1056
if (nxt )
1058
1057
nxt -> prev = pv ;
1059
1058
gc_num .freed += v -> sz & ~3 ;
1060
- jl_atomic_store_relaxed (& gc_heap_stats .malloc_bytes_freed ,
1061
- jl_atomic_load_relaxed (& gc_heap_stats .malloc_bytes_freed ) + (v -> sz & ~3 ));
1062
1059
jl_atomic_store_relaxed (& gc_heap_stats .heap_size ,
1063
1060
jl_atomic_load_relaxed (& gc_heap_stats .heap_size ) - (v -> sz & ~3 ));
1064
1061
#ifdef MEMDEBUG
@@ -1120,7 +1117,6 @@ void jl_gc_count_allocd(size_t sz) JL_NOTSAFEPOINT
1120
1117
jl_ptls_t ptls = jl_current_task -> ptls ;
1121
1118
jl_atomic_store_relaxed (& ptls -> gc_num .allocd ,
1122
1119
jl_atomic_load_relaxed (& ptls -> gc_num .allocd ) + sz );
1123
- jl_atomic_fetch_add_relaxed (& gc_heap_stats .bytes_mallocd , sz );
1124
1120
jl_atomic_fetch_add_relaxed (& gc_heap_stats .heap_size , sz );
1125
1121
}
1126
1122
@@ -1196,12 +1192,8 @@ static void jl_gc_free_array(jl_array_t *a) JL_NOTSAFEPOINT
1196
1192
jl_free_aligned (d );
1197
1193
else
1198
1194
free (d );
1199
- jl_atomic_store_relaxed (& gc_heap_stats .malloc_bytes_freed ,
1200
- jl_atomic_load_relaxed (& gc_heap_stats .malloc_bytes_freed ) + jl_array_nbytes (a ));
1201
1195
jl_atomic_store_relaxed (& gc_heap_stats .heap_size ,
1202
1196
jl_atomic_load_relaxed (& gc_heap_stats .heap_size ) - jl_array_nbytes (a ));
1203
- jl_atomic_fetch_add_relaxed (& gc_heap_stats .malloc_bytes_freed , jl_array_nbytes (a ));
1204
- jl_atomic_fetch_add_relaxed (& gc_heap_stats .heap_size , - jl_array_nbytes (a ));
1205
1197
gc_num .freed += jl_array_nbytes (a );
1206
1198
gc_num .freecall ++ ;
1207
1199
}
@@ -1273,7 +1265,6 @@ static NOINLINE jl_taggedvalue_t *gc_add_page(jl_gc_pool_t *p) JL_NOTSAFEPOINT
1273
1265
set_page_metadata (pg );
1274
1266
push_page_metadata_back (& ptls -> page_metadata_allocd , pg );
1275
1267
jl_taggedvalue_t * fl = gc_reset_page (ptls , p , pg );
1276
- jl_atomic_fetch_add_relaxed (& gc_heap_stats .bytes_allocd , GC_PAGE_SZ );
1277
1268
jl_atomic_fetch_add_relaxed (& gc_heap_stats .heap_size , GC_PAGE_SZ );
1278
1269
p -> newpages = fl ;
1279
1270
return fl ;
@@ -1468,11 +1459,9 @@ static jl_taggedvalue_t **gc_sweep_page(jl_gc_pool_t *p, jl_gc_pagemeta_t **allo
1468
1459
}
1469
1460
else if (freed_lazily ) {
1470
1461
push_page_metadata_back (lazily_freed , pg );
1471
- jl_atomic_fetch_add_relaxed (& gc_heap_stats .bytes_freed , GC_PAGE_SZ );
1472
1462
jl_atomic_fetch_add_relaxed (& gc_heap_stats .heap_size , - GC_PAGE_SZ );
1473
1463
}
1474
1464
else {
1475
- jl_atomic_fetch_add_relaxed (& gc_heap_stats .bytes_freed , GC_PAGE_SZ );
1476
1465
jl_atomic_fetch_add_relaxed (& gc_heap_stats .heap_size , - GC_PAGE_SZ );
1477
1466
#ifdef _P64 // only enable concurrent sweeping on 64bit
1478
1467
if (jl_n_sweepthreads == 0 ) {
@@ -3279,29 +3268,30 @@ static int _jl_gc_collect(jl_ptls_t ptls, jl_gc_collection_t collection)
3279
3268
}
3280
3269
3281
3270
size_t heap_size = jl_atomic_load_relaxed (& gc_heap_stats .heap_size );
3282
- uint64_t alloc_diff = before_free_heap_size - old_heap_size ;
3283
- uint64_t freed_diff = before_free_heap_size - heap_size ;
3284
-
3285
- double alloc_smooth_factor = 0.95 ;
3286
- double collec_smooth_factor = 0.5 ;
3287
- double tuning_factor = 0.03 ;
3288
- double alloc_mem = jl_gc_smooth (old_alloc_diff , alloc_diff , alloc_smooth_factor );
3289
- double alloc_time = jl_gc_smooth (old_mut_time , mutator_time , alloc_smooth_factor );
3290
- double gc_mem = jl_gc_smooth (old_freed_diff , freed_diff , collec_smooth_factor );
3291
- double gc_time = jl_gc_smooth (old_pause_time , pause , collec_smooth_factor );
3292
- old_alloc_diff = alloc_diff ;
3293
- old_mut_time = mutator_time ;
3294
- old_freed_diff = freed_diff ;
3295
- old_pause_time = pause ;
3296
- old_heap_size = heap_size ;
3271
+ double target_allocs = 0.0 ;
3297
3272
double min_interval = default_collect_interval ;
3298
- double target_allocs ;
3299
- if (alloc_mem != 0 && alloc_time != 0 && gc_mem != 0 && gc_time != 0 ) {
3300
- double alloc_rate = alloc_mem /alloc_time ;
3301
- double gc_rate = gc_mem /gc_time ;
3302
- target_allocs = sqrt (((double )heap_size /min_interval * alloc_rate )/(gc_rate * tuning_factor )); // work on multiples of min interval
3273
+ if (collection == JL_GC_AUTO ) {
3274
+ uint64_t alloc_diff = before_free_heap_size - old_heap_size ;
3275
+ uint64_t freed_diff = before_free_heap_size - heap_size ;
3276
+ double alloc_smooth_factor = 0.95 ;
3277
+ double collect_smooth_factor = 0.5 ;
3278
+ double tuning_factor = 0.03 ;
3279
+ double alloc_mem = jl_gc_smooth (old_alloc_diff , alloc_diff , alloc_smooth_factor );
3280
+ double alloc_time = jl_gc_smooth (old_mut_time , mutator_time , alloc_smooth_factor );
3281
+ double gc_mem = jl_gc_smooth (old_freed_diff , freed_diff , collect_smooth_factor );
3282
+ double gc_time = jl_gc_smooth (old_pause_time , pause , collect_smooth_factor );
3283
+ old_alloc_diff = alloc_diff ;
3284
+ old_mut_time = mutator_time ;
3285
+ old_freed_diff = freed_diff ;
3286
+ old_pause_time = pause ;
3287
+ old_heap_size = heap_size ;
3288
+ if (alloc_mem != 0 && alloc_time != 0 && gc_mem != 0 && gc_time != 0 ) {
3289
+ double alloc_rate = alloc_mem /alloc_time ;
3290
+ double gc_rate = gc_mem /gc_time ;
3291
+ target_allocs = sqrt (((double )heap_size /min_interval * alloc_rate )/(gc_rate * tuning_factor )); // work on multiples of min interval
3292
+ }
3303
3293
}
3304
- else
3294
+ if ( target_allocs == 0.0 )
3305
3295
target_allocs = 2 * sqrt ((double )heap_size /min_interval );
3306
3296
3307
3297
uint64_t target_heap = (uint64_t )target_allocs * min_interval + heap_size ;
@@ -3611,7 +3601,6 @@ JL_DLLEXPORT void *jl_gc_counted_malloc(size_t sz)
3611
3601
jl_atomic_load_relaxed (& ptls -> gc_num .allocd ) + sz );
3612
3602
jl_atomic_store_relaxed (& ptls -> gc_num .malloc ,
3613
3603
jl_atomic_load_relaxed (& ptls -> gc_num .malloc ) + 1 );
3614
- jl_atomic_fetch_add_relaxed (& gc_heap_stats .bytes_mallocd , sz );
3615
3604
jl_atomic_fetch_add_relaxed (& gc_heap_stats .heap_size , sz );
3616
3605
}
3617
3606
return malloc (sz );
@@ -3628,7 +3617,6 @@ JL_DLLEXPORT void *jl_gc_counted_calloc(size_t nm, size_t sz)
3628
3617
jl_atomic_load_relaxed (& ptls -> gc_num .allocd ) + nm * sz );
3629
3618
jl_atomic_store_relaxed (& ptls -> gc_num .malloc ,
3630
3619
jl_atomic_load_relaxed (& ptls -> gc_num .malloc ) + 1 );
3631
- jl_atomic_fetch_add_relaxed (& gc_heap_stats .bytes_mallocd , nm * sz );
3632
3620
jl_atomic_fetch_add_relaxed (& gc_heap_stats .heap_size , nm * sz );
3633
3621
}
3634
3622
return calloc (nm , sz );
@@ -3645,7 +3633,6 @@ JL_DLLEXPORT void jl_gc_counted_free_with_size(void *p, size_t sz)
3645
3633
jl_atomic_load_relaxed (& ptls -> gc_num .freed ) + sz );
3646
3634
jl_atomic_store_relaxed (& ptls -> gc_num .freecall ,
3647
3635
jl_atomic_load_relaxed (& ptls -> gc_num .freecall ) + 1 );
3648
- jl_atomic_fetch_add_relaxed (& gc_heap_stats .malloc_bytes_freed , sz );
3649
3636
jl_atomic_fetch_add_relaxed (& gc_heap_stats .heap_size , - sz );
3650
3637
}
3651
3638
}
@@ -3665,8 +3652,6 @@ JL_DLLEXPORT void *jl_gc_counted_realloc_with_old_size(void *p, size_t old, size
3665
3652
jl_atomic_load_relaxed (& ptls -> gc_num .allocd ) + (sz - old ));
3666
3653
jl_atomic_store_relaxed (& ptls -> gc_num .realloc ,
3667
3654
jl_atomic_load_relaxed (& ptls -> gc_num .realloc ) + 1 );
3668
- jl_atomic_fetch_add_relaxed (& gc_heap_stats .bytes_mallocd , sz );
3669
- jl_atomic_fetch_add_relaxed (& gc_heap_stats .malloc_bytes_freed , old );
3670
3655
jl_atomic_fetch_add_relaxed (& gc_heap_stats .heap_size , sz - old );
3671
3656
}
3672
3657
return realloc (p , sz );
@@ -3742,7 +3727,6 @@ JL_DLLEXPORT void *jl_gc_managed_malloc(size_t sz)
3742
3727
jl_atomic_load_relaxed (& ptls -> gc_num .allocd ) + allocsz );
3743
3728
jl_atomic_store_relaxed (& ptls -> gc_num .malloc ,
3744
3729
jl_atomic_load_relaxed (& ptls -> gc_num .malloc ) + 1 );
3745
- jl_atomic_fetch_add_relaxed (& gc_heap_stats .bytes_mallocd , allocsz );
3746
3730
jl_atomic_fetch_add_relaxed (& gc_heap_stats .heap_size , allocsz );
3747
3731
int last_errno = errno ;
3748
3732
#ifdef _OS_WINDOWS_
@@ -3782,8 +3766,6 @@ static void *gc_managed_realloc_(jl_ptls_t ptls, void *d, size_t sz, size_t olds
3782
3766
jl_atomic_load_relaxed (& ptls -> gc_num .allocd ) + (allocsz - oldsz ));
3783
3767
jl_atomic_store_relaxed (& ptls -> gc_num .realloc ,
3784
3768
jl_atomic_load_relaxed (& ptls -> gc_num .realloc ) + 1 );
3785
- jl_atomic_fetch_add_relaxed (& gc_heap_stats .bytes_mallocd , allocsz );
3786
- jl_atomic_fetch_add_relaxed (& gc_heap_stats .malloc_bytes_freed , oldsz );
3787
3769
jl_atomic_fetch_add_relaxed (& gc_heap_stats .heap_size , allocsz - oldsz );
3788
3770
int last_errno = errno ;
3789
3771
#ifdef _OS_WINDOWS_
@@ -3873,7 +3855,6 @@ static void *gc_perm_alloc_large(size_t sz, int zero, unsigned align, unsigned o
3873
3855
#ifdef _OS_WINDOWS_
3874
3856
SetLastError (last_error );
3875
3857
#endif
3876
- jl_atomic_fetch_add_relaxed (& gc_heap_stats .bytes_allocd ,sz );
3877
3858
jl_atomic_fetch_add_relaxed (& gc_heap_stats .heap_size ,sz );
3878
3859
errno = last_errno ;
3879
3860
jl_may_leak (base );
@@ -3918,7 +3899,6 @@ void *jl_gc_perm_alloc_nolock(size_t sz, int zero, unsigned align, unsigned offs
3918
3899
errno = last_errno ;
3919
3900
if (__unlikely (pool == MAP_FAILED ))
3920
3901
return NULL ;
3921
- jl_atomic_fetch_add_relaxed (& gc_heap_stats .pages_perm_allocd , 1 );
3922
3902
#endif
3923
3903
gc_perm_pool = (uintptr_t )pool ;
3924
3904
gc_perm_end = gc_perm_pool + GC_PERM_POOL_SIZE ;
0 commit comments