Skip to content

Commit

Permalink
address a TODO in gc_sweep_page (i.e. save an unnecessary fetch-add) (J…
Browse files Browse the repository at this point in the history
  • Loading branch information
d-netto committed Jul 4, 2024
1 parent 454ed8c commit 5163fe7
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1528,9 +1528,16 @@ static void gc_sweep_page(gc_page_profiler_serializer_t *s, jl_gc_pool_t *p, jl_
gc_page_profile_write_to_file(s);
gc_update_page_fragmentation_data(pg);
gc_time_count_page(freedall, pg_skpd);
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);
jl_ptls_t ptls = jl_current_task->ptls;
// Note that we aggregate the `pool_live_bytes` over all threads before returning this
// value to the user. It doesn't matter how the `pool_live_bytes` are partitioned among
// the threads as long as the sum is correct. Let's add the `pool_live_bytes` to the current thread
// instead of adding it to the thread that originally allocated the page, so we can avoid
// an atomic-fetch-add here.
size_t delta = (GC_PAGE_SZ - GC_PAGE_OFFSET - nfree * osize);
jl_atomic_store_relaxed(&ptls->gc_num.pool_live_bytes,
jl_atomic_load_relaxed(&ptls->gc_num.pool_live_bytes) + delta);
jl_atomic_fetch_add_relaxed((_Atomic(int64_t) *)&gc_num.freed, (nfree - old_nfree) * osize);
}

// the actual sweeping over all allocated pages in a memory pool
Expand Down

0 comments on commit 5163fe7

Please sign in to comment.