From 27e1ed91234aa5adc96854d47ed8ca3b10b04656 Mon Sep 17 00:00:00 2001 From: d-netto Date: Mon, 21 Aug 2023 12:41:56 -0300 Subject: [PATCH] Metric for number of live bytes in the pool allocator (#51151) --- src/gc.c | 8 ++++++++ src/jl_exported_funcs.inc | 1 + 2 files changed, 9 insertions(+) diff --git a/src/gc.c b/src/gc.c index c0ed53c8dca0d..17e6f45aa7476 100644 --- a/src/gc.c +++ b/src/gc.c @@ -746,6 +746,7 @@ int prev_sweep_full = 1; int under_pressure = 0; // Full collection heuristics +static int64_t pool_live_bytes = 0; static int64_t live_bytes = 0; static int64_t promoted_bytes = 0; static int64_t last_full_live = 0; // live_bytes after last full collection @@ -1499,6 +1500,7 @@ static jl_taggedvalue_t **gc_sweep_page(jl_gc_pool_t *p, jl_gc_pagemeta_t **allo } gc_time_count_page(freedall, pg_skpd); gc_num.freed += (nfree - old_nfree) * osize; + pool_live_bytes += GC_PAGE_SZ - GC_PAGE_OFFSET - nfree * osize; return pfl; } @@ -3098,6 +3100,11 @@ JL_DLLEXPORT int64_t jl_gc_sync_total_bytes(int64_t offset) JL_NOTSAFEPOINT return newtb - oldtb; } +JL_DLLEXPORT int64_t jl_gc_pool_live_bytes(void) +{ + return pool_live_bytes; +} + JL_DLLEXPORT int64_t jl_gc_live_bytes(void) { return live_bytes; @@ -3298,6 +3305,7 @@ static int _jl_gc_collect(jl_ptls_t ptls, jl_gc_collection_t collection) promoted_bytes = 0; } scanned_bytes = 0; + pool_live_bytes = 0; // 6. start sweeping uint64_t start_sweep_time = jl_hrtime(); JL_PROBE_GC_SWEEP_BEGIN(sweep_full); diff --git a/src/jl_exported_funcs.inc b/src/jl_exported_funcs.inc index 57a2e0cfc58ec..3ca083b1df6cc 100644 --- a/src/jl_exported_funcs.inc +++ b/src/jl_exported_funcs.inc @@ -176,6 +176,7 @@ XX(jl_gc_internal_obj_base_ptr) \ XX(jl_gc_is_enabled) \ XX(jl_gc_is_in_finalizer) \ + XX(jl_gc_pool_live_bytes) \ XX(jl_gc_live_bytes) \ XX(jl_gc_managed_malloc) \ XX(jl_gc_managed_realloc) \