Skip to content

Commit

Permalink
relax assertion involving pg->nold to reflect that it may be a bit in…
Browse files Browse the repository at this point in the history
…accurate with parallel marking (#50466)
  • Loading branch information
d-netto committed Jul 10, 2023
1 parent 84ef74f commit 8e877cb
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ STATIC_INLINE void gc_setmark_pool_(jl_ptls_t ptls, jl_taggedvalue_t *o,
if (mark_mode == GC_OLD_MARKED) {
ptls->gc_cache.perm_scanned_bytes += page->osize;
static_assert(sizeof(_Atomic(uint16_t)) == sizeof(page->nold), "");
jl_atomic_fetch_add_relaxed((_Atomic(uint16_t)*)&page->nold, 1);
page->nold++;
}
else {
ptls->gc_cache.scanned_bytes += page->osize;
Expand Down Expand Up @@ -1374,20 +1374,27 @@ static jl_taggedvalue_t **gc_sweep_page(jl_gc_pool_t *p, jl_gc_pagemeta_t **allo
nfree = (GC_PAGE_SZ - GC_PAGE_OFFSET) / osize;
goto done;
}
// For quick sweep, we might be able to skip the page if the page doesn't
// have any young live cell before marking.
if (!sweep_full && !pg->has_young) {
assert(!prev_sweep_full || pg->prev_nold >= pg->nold);
if (!prev_sweep_full || pg->prev_nold == pg->nold) {
// the position of the freelist begin/end in this page
// is stored in its metadata
if (pg->fl_begin_offset != (uint16_t)-1) {
*pfl = page_pfl_beg(pg);
pfl = (jl_taggedvalue_t**)page_pfl_end(pg);
// note that `pg->nold` may not be accurate with multithreaded marking since
// two threads may race when trying to set the mark bit in `gc_try_setmark_tag`.
// We're basically losing a bit of precision in the sweep phase at the cost of
// making the mark phase considerably cheaper.
// See issue #50419
if (jl_n_markthreads == 0) {
// For quick sweep, we might be able to skip the page if the page doesn't
// have any young live cell before marking.
if (!sweep_full && !pg->has_young) {
assert(!prev_sweep_full || pg->prev_nold >= pg->nold);
if (!prev_sweep_full || pg->prev_nold == pg->nold) {
// the position of the freelist begin/end in this page
// is stored in its metadata
if (pg->fl_begin_offset != (uint16_t)-1) {
*pfl = page_pfl_beg(pg);
pfl = (jl_taggedvalue_t**)page_pfl_end(pg);
}
freedall = 0;
nfree = pg->nfree;
goto done;
}
freedall = 0;
nfree = pg->nfree;
goto done;
}
}

Expand Down

0 comments on commit 8e877cb

Please sign in to comment.