@@ -753,7 +753,6 @@ int current_sweep_full = 0;
753753int under_pressure = 0 ;
754754
755755// Full collection heuristics
756- static int64_t pool_live_bytes = 0 ;
757756static int64_t live_bytes = 0 ;
758757static int64_t promoted_bytes = 0 ;
759758static int64_t last_full_live = 0 ; // live_bytes after last full collection
@@ -1306,6 +1305,8 @@ STATIC_INLINE jl_value_t *jl_gc_pool_alloc_inner(jl_ptls_t ptls, int pool_offset
13061305 maybe_collect (ptls );
13071306 jl_atomic_store_relaxed (& ptls -> gc_num .allocd ,
13081307 jl_atomic_load_relaxed (& ptls -> gc_num .allocd ) + osize );
1308+ jl_atomic_store_relaxed (& ptls -> gc_num .pool_live_bytes ,
1309+ jl_atomic_load_relaxed (& ptls -> gc_num .pool_live_bytes ) + osize );
13091310 jl_atomic_store_relaxed (& ptls -> gc_num .poolalloc ,
13101311 jl_atomic_load_relaxed (& ptls -> gc_num .poolalloc ) + 1 );
13111312 // first try to use the freelist
@@ -1492,7 +1493,8 @@ static void gc_sweep_page(jl_gc_pool_t *p, jl_gc_page_stack_t *allocd, jl_gc_pag
14921493 }
14931494 }
14941495 gc_time_count_page (freedall , pg_skpd );
1495- jl_atomic_fetch_add ((_Atomic (int64_t ) * )& pool_live_bytes , GC_PAGE_SZ - GC_PAGE_OFFSET - nfree * osize );
1496+ jl_ptls_t ptls = gc_all_tls_states [pg -> thread_n ];
1497+ jl_atomic_fetch_add (& ptls -> gc_num .pool_live_bytes , GC_PAGE_SZ - GC_PAGE_OFFSET - nfree * osize );
14961498 jl_atomic_fetch_add ((_Atomic (int64_t ) * )& gc_num .freed , (nfree - old_nfree ) * osize );
14971499}
14981500
@@ -1614,6 +1616,7 @@ static void gc_sweep_pool(void)
16141616 }
16151617 continue ;
16161618 }
1619+ jl_atomic_store_relaxed (& ptls2 -> gc_num .pool_live_bytes , 0 );
16171620 for (int i = 0 ; i < JL_GC_N_POOLS ; i ++ ) {
16181621 jl_gc_pool_t * p = & ptls2 -> heap .norm_pools [i ];
16191622 jl_taggedvalue_t * last = p -> freelist ;
@@ -3265,6 +3268,13 @@ JL_DLLEXPORT int64_t jl_gc_sync_total_bytes(int64_t offset) JL_NOTSAFEPOINT
32653268
32663269JL_DLLEXPORT int64_t jl_gc_pool_live_bytes (void )
32673270{
3271+ int64_t pool_live_bytes = 0 ;
3272+ for (int i = 0 ; i < gc_n_threads ; i ++ ) {
3273+ jl_ptls_t ptls2 = gc_all_tls_states [i ];
3274+ if (ptls2 != NULL ) {
3275+ pool_live_bytes += jl_atomic_load_relaxed (& ptls2 -> gc_num .pool_live_bytes );
3276+ }
3277+ }
32683278 return pool_live_bytes ;
32693279}
32703280
@@ -3470,7 +3480,6 @@ static int _jl_gc_collect(jl_ptls_t ptls, jl_gc_collection_t collection)
34703480 promoted_bytes = 0 ;
34713481 }
34723482 scanned_bytes = 0 ;
3473- pool_live_bytes = 0 ;
34743483 // 6. start sweeping
34753484 uint64_t start_sweep_time = jl_hrtime ();
34763485 JL_PROBE_GC_SWEEP_BEGIN (sweep_full );
0 commit comments