@@ -1130,12 +1130,13 @@ static void combine_thread_gc_counts(jl_gc_num_t *dest) JL_NOTSAFEPOINT
1130
1130
jl_ptls_t ptls = gc_all_tls_states [i ];
1131
1131
if (ptls ) {
1132
1132
dest -> allocd += (jl_atomic_load_relaxed (& ptls -> gc_num .allocd ) + gc_num .interval );
1133
- dest -> freed += jl_atomic_load_relaxed (& ptls -> gc_num .freed );
1134
1133
dest -> malloc += jl_atomic_load_relaxed (& ptls -> gc_num .malloc );
1135
1134
dest -> realloc += jl_atomic_load_relaxed (& ptls -> gc_num .realloc );
1136
1135
dest -> poolalloc += jl_atomic_load_relaxed (& ptls -> gc_num .poolalloc );
1137
1136
dest -> bigalloc += jl_atomic_load_relaxed (& ptls -> gc_num .bigalloc );
1138
- dest -> freecall += jl_atomic_load_relaxed (& ptls -> gc_num .freecall );
1137
+ uint64_t alloc_acc = jl_atomic_load_relaxed (& ptls -> gc_num .alloc_acc );
1138
+ uint64_t free_acc = jl_atomic_load_relaxed (& ptls -> gc_num .free_acc );
1139
+ jl_atomic_store_relaxed (& gc_heap_stats .heap_size , alloc_acc - free_acc + jl_atomic_load_relaxed (& gc_heap_stats .heap_size ));
1139
1140
}
1140
1141
}
1141
1142
}
@@ -3601,7 +3602,13 @@ JL_DLLEXPORT void *jl_gc_counted_malloc(size_t sz)
3601
3602
jl_atomic_load_relaxed (& ptls -> gc_num .allocd ) + sz );
3602
3603
jl_atomic_store_relaxed (& ptls -> gc_num .malloc ,
3603
3604
jl_atomic_load_relaxed (& ptls -> gc_num .malloc ) + 1 );
3604
- jl_atomic_fetch_add_relaxed (& gc_heap_stats .heap_size , sz );
3605
+ uint64_t alloc_acc = jl_atomic_load_relaxed (& ptls -> gc_num .alloc_acc );
3606
+ if (alloc_acc + sz < 16 * 1024 )
3607
+ jl_atomic_store_relaxed (& ptls -> gc_num .alloc_acc , alloc_acc + sz );
3608
+ else {
3609
+ jl_atomic_fetch_add_relaxed (& gc_heap_stats .heap_size , alloc_acc + sz );
3610
+ jl_atomic_store_relaxed (& ptls -> gc_num .alloc_acc , 0 );
3611
+ }
3605
3612
}
3606
3613
return malloc (sz );
3607
3614
}
@@ -3617,7 +3624,13 @@ JL_DLLEXPORT void *jl_gc_counted_calloc(size_t nm, size_t sz)
3617
3624
jl_atomic_load_relaxed (& ptls -> gc_num .allocd ) + nm * sz );
3618
3625
jl_atomic_store_relaxed (& ptls -> gc_num .malloc ,
3619
3626
jl_atomic_load_relaxed (& ptls -> gc_num .malloc ) + 1 );
3620
- jl_atomic_fetch_add_relaxed (& gc_heap_stats .heap_size , nm * sz );
3627
+ uint64_t alloc_acc = jl_atomic_load_relaxed (& ptls -> gc_num .alloc_acc );
3628
+ if (alloc_acc + sz < 16 * 1024 )
3629
+ jl_atomic_store_relaxed (& ptls -> gc_num .alloc_acc , alloc_acc + sz * nm );
3630
+ else {
3631
+ jl_atomic_fetch_add_relaxed (& gc_heap_stats .heap_size , alloc_acc + sz * nm );
3632
+ jl_atomic_store_relaxed (& ptls -> gc_num .alloc_acc , 0 );
3633
+ }
3621
3634
}
3622
3635
return calloc (nm , sz );
3623
3636
}
@@ -3629,11 +3642,13 @@ JL_DLLEXPORT void jl_gc_counted_free_with_size(void *p, size_t sz)
3629
3642
free (p );
3630
3643
if (pgcstack != NULL && ct -> world_age ) {
3631
3644
jl_ptls_t ptls = ct -> ptls ;
3632
- jl_atomic_store_relaxed (& ptls -> gc_num .freed ,
3633
- jl_atomic_load_relaxed (& ptls -> gc_num .freed ) + sz );
3634
- jl_atomic_store_relaxed (& ptls -> gc_num .freecall ,
3635
- jl_atomic_load_relaxed (& ptls -> gc_num .freecall ) + 1 );
3636
- jl_atomic_fetch_add_relaxed (& gc_heap_stats .heap_size , - sz );
3645
+ uint64_t free_acc = jl_atomic_load_relaxed (& ptls -> gc_num .free_acc );
3646
+ if (free_acc + sz < 16 * 1024 )
3647
+ jl_atomic_store_relaxed (& ptls -> gc_num .free_acc , free_acc + sz );
3648
+ else {
3649
+ jl_atomic_fetch_add_relaxed (& gc_heap_stats .heap_size , - (free_acc + sz ));
3650
+ jl_atomic_store_relaxed (& ptls -> gc_num .free_acc , 0 );
3651
+ }
3637
3652
}
3638
3653
}
3639
3654
0 commit comments