diff --git a/base/sysinfo.jl b/base/sysinfo.jl index 5bd3573fb4736..0db396c9a42d3 100644 --- a/base/sysinfo.jl +++ b/base/sysinfo.jl @@ -14,6 +14,7 @@ export BINDIR, MACHINE, KERNEL, JIT, + PAGESIZE, cpu_info, cpu_summary, sysimage_target, @@ -144,6 +145,13 @@ Note: Included in the detailed system information via `versioninfo(verbose=true) """ global JIT::String +""" + Sys.PAGESIZE::Clong + +A number providing the pagesize of the given OS. Common values being 4kb or 64kb on Linux. +""" +global PAGESIZE::Clong + function __init__() env_threads = nothing if haskey(ENV, "JULIA_CPU_THREADS") @@ -162,6 +170,7 @@ function __init__() global SC_CLK_TCK = ccall(:jl_SC_CLK_TCK, Clong, ()) global CPU_NAME = ccall(:jl_get_cpu_name, Ref{String}, ()) global JIT = ccall(:jl_get_JIT, Ref{String}, ()) + global PAGESIZE = Int(Sys.isunix() ? ccall(:jl_getpagesize, Clong, ()) : ccall(:jl_getallocationgranularity, Clong, ())) __init_build() nothing end diff --git a/stdlib/Mmap/src/Mmap.jl b/stdlib/Mmap/src/Mmap.jl index c527123d51bb8..4802ede3af5d9 100644 --- a/stdlib/Mmap/src/Mmap.jl +++ b/stdlib/Mmap/src/Mmap.jl @@ -6,11 +6,10 @@ Low level module for mmap (memory mapping of files). module Mmap import Base: OS_HANDLE, INVALID_OS_HANDLE +using Sys: PAGESIZE export mmap -const PAGESIZE = Int(Sys.isunix() ? ccall(:jl_getpagesize, Clong, ()) : ccall(:jl_getallocationgranularity, Clong, ())) - # for mmaps not backed by files mutable struct Anonymous <: IO name::String diff --git a/stdlib/Mmap/test/runtests.jl b/stdlib/Mmap/test/runtests.jl index 4ab04bf733190..ee273e8debc13 100644 --- a/stdlib/Mmap/test/runtests.jl +++ b/stdlib/Mmap/test/runtests.jl @@ -268,6 +268,7 @@ A2 = mmap(s, Matrix{Int}, (m,n)) seek(s, 0) A3 = mmap(s, Matrix{Int}, (m,n), convert(Int64, 2*sizeof(Int))) @test A == A3 +seek(s, 0) A4 = mmap(s, Matrix{Int}, (m,150), convert(Int64, (2+150*m)*sizeof(Int))) @test A[:, 151:end] == A4 close(s)