Skip to content

Commit e1c38fe

Browse files
authored
functionality to expose page utilization at the julia level (#113)
1 parent fd60a08 commit e1c38fe

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
@@ -99,6 +99,13 @@ function gc_live_bytes()
9999
Int(ccall(:jl_gc_live_bytes, Int64, ())) + num.allocd + num.deferred_alloc
100100
end
101101

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

src/gc.c

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

14711471
gc_fragmentation_stat_t gc_page_fragmentation_stats[JL_GC_N_POOLS];
1472+
JL_DLLEXPORT double jl_gc_page_utilization_stats[JL_GC_N_MAX_POOLS];
14721473

14731474
STATIC_INLINE void gc_update_page_fragmentation_data(jl_gc_pagemeta_t *pg) JL_NOTSAFEPOINT
14741475
{
1475-
#ifdef GC_MEASURE_PAGE_FRAGMENTATION
14761476
gc_fragmentation_stat_t *stats = &gc_page_fragmentation_stats[pg->pool_n];
14771477
jl_atomic_fetch_add(&stats->n_freed_objs, pg->nfree);
14781478
jl_atomic_fetch_add(&stats->n_pages_allocd, 1);
1479-
#endif
14801479
}
14811480

14821481
STATIC_INLINE void gc_dump_page_utilization_data(void) JL_NOTSAFEPOINT
14831482
{
1484-
#ifdef GC_MEASURE_PAGE_FRAGMENTATION
14851483
for (int i = 0; i < JL_GC_N_POOLS; i++) {
14861484
gc_fragmentation_stat_t *stats = &gc_page_fragmentation_stats[i];
14871485
double utilization = 1.0;
@@ -1490,12 +1488,10 @@ STATIC_INLINE void gc_dump_page_utilization_data(void) JL_NOTSAFEPOINT
14901488
if (n_pages_allocd != 0) {
14911489
utilization -= ((double)n_freed_objs * (double)jl_gc_sizeclasses[i]) / (double)n_pages_allocd / (double)GC_PAGE_SZ;
14921490
}
1493-
jl_safe_printf("Size class %d: %.2f%% utilization\n", jl_gc_sizeclasses[i], utilization * 100.0);
1491+
jl_gc_page_utilization_stats[i] = utilization;
14941492
jl_atomic_store_relaxed(&stats->n_freed_objs, 0);
14951493
jl_atomic_store_relaxed(&stats->n_pages_allocd, 0);
14961494
}
1497-
jl_safe_printf("-----------------------------------------\n");
1498-
#endif
14991495
}
15001496

15011497
int64_t buffered_pages = 0;

src/gc.h

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

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

0 commit comments

Comments
 (0)