From 3725a53f4a6908a52304c741e34612e8eb574d39 Mon Sep 17 00:00:00 2001 From: d-netto Date: Mon, 17 Jul 2023 15:22:30 -0300 Subject: [PATCH] Revert "relax assertion involving pg->nold to reflect that it may be a bit inaccurate with parallel marking (#50466)" This reverts commit 8e877cbb01d2c26a3fdcb7b9302f4d3ead229f9f. --- src/gc.c | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/src/gc.c b/src/gc.c index 0761e29092e89..7f8c046de23d1 100644 --- a/src/gc.c +++ b/src/gc.c @@ -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), ""); - page->nold++; + jl_atomic_fetch_add_relaxed((_Atomic(uint16_t)*)&page->nold, 1); } else { ptls->gc_cache.scanned_bytes += page->osize; @@ -1377,27 +1377,20 @@ 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; } - // 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; + // 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; } }