Skip to content

Commit

Permalink
add function to query GC page size (JuliaLang#54115) (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
d-netto authored Apr 20, 2024
1 parent 01b4a24 commit bcd9f13
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/gc-pages.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
extern "C" {
#endif

JL_DLLEXPORT uint64_t jl_get_pg_size(void)
{
return GC_PAGE_SZ;
}

// Try to allocate memory in chunks to permit faster allocation
// and improve memory locality of the pools
#ifdef _P64
Expand Down
19 changes: 19 additions & 0 deletions test/gc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ function run_gctest(file)
end
end

function run_nonzero_page_utilization_test()
GC.gc()
page_utilization = Base.gc_page_utilization_data()
# at least one of the pools should have nonzero page_utilization
@test any(page_utilization .> 0)
end

function run_pg_size_test()
page_size = @ccall jl_get_pg_size()::UInt64
# supported page sizes: 4KB and 16KB
@test page_size == (1 << 12) || page_size == (1 << 14)
end

# !!! note:
# Since we run our tests on 32bit OS as well we confine ourselves
# to parameters that allocate about 512MB of objects. Max RSS is lower
Expand All @@ -25,3 +38,9 @@ end
run_gctest("gc/objarray.jl")
run_gctest("gc/chunks.jl")
end

@testset "GC page metrics" begin
run_nonzero_page_utilization_test()
run_pg_size_test()
end

0 comments on commit bcd9f13

Please sign in to comment.