@@ -1189,11 +1189,16 @@ static void reset_thread_gc_counts(void) JL_NOTSAFEPOINT
11891189 }
11901190}
11911191
1192+ static int64_t inc_live_bytes (int64_t inc ) JL_NOTSAFEPOINT
1193+ {
1194+ jl_timing_counter_inc (JL_TIMING_COUNTER_HeapSize , inc );
1195+ return live_bytes += inc ;
1196+ }
1197+
11921198void jl_gc_reset_alloc_count (void ) JL_NOTSAFEPOINT
11931199{
11941200 combine_thread_gc_counts (& gc_num );
1195- live_bytes += (gc_num .deferred_alloc + gc_num .allocd );
1196- jl_timing_counter_inc (JL_TIMING_COUNTER_HeapSize , gc_num .deferred_alloc + gc_num .allocd );
1201+ inc_live_bytes (gc_num .deferred_alloc + gc_num .allocd );
11971202 gc_num .allocd = 0 ;
11981203 gc_num .deferred_alloc = 0 ;
11991204 reset_thread_gc_counts ();
@@ -3095,6 +3100,10 @@ static int _jl_gc_collect(jl_ptls_t ptls, jl_gc_collection_t collection)
30953100{
30963101 combine_thread_gc_counts (& gc_num );
30973102
3103+ // We separate the update of the graph from the update of live_bytes here
3104+ // so that the sweep shows a downward trend in memory usage.
3105+ jl_timing_counter_inc (JL_TIMING_COUNTER_HeapSize , gc_num .allocd );
3106+
30983107 jl_gc_markqueue_t * mq = & ptls -> mark_queue ;
30993108
31003109 uint64_t gc_start_time = jl_hrtime ();
@@ -3339,8 +3348,10 @@ static int _jl_gc_collect(jl_ptls_t ptls, jl_gc_collection_t collection)
33393348 }
33403349
33413350 last_live_bytes = live_bytes ;
3351+ // Can't call inc_live_bytes here because we already added allocd
3352+ // to the graph earlier
33423353 live_bytes += - gc_num .freed + gc_num .allocd ;
3343- jl_timing_counter_inc (JL_TIMING_COUNTER_HeapSize , - gc_num .freed + gc_num . allocd );
3354+ jl_timing_counter_dec (JL_TIMING_COUNTER_HeapSize , gc_num .freed );
33443355
33453356 if (collection == JL_GC_AUTO ) {
33463357 //If we aren't freeing enough or are seeing lots and lots of pointers let it increase faster
@@ -3772,8 +3783,7 @@ static void *gc_managed_realloc_(jl_ptls_t ptls, void *d, size_t sz, size_t olds
37723783
37733784 if (jl_astaggedvalue (owner )-> bits .gc == GC_OLD_MARKED ) {
37743785 ptls -> gc_cache .perm_scanned_bytes += allocsz - oldsz ;
3775- live_bytes += allocsz - oldsz ;
3776- jl_timing_counter_inc (JL_TIMING_COUNTER_HeapSize , allocsz - oldsz );
3786+ inc_live_bytes (allocsz - oldsz );
37773787 }
37783788 else if (allocsz < oldsz )
37793789 jl_atomic_store_relaxed (& ptls -> gc_num .freed ,
0 commit comments