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

relax assertion involving pg->nold to reflect that it may be a bit in… #50466

Merged
merged 4 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 13 additions & 11 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 @@ -1382,17 +1382,19 @@ static jl_taggedvalue_t **gc_sweep_page(jl_gc_pool_t *p, jl_gc_pagemeta_t **allo
// 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
assert(jl_n_markthreads != 0 || !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);
if (jl_n_markthreads == 0) {
gbaraldi marked this conversation as resolved.
Show resolved Hide resolved
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
54 changes: 54 additions & 0 deletions test.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

module BinaryTreeMutable

# Adopted from
# https://benchmarksgame-team.pages.debian.net/benchmarksgame/description/binarytrees.html#binarytrees

using Base.Threads
using Printf

mutable struct Node
l::Union{Nothing, Node}
r::Union{Nothing, Node}
end

function make(n::Int)
return n === 0 ? Node(nothing, nothing) : Node(make(n-1), make(n-1))
end

function check(node::Node)
return 1 + (node.l === nothing ? 0 : check(node.l) + check(node.r))
end

function binary_trees(io, n::Int)
@printf io "stretch tree of depth %jd\t check: %jd\n" n+1 check(make(n+1))

long_tree = make(n)
minDepth = 4
resultSize = div((n - minDepth), 2) + 1
results = Vector{String}(undef, resultSize)
Threads.@threads for depth in minDepth:2:n
c = 0
niter = 1 << (n - depth + minDepth)
for _ in 1:niter
c += check(make(depth))
end
index = div((depth - minDepth),2) + 1
results[index] = @sprintf "%jd\t trees of depth %jd\t check: %jd\n" niter depth c
end

for i in results
write(io, i)
end

@printf io "long lived tree of depth %jd\t check: %jd\n" n check(long_tree)
end

end #module

using .BinaryTreeMutable

# Memory usage is 466MB
BinaryTreeMutable.binary_trees(devnull, 16)
GC.gc()