Skip to content

Commit

Permalink
eagerly update pool live bytes metric
Browse files Browse the repository at this point in the history
  • Loading branch information
d-netto committed Nov 3, 2023
1 parent 9cd802f commit dbc701f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,6 @@ int prev_sweep_full = 1;
int current_sweep_full = 0;

// Full collection heuristics
static int64_t pool_live_bytes = 0;
static int64_t live_bytes = 0;
static int64_t promoted_bytes = 0;
static int64_t last_live_bytes = 0; // live_bytes at last collection
Expand Down Expand Up @@ -1384,6 +1383,8 @@ STATIC_INLINE jl_value_t *jl_gc_pool_alloc_inner(jl_ptls_t ptls, int pool_offset
maybe_collect(ptls);
jl_atomic_store_relaxed(&ptls->gc_num.allocd,
jl_atomic_load_relaxed(&ptls->gc_num.allocd) + osize);
jl_atomic_store_relaxed(&ptls->gc_num.pool_live_bytes,
jl_atomic_load_relaxed(&ptls->gc_num.pool_live_bytes) + osize);
jl_atomic_store_relaxed(&ptls->gc_num.poolalloc,
jl_atomic_load_relaxed(&ptls->gc_num.poolalloc) + 1);
// first try to use the freelist
Expand Down Expand Up @@ -1568,7 +1569,8 @@ static void gc_sweep_page(jl_gc_pool_t *p, jl_gc_page_stack_t *allocd, jl_gc_pag
}
}
gc_time_count_page(freedall, pg_skpd);
jl_atomic_fetch_add((_Atomic(int64_t) *)&pool_live_bytes, GC_PAGE_SZ - GC_PAGE_OFFSET - nfree * osize);
jl_ptls_t ptls = gc_all_tls_states[pg->thread_n];
jl_atomic_fetch_add(&ptls->gc_num.pool_live_bytes, GC_PAGE_SZ - GC_PAGE_OFFSET - nfree * osize);
jl_atomic_fetch_add((_Atomic(int64_t) *)&gc_num.freed, (nfree - old_nfree) * osize);
}

Expand Down Expand Up @@ -1690,6 +1692,7 @@ static void gc_sweep_pool(void)
}
continue;
}
jl_atomic_store_relaxed(&ptls2->gc_num.pool_live_bytes, 0);
for (int i = 0; i < JL_GC_N_POOLS; i++) {
jl_gc_pool_t *p = &ptls2->heap.norm_pools[i];
jl_taggedvalue_t *last = p->freelist;
Expand Down Expand Up @@ -3207,6 +3210,13 @@ JL_DLLEXPORT int64_t jl_gc_sync_total_bytes(int64_t offset) JL_NOTSAFEPOINT

JL_DLLEXPORT int64_t jl_gc_pool_live_bytes(void)
{
int64_t pool_live_bytes = 0;
for (int i = 0; i < gc_n_threads; i++) {
jl_ptls_t ptls2 = gc_all_tls_states[i];
if (ptls2 != NULL) {
pool_live_bytes += jl_atomic_load_relaxed(&ptls2->gc_num.pool_live_bytes);
}
}
return pool_live_bytes;
}

Expand Down Expand Up @@ -3394,7 +3404,6 @@ static int _jl_gc_collect(jl_ptls_t ptls, jl_gc_collection_t collection)
}
scanned_bytes = 0;
// 6. start sweeping
pool_live_bytes = 0;
uint64_t start_sweep_time = jl_hrtime();
JL_PROBE_GC_SWEEP_BEGIN(sweep_full);
current_sweep_full = sweep_full;
Expand Down
1 change: 1 addition & 0 deletions src/julia_threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ typedef struct {

typedef struct {
_Atomic(int64_t) allocd;
_Atomic(int64_t) pool_live_bytes;
_Atomic(int64_t) freed;
_Atomic(uint64_t) malloc;
_Atomic(uint64_t) realloc;
Expand Down

0 comments on commit dbc701f

Please sign in to comment.