Skip to content

Commit cddef7e

Browse files
committed
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 d9cccf6 commit cddef7e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/gc.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,7 @@ int under_pressure = 0;
872872
#define inc_sat(v,s) v = (v) >= s ? s : (v)+1
873873

874874
// Full collection heuristics
875+
static int64_t pool_live_bytes = 0;
875876
static int64_t live_bytes = 0;
876877
static int64_t promoted_bytes = 0;
877878
static int64_t last_live_bytes = 0; // live_bytes at last collection
@@ -1691,6 +1692,7 @@ static jl_taggedvalue_t **sweep_page(jl_gc_pool_t *p, jl_gc_pagemeta_t *pg, jl_t
16911692
done:
16921693
gc_time_count_page(freedall, pg_skpd);
16931694
gc_num.freed += (nfree - old_nfree) * osize;
1695+
pool_live_bytes += GC_PAGE_SZ - GC_PAGE_OFFSET - nfree * osize;
16941696
return pfl;
16951697
}
16961698

@@ -3335,6 +3337,11 @@ JL_DLLEXPORT int64_t jl_gc_sync_total_bytes(int64_t offset) JL_NOTSAFEPOINT
33353337
return newtb - oldtb;
33363338
}
33373339

3340+
JL_DLLEXPORT int64_t jl_gc_pool_live_bytes(void)
3341+
{
3342+
return pool_live_bytes;
3343+
}
3344+
33383345
JL_DLLEXPORT int64_t jl_gc_live_bytes(void)
33393346
{
33403347
return live_bytes;
@@ -3587,7 +3594,8 @@ static int _jl_gc_collect(jl_ptls_t ptls, jl_gc_collection_t collection)
35873594
promoted_bytes = 0;
35883595
}
35893596
scanned_bytes = 0;
3590-
// 5. start sweeping
3597+
pool_live_bytes = 0;
3598+
// 6. start sweeping
35913599
uint64_t start_sweep_time = jl_hrtime();
35923600
JL_PROBE_GC_SWEEP_BEGIN(sweep_full);
35933601
sweep_weak_refs();

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_get_max_memory) \
177177
XX(jl_gc_internal_obj_base_ptr) \
178178
XX(jl_gc_is_enabled) \
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)