Skip to content

Commit 0cc0dbd

Browse files
authored
Metric for number of live bytes in the pool allocator (#51151)
We want to study what is the degree of fragmentation we have in the pool allocator specifically. `pool_live_bytes` / `(live pages * GC_PAGE_SZ)` should provide an estimate of that.
1 parent 70000ac commit 0cc0dbd

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/gc.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@ int prev_sweep_full = 1;
753753
int under_pressure = 0;
754754

755755
// Full collection heuristics
756+
static int64_t pool_live_bytes = 0;
756757
static int64_t live_bytes = 0;
757758
static int64_t promoted_bytes = 0;
758759
static int64_t last_live_bytes = 0; // live_bytes at last collection
@@ -1530,6 +1531,7 @@ static jl_taggedvalue_t **gc_sweep_page(jl_gc_pool_t *p, jl_gc_pagemeta_t **allo
15301531
}
15311532
gc_time_count_page(freedall, pg_skpd);
15321533
gc_num.freed += (nfree - old_nfree) * osize;
1534+
pool_live_bytes += GC_PAGE_SZ - GC_PAGE_OFFSET - nfree * osize;
15331535
return pfl;
15341536
}
15351537

@@ -3108,6 +3110,11 @@ JL_DLLEXPORT int64_t jl_gc_sync_total_bytes(int64_t offset) JL_NOTSAFEPOINT
31083110
return newtb - oldtb;
31093111
}
31103112

3113+
JL_DLLEXPORT int64_t jl_gc_pool_live_bytes(void)
3114+
{
3115+
return pool_live_bytes;
3116+
}
3117+
31113118
JL_DLLEXPORT int64_t jl_gc_live_bytes(void)
31123119
{
31133120
return live_bytes;
@@ -3269,6 +3276,7 @@ static int _jl_gc_collect(jl_ptls_t ptls, jl_gc_collection_t collection)
32693276
promoted_bytes = 0;
32703277
}
32713278
scanned_bytes = 0;
3279+
pool_live_bytes = 0;
32723280
// 6. start sweeping
32733281
uint64_t start_sweep_time = jl_hrtime();
32743282
JL_PROBE_GC_SWEEP_BEGIN(sweep_full);

src/jl_exported_funcs.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@
176176
XX(jl_gc_internal_obj_base_ptr) \
177177
XX(jl_gc_is_enabled) \
178178
XX(jl_gc_is_in_finalizer) \
179+
XX(jl_gc_pool_live_bytes) \
179180
XX(jl_gc_live_bytes) \
180181
XX(jl_gc_managed_malloc) \
181182
XX(jl_gc_managed_realloc) \

0 commit comments

Comments
 (0)