Skip to content

Commit 0a4b810

Browse files
d-nettovchuravy
andauthored
functionality to expose page utilization at the julia level (#52390)
--------- Co-authored-by: Valentin Churavy <vchuravy@users.noreply.github.com>
1 parent bb7091c commit 0a4b810

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

base/timing.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ function gc_live_bytes()
9898
Int(ccall(:jl_gc_live_bytes, Int64, ())) + num.allocd + num.deferred_alloc
9999
end
100100

101+
# must be kept in sync with the value from `src/julia_threads.h``
102+
const JL_GC_N_MAX_POOLS = 51
103+
function gc_page_utilization_data()
104+
page_utilization_raw = cglobal(:gc_page_utilization_stats, Float64)
105+
return Base.unsafe_wrap(Array, page_utilization_raw, JL_GC_N_MAX_POOLS, own=false)
106+
end
107+
101108
"""
102109
Base.jit_total_bytes()
103110

src/gc.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,19 +1421,17 @@ int jl_gc_classify_pools(size_t sz, int *osize)
14211421
// sweep phase
14221422

14231423
gc_fragmentation_stat_t gc_page_fragmentation_stats[JL_GC_N_POOLS];
1424+
JL_DLLEXPORT double gc_page_utilization_stats[JL_GC_N_MAX_POOLS];
14241425

14251426
STATIC_INLINE void gc_update_page_fragmentation_data(jl_gc_pagemeta_t *pg) JL_NOTSAFEPOINT
14261427
{
1427-
#ifdef GC_MEASURE_PAGE_FRAGMENTATION
14281428
gc_fragmentation_stat_t *stats = &gc_page_fragmentation_stats[pg->pool_n];
14291429
jl_atomic_fetch_add(&stats->n_freed_objs, pg->nfree);
14301430
jl_atomic_fetch_add(&stats->n_pages_allocd, 1);
1431-
#endif
14321431
}
14331432

14341433
STATIC_INLINE void gc_dump_page_utilization_data(void) JL_NOTSAFEPOINT
14351434
{
1436-
#ifdef GC_MEASURE_PAGE_FRAGMENTATION
14371435
for (int i = 0; i < JL_GC_N_POOLS; i++) {
14381436
gc_fragmentation_stat_t *stats = &gc_page_fragmentation_stats[i];
14391437
double utilization = 1.0;
@@ -1442,12 +1440,10 @@ STATIC_INLINE void gc_dump_page_utilization_data(void) JL_NOTSAFEPOINT
14421440
if (n_pages_allocd != 0) {
14431441
utilization -= ((double)n_freed_objs * (double)jl_gc_sizeclasses[i]) / (double)n_pages_allocd / (double)GC_PAGE_SZ;
14441442
}
1445-
jl_safe_printf("Size class %d: %.2f%% utilization\n", jl_gc_sizeclasses[i], utilization * 100.0);
1443+
gc_page_utilization_stats[i] = utilization;
14461444
jl_atomic_store_relaxed(&stats->n_freed_objs, 0);
14471445
jl_atomic_store_relaxed(&stats->n_pages_allocd, 0);
14481446
}
1449-
jl_safe_printf("-----------------------------------------\n");
1450-
#endif
14511447
}
14521448

14531449
int64_t buffered_pages = 0;

src/gc.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,6 @@ STATIC_INLINE jl_gc_pagemeta_t *pop_lf_back(jl_gc_page_stack_t *pool) JL_NOTSAFE
238238
}
239239
}
240240

241-
// data structures for tracking fragmentation in the pool allocator
242-
// #define GC_MEASURE_PAGE_FRAGMENTATION
243-
244241
typedef struct {
245242
_Atomic(size_t) n_freed_objs;
246243
_Atomic(size_t) n_pages_allocd;

0 commit comments

Comments
 (0)