alexcrichton requested peterhuene for a review on PR #3266.
alexcrichton opened PR #3266 from deserialize-file
to main
:
This commit adds a new method to the
wasmtime::Module
type,
deserialize_file
. This is intended to be the same as thedeserialize
method except for the serialized module is present as an on-disk file.
This enables Wasmtime to internally usemmap
to avoid copying bytes
around and generally makes loading a module much faster.A C API is added in this commit as well for various bindings to use this
accelerated path now as well. Another option perhaps for a Rust-based
API is to have an API taking aFile
itself to allow for a custom file
descriptor in one way or another, but for now that's left for a possible
future refactoring if we find a use case.cc #3230
alexcrichton updated PR #3266 from deserialize-file
to main
.
peterhuene submitted PR review.
peterhuene submitted PR review.
peterhuene created PR review comment:
Same comment as above re: path to file.
peterhuene created PR review comment:
Can we include the path to the file in the context here?
peterhuene created PR review comment:
Same comment as above re: path to file.
peterhuene created PR review comment:
We'll definitely want to use
OpenOptions::share_mode
(withFILE_SHARE_READ
probably) to open the file on Windows to prevent write access to the file so another process can't write to it while we have it mapped.
peterhuene created PR review comment:
Nit: preference for
with_context
here given theformat!
?
peterhuene created PR review comment:
I think we might need
FILE_MAP_COPY
here so that if we handle any relocations in the text section, the pages become private (and backed with the page file) rather than modifying the share pages which ultimately get flushed to the backed file (the precompiled module in this case).
peterhuene created PR review comment:
Nit: preference for
with_context
here given theformat!
?
peterhuene created PR review comment:
I think we probably want this to be
PAGE_EXECUTE_READ
with aFILE_MAP_COPY
below.
peterhuene created PR review comment:
I'm actually really surprised this would work on Windows when the mapped file was opened
FILE_GENERIC_READ
as changing the protection level of the mapped pages would bypass file system access rights.
peterhuene created PR review comment:
Nit: preference for
with_context
here given theformat!
?
peterhuene submitted PR review.
peterhuene created PR review comment:
Doh:
When copy-on-write access is specified, the system and process commit charge taken is for the entire view
because the calling process can potentially write to every page in the view, making all pages private.We're going to need separate mapped views for the file, one specifically for the text section that's mapped
FILE_MAP_READ
,FILE_MAP_COPY
, andFILE_MAP_EXECUTE
.
peterhuene edited PR review comment.
peterhuene edited PR review comment.
peterhuene edited PR review comment.
peterhuene submitted PR review.
peterhuene created PR review comment:
Alternatively, I think we may be able to keep the single view, but change the protection level of the text section's pages to
PAGE_EXECUTE_WRITECOPY
during relocation, provided the mapping was created withPAGE_EXECUTE_READ
?I'd have to experiment a bit.
peterhuene edited PR review comment.
peterhuene edited PR review comment.
alexcrichton updated PR #3266 from deserialize-file
to main
.
alexcrichton submitted PR review.
alexcrichton created PR review comment:
Oh this is already guarded by the
if
so this only gets executed in the error path anyway (and the closure would always be executed in this case)
alexcrichton submitted PR review.
alexcrichton created PR review comment:
I opted to add this context a layer above to avoid having to include it in all the error messages here (if you're ok with that since at least for now it's only called in one location)
peterhuene submitted PR review.
peterhuene created PR review comment:
Excellent point. My brain was just over zealous in seeing work done in a
context
call.
peterhuene submitted PR review.
alexcrichton merged PR #3266.
Last updated: Nov 22 2024 at 17:03 UTC