A hopefully quick question. My understanding is that Wasmtime uses mmap
in 3 places:
memory.grow
, load
and store
instructions and friends).mmap
.There are currently configuration options to use custom allocators from embedders for 2 and 3.
Does that sound correct? Are there other locations where mmap
is used? Thanks in advance!
two other cases off the top of my head:
malloc
for various things which will call mmap
mmap
can be used for cow memory imageswasmtime will call malloc for various things which will call mmap
Is this different than usage of Rust allocator?
nope
Cool - thanks! That was all I wanted to double check. Appreciate the rapid response :thumbs_up:
https://docs.rs/wasmtime/latest/wasmtime/struct.Config.html#method.memory_init_cow
^ info about the cow memory images
Thanks I was just going to look that up.
Do you have a code pointer for where this happens (no worries I can also go hunt it down)
Is that it?
Does that still work if with_host_memory
is being used?
Looks like not: https://github.com/bytecodealliance/wasmtime/blob/738d41eaf2e257f776dc5643b19e41ae0a3e2700/crates/wasmtime/src/trampoline/memory.rs#L127
I haven't ever actually poked at the cow memory images implementation myself, so I'd just do exactly what you are doing to answer these questions, which is dig in and read the code
so: good luck!
Seems like if a custom host memory is being used those cow images should be disabled. Anyways, thanks for the help! Looks like I should plumb another config option through the C-API
Tyler Rockwood has marked this topic as resolved.
I haven't dug into the low-level details, but my high level understanding is that when you instantiate a module or component from a .cwasm file, Wasmtime will try to COW the memory image in that file.
One thing perhaps worth noting is that whilen COW uses mmap it always does so with MMAP_FIXED. If your custom host memory is not page aligned then you should disable COW
Custom host memory doesn't support COW at all, so I wonder if we should have the config assert that cow is not on with custom host memory.
that's a good point yeah, that should probably assert that it's None
and whenever a custom memory is set in Config
it additionally validates that cow is disabled
Last updated: Nov 22 2024 at 17:03 UTC