Skip to content

Commit 54db887

Browse files
d-nettoRAI CI (GitHub Action Automation)
authored andcommitted
functionality to expose page utilization at the julia level (#113)
1 parent 61ceba0 commit 54db887

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(:jl_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
@@ -1398,21 +1398,19 @@ int jl_gc_classify_pools(size_t sz, int *osize)
13981398
// sweep phase
13991399

14001400
gc_fragmentation_stat_t gc_page_fragmentation_stats[JL_GC_N_POOLS];
1401+
JL_DLLEXPORT double jl_gc_page_utilization_stats[JL_GC_N_MAX_POOLS];
14011402

14021403
extern gc_fragmentation_stat_t gc_page_fragmentation_stats[JL_GC_N_POOLS];
14031404

14041405
STATIC_INLINE void gc_update_page_fragmentation_data(jl_gc_pagemeta_t *pg) JL_NOTSAFEPOINT
14051406
{
1406-
#ifdef GC_MEASURE_PAGE_FRAGMENTATION
14071407
gc_fragmentation_stat_t *stats = &gc_page_fragmentation_stats[pg->pool_n];
14081408
jl_atomic_fetch_add(&stats->n_freed_objs, pg->nfree);
14091409
jl_atomic_fetch_add(&stats->n_pages_allocd, 1);
1410-
#endif
14111410
}
14121411

14131412
STATIC_INLINE void gc_dump_page_utilization_data(void) JL_NOTSAFEPOINT
14141413
{
1415-
#ifdef GC_MEASURE_PAGE_FRAGMENTATION
14161414
for (int i = 0; i < JL_GC_N_POOLS; i++) {
14171415
gc_fragmentation_stat_t *stats = &gc_page_fragmentation_stats[i];
14181416
double utilization = 1.0;
@@ -1421,12 +1419,10 @@ STATIC_INLINE void gc_dump_page_utilization_data(void) JL_NOTSAFEPOINT
14211419
if (n_pages_allocd != 0) {
14221420
utilization -= ((double)n_freed_objs * (double)jl_gc_sizeclasses[i]) / (double)n_pages_allocd / (double)GC_PAGE_SZ;
14231421
}
1424-
jl_safe_printf("Size class %d: %.2f%% utilization\n", jl_gc_sizeclasses[i], utilization * 100.0);
1422+
jl_gc_page_utilization_stats[i] = utilization;
14251423
jl_atomic_store_relaxed(&stats->n_freed_objs, 0);
14261424
jl_atomic_store_relaxed(&stats->n_pages_allocd, 0);
14271425
}
1428-
jl_safe_printf("-----------------------------------------\n");
1429-
#endif
14301426
}
14311427

14321428
int64_t buffered_pages = 0;

src/gc.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,6 @@ STATIC_INLINE jl_gc_pagemeta_t *pop_lf_back(jl_gc_page_stack_t *pool) JL_NOTSAFE
223223
}
224224
}
225225

226-
// data structures for tracking fragmentation in the pool allocator
227-
// #define GC_MEASURE_PAGE_FRAGMENTATION
228-
229226
typedef struct {
230227
_Atomic(size_t) n_freed_objs;
231228
_Atomic(size_t) n_pages_allocd;

0 commit comments

Comments
 (0)