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

Fix mmap_array with offset on Windows #7242

Merged
merged 3 commits into from
Jun 15, 2014
Merged

Conversation

tkelman
Copy link
Contributor

@tkelman tkelman commented Jun 13, 2014

query allocation granularity (64k on Windows, larger than page size which is 4k),
ensure offset to MapViewOfFile is a multiple of the granularity

add a test for mmap_array with offset

fixes #7080 and #6203

some mmap issues remain with HDF5.jl, but there may be something else going on there

query allocation granularity (64k on Windows, larger than page size which is 4k),
ensure offset to MapViewOfFile is a multiple of the granularity

add a test for mmap with offset
@tkelman tkelman changed the title Fix mmap with offset on Windows Fix mmap_array with offset on Windows Jun 13, 2014
@StefanKarpinski
Copy link
Member

@vtjnash, @ihnorton – could you guys test and merge if this looks good. Thanks, @tkelman!

error("file is too large to memory-map on this platform")
end
# Set the offset to a page boundary
offset_page::FileOffset = ifloor(offset/granularity)*granularity
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use idiv instead?

@timholy
Copy link
Member

timholy commented Jun 13, 2014

Before merging, it will probably be useful to wait until JuliaIO/HDF5.jl#89 is working, as it's another easy way to test mmap facilities.

szarray = convert(Csize_t, len)
szfile = szarray + convert(Csize_t, offset)
szfile = szarray + convert(Csize_t, offset-offset_page)
mmaphandle = ccall(:CreateFileMappingW, stdcall, Ptr{Void}, (Ptr{Void}, Ptr{Void}, Cint, Cint, Cint, Ptr{Uint16}),
shandle.handle, C_NULL, flprotect, szfile>>32, szfile&0xffffffff, C_NULL)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from reading msdn, it appears that szfile here should = offset + szarray

or it can equal 0, without any actual cost (http://msdn.microsoft.com/en-us/library/windows/desktop/aa366542(v=vs.85).aspx)

replace 0xffffffff with typemax(Uint32)
add a test with a larger offset than 64k
use div(a, b) instead of ifloor(a/b)
@tkelman
Copy link
Contributor Author

tkelman commented Jun 14, 2014

Thanks @vtjnash, you clearly understand what you're reading on MSDN better than I do. Your recommended changes fixed mmap_array with a greater-than-64k offset that was giving me trouble yesterday, so I put in another test for that. HDF5 problem not yet resolved, and still not sure about changing the meaning of jl_getpagesize. Would the current 4k page size have any use in any circumstances aside from mmap'ing (where it is the wrong number on Windows)?

@vtjnash
Copy link
Member

vtjnash commented Jun 14, 2014

I recently added support for printing error messages on windows (https://github.com/JuliaLang/julia/blob/master/base/env.jl#L14). It would be great if you could clean that up a bit and start using it everywhere we do calls to the windows API, so that we get better error messages.

@tkelman
Copy link
Contributor Author

tkelman commented Jun 14, 2014

Ooh, I like:

julia> b = [1]
1-element Array{Int64,1}:
 1
julia> msync(pointer(b), 6)
ERROR: could not msync: Attempt to access invalid address.
 in error at error.jl:21
 in msync at mmap.jl:168

that was by changing the error message to error("could not msync: $(FormatMessage())")

@vtjnash
Copy link
Member

vtjnash commented Jun 14, 2014

this looks good to merge. I can't quite follow the HDF5 issue, however, if that is still a problem.

@tkelman
Copy link
Contributor Author

tkelman commented Jun 14, 2014

The HDF5 issue seems to be a combination of different permissions when Julia is run non-interactively (something fishy with environment variables in spawned processes maybe?), and an endianness problem. something particular to the HDF5 API

@timholy
Copy link
Member

timholy commented Jun 15, 2014

That's definitely not an endianness issue; if it were, the result would be 0x04030201 (i.e., the bytes in the opposite order).

@tkelman
Copy link
Contributor Author

tkelman commented Jun 15, 2014

hm, okay. well the bytes are in reverse order in the .jld file, but that's true for both linux and windows hdf5...

@timholy
Copy link
Member

timholy commented Jun 15, 2014

OK, the HDF5 problem has been debugged to the point that I suspect this can be merged.

timholy added a commit that referenced this pull request Jun 15, 2014
Fix mmap_array with offset on Windows
@timholy timholy merged commit af0d727 into JuliaLang:master Jun 15, 2014
@tkelman tkelman deleted the mmap_windows branch June 15, 2014 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot memory map with offset under Win7
4 participants