Skip to content

Commit db003be

Browse files
green-brvtjnash
andauthored
Mmap fix on system with 64k pagesize. (#59695)
Not sure if this is the best approach but seemed to allow Mmap test to pass. Seems the pagesize was being set to value at build-time rather than being re-evaluated at runtime. Running Mmap tests on system with 64k pagesize, Mmap would still think its on a system with 4k pagesize and therefore fail. --------- Co-authored-by: Jameson Nash <[email protected]>
1 parent ecfec85 commit db003be

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

base/sysinfo.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export BINDIR,
1414
MACHINE,
1515
KERNEL,
1616
JIT,
17+
PAGESIZE,
1718
cpu_info,
1819
cpu_summary,
1920
sysimage_target,
@@ -144,6 +145,13 @@ Note: Included in the detailed system information via `versioninfo(verbose=true)
144145
"""
145146
global JIT::String
146147

148+
"""
149+
Sys.PAGESIZE::Clong
150+
151+
A number providing the pagesize of the given OS. Common values being 4kb or 64kb on Linux.
152+
"""
153+
global PAGESIZE::Clong
154+
147155
function __init__()
148156
env_threads = nothing
149157
if haskey(ENV, "JULIA_CPU_THREADS")
@@ -162,6 +170,7 @@ function __init__()
162170
global SC_CLK_TCK = ccall(:jl_SC_CLK_TCK, Clong, ())
163171
global CPU_NAME = ccall(:jl_get_cpu_name, Ref{String}, ())
164172
global JIT = ccall(:jl_get_JIT, Ref{String}, ())
173+
global PAGESIZE = Int(Sys.isunix() ? ccall(:jl_getpagesize, Clong, ()) : ccall(:jl_getallocationgranularity, Clong, ()))
165174
__init_build()
166175
nothing
167176
end

stdlib/Mmap/src/Mmap.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ Low level module for mmap (memory mapping of files).
66
module Mmap
77

88
import Base: OS_HANDLE, INVALID_OS_HANDLE
9+
using Base.Sys: PAGESIZE
910

1011
export mmap
1112

12-
const PAGESIZE = Int(Sys.isunix() ? ccall(:jl_getpagesize, Clong, ()) : ccall(:jl_getallocationgranularity, Clong, ()))
13-
1413
# for mmaps not backed by files
1514
mutable struct Anonymous <: IO
1615
name::String

stdlib/Mmap/test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ A2 = mmap(s, Matrix{Int}, (m,n))
269269
seek(s, 0)
270270
A3 = mmap(s, Matrix{Int}, (m,n), convert(Int64, 2*sizeof(Int)))
271271
@test A == A3
272+
seek(s, 0)
272273
A4 = mmap(s, Matrix{Int}, (m,150), convert(Int64, (2+150*m)*sizeof(Int)))
273274
@test A[:, 151:end] == A4
274275
close(s)

0 commit comments

Comments
 (0)