@@ -758,7 +758,6 @@ int current_sweep_full = 0;
758758int under_pressure = 0 ;
759759
760760// Full collection heuristics
761- static int64_t pool_live_bytes = 0 ;
762761static int64_t live_bytes = 0 ;
763762static int64_t promoted_bytes = 0 ;
764763static int64_t last_live_bytes = 0 ; // live_bytes at last collection
@@ -1333,6 +1332,8 @@ STATIC_INLINE jl_value_t *jl_gc_pool_alloc_inner(jl_ptls_t ptls, int pool_offset
13331332 maybe_collect (ptls );
13341333 jl_atomic_store_relaxed (& ptls -> gc_num .allocd ,
13351334 jl_atomic_load_relaxed (& ptls -> gc_num .allocd ) + osize );
1335+ jl_atomic_store_relaxed (& ptls -> gc_num .pool_live_bytes ,
1336+ jl_atomic_load_relaxed (& ptls -> gc_num .pool_live_bytes ) + osize );
13361337 jl_atomic_store_relaxed (& ptls -> gc_num .poolalloc ,
13371338 jl_atomic_load_relaxed (& ptls -> gc_num .poolalloc ) + 1 );
13381339 // first try to use the freelist
@@ -1520,7 +1521,8 @@ static void gc_sweep_page(jl_gc_pool_t *p, jl_gc_page_stack_t *allocd, jl_gc_pag
15201521 }
15211522 }
15221523 gc_time_count_page (freedall , pg_skpd );
1523- jl_atomic_fetch_add ((_Atomic (int64_t ) * )& pool_live_bytes , GC_PAGE_SZ - GC_PAGE_OFFSET - nfree * osize );
1524+ jl_ptls_t ptls = gc_all_tls_states [pg -> thread_n ];
1525+ jl_atomic_fetch_add (& ptls -> gc_num .pool_live_bytes , GC_PAGE_SZ - GC_PAGE_OFFSET - nfree * osize );
15241526 jl_atomic_fetch_add ((_Atomic (int64_t ) * )& gc_num .freed , (nfree - old_nfree ) * osize );
15251527}
15261528
@@ -1642,6 +1644,7 @@ static void gc_sweep_pool(void)
16421644 }
16431645 continue ;
16441646 }
1647+ jl_atomic_store_relaxed (& ptls2 -> gc_num .pool_live_bytes , 0 );
16451648 for (int i = 0 ; i < JL_GC_N_POOLS ; i ++ ) {
16461649 jl_gc_pool_t * p = & ptls2 -> heap .norm_pools [i ];
16471650 jl_taggedvalue_t * last = p -> freelist ;
@@ -3182,6 +3185,13 @@ JL_DLLEXPORT int64_t jl_gc_sync_total_bytes(int64_t offset) JL_NOTSAFEPOINT
31823185
31833186JL_DLLEXPORT int64_t jl_gc_pool_live_bytes (void )
31843187{
3188+ int64_t pool_live_bytes = 0 ;
3189+ for (int i = 0 ; i < gc_n_threads ; i ++ ) {
3190+ jl_ptls_t ptls2 = gc_all_tls_states [i ];
3191+ if (ptls2 != NULL ) {
3192+ pool_live_bytes += jl_atomic_load_relaxed (& ptls2 -> gc_num .pool_live_bytes );
3193+ }
3194+ }
31853195 return pool_live_bytes ;
31863196}
31873197
@@ -3346,7 +3356,6 @@ static int _jl_gc_collect(jl_ptls_t ptls, jl_gc_collection_t collection)
33463356 promoted_bytes = 0 ;
33473357 }
33483358 scanned_bytes = 0 ;
3349- pool_live_bytes = 0 ;
33503359 // 6. start sweeping
33513360 uint64_t start_sweep_time = jl_hrtime ();
33523361 JL_PROBE_GC_SWEEP_BEGIN (sweep_full );
0 commit comments