Skip to content

Commit

Permalink
Metric for number of live bytes in the pool allocator (JuliaLang#51151)
Browse files Browse the repository at this point in the history
  • Loading branch information
d-netto authored and kpamnany committed Oct 21, 2023
1 parent 19dd1e0 commit 9ae2826
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,7 @@ int prev_sweep_full = 1;
#define inc_sat(v,s) v = (v) >= s ? s : (v)+1

// 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_live_bytes = 0; // live_bytes at last collection
Expand Down Expand Up @@ -1654,6 +1655,7 @@ static jl_taggedvalue_t **sweep_page(jl_gc_pool_t *p, jl_gc_pagemeta_t *pg, jl_t
done:
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;
}

Expand Down Expand Up @@ -3298,6 +3300,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;
Expand Down Expand Up @@ -3551,6 +3558,7 @@ static int _jl_gc_collect(jl_ptls_t ptls, jl_gc_collection_t collection)
}
scanned_bytes = 0;
// 5. start sweeping
pool_live_bytes = 0;
uint64_t start_sweep_time = jl_hrtime();
JL_PROBE_GC_SWEEP_BEGIN(sweep_full);
sweep_weak_refs();
Expand Down
1 change: 1 addition & 0 deletions src/jl_exported_funcs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
XX(jl_gc_get_max_memory) \
XX(jl_gc_internal_obj_base_ptr) \
XX(jl_gc_is_enabled) \
XX(jl_gc_pool_live_bytes) \
XX(jl_gc_live_bytes) \
XX(jl_gc_managed_malloc) \
XX(jl_gc_managed_realloc) \
Expand Down

0 comments on commit 9ae2826

Please sign in to comment.