Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eagerly update pool live bytes metric #105

Merged
merged 1 commit into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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