@@ -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
@@ -1313,6 +1312,8 @@ STATIC_INLINE jl_value_t *jl_gc_pool_alloc_inner(jl_ptls_t ptls, int pool_offset
13131312 maybe_collect (ptls );
13141313 jl_atomic_store_relaxed (& ptls -> gc_num .allocd ,
13151314 jl_atomic_load_relaxed (& ptls -> gc_num .allocd ) + osize );
1315+ jl_atomic_store_relaxed (& ptls -> gc_num .pool_live_bytes ,
1316+ jl_atomic_load_relaxed (& ptls -> gc_num .pool_live_bytes ) + osize );
13161317 jl_atomic_store_relaxed (& ptls -> gc_num .poolalloc ,
13171318 jl_atomic_load_relaxed (& ptls -> gc_num .poolalloc ) + 1 );
13181319 // first try to use the freelist
@@ -1499,7 +1500,8 @@ static void gc_sweep_page(jl_gc_pool_t *p, jl_gc_page_stack_t *allocd, jl_gc_pag
14991500 }
15001501 }
15011502 gc_time_count_page (freedall , pg_skpd );
1502- jl_atomic_fetch_add ((_Atomic (int64_t ) * )& pool_live_bytes , GC_PAGE_SZ - GC_PAGE_OFFSET - nfree * osize );
1503+ jl_ptls_t ptls = gc_all_tls_states [pg -> thread_n ];
1504+ jl_atomic_fetch_add (& ptls -> gc_num .pool_live_bytes , GC_PAGE_SZ - GC_PAGE_OFFSET - nfree * osize );
15031505 jl_atomic_fetch_add ((_Atomic (int64_t ) * )& gc_num .freed , (nfree - old_nfree ) * osize );
15041506}
15051507
@@ -1621,6 +1623,7 @@ static void gc_sweep_pool(void)
16211623 }
16221624 continue ;
16231625 }
1626+ jl_atomic_store_relaxed (& ptls2 -> gc_num .pool_live_bytes , 0 );
16241627 for (int i = 0 ; i < JL_GC_N_POOLS ; i ++ ) {
16251628 jl_gc_pool_t * p = & ptls2 -> heap .norm_pools [i ];
16261629 jl_taggedvalue_t * last = p -> freelist ;
@@ -3258,6 +3261,13 @@ JL_DLLEXPORT int64_t jl_gc_sync_total_bytes(int64_t offset) JL_NOTSAFEPOINT
32583261
32593262JL_DLLEXPORT int64_t jl_gc_pool_live_bytes (void )
32603263{
3264+ int64_t pool_live_bytes = 0 ;
3265+ for (int i = 0 ; i < gc_n_threads ; i ++ ) {
3266+ jl_ptls_t ptls2 = gc_all_tls_states [i ];
3267+ if (ptls2 != NULL ) {
3268+ pool_live_bytes += jl_atomic_load_relaxed (& ptls2 -> gc_num .pool_live_bytes );
3269+ }
3270+ }
32613271 return pool_live_bytes ;
32623272}
32633273
@@ -3463,7 +3473,6 @@ static int _jl_gc_collect(jl_ptls_t ptls, jl_gc_collection_t collection)
34633473 promoted_bytes = 0 ;
34643474 }
34653475 scanned_bytes = 0 ;
3466- pool_live_bytes = 0 ;
34673476 // 6. start sweeping
34683477 uint64_t start_sweep_time = jl_hrtime ();
34693478 JL_PROBE_GC_SWEEP_BEGIN (sweep_full );
0 commit comments