WebAssembly / memory-control

A proposal to introduce finer grained control of WebAssembly memory.
Other
37 stars 2 forks source link

Sub-proposal: `virtual` mode #18

Open bvisness opened 3 months ago

bvisness commented 3 months ago

This issue tracks discussion of the virtual mode sub-proposal. This proposal is one possible component of the eventual Memory Control MVP. Please make sure to read the full sub-proposal document.

programmerjake commented 2 months ago

https://github.com/WebAssembly/memory-control/blob/16dd6b93ab82d0b4b252e3da5451e9b5e452ee62/proposals/memory-control/virtual.md#L80

I don't think you can use munmap since iirc that would let the host put unrelated allocations in the memory range that was supposed to be reserved for the wasm instance.

bvisness commented 2 months ago

I think you're right, and the "unmap" operation should probably be implemented by another PROT_NONE instead. As far as I'm aware, this should free any physical resources and reduce commit.

SingleAccretion commented 2 months ago

Why is it important for the failure mode of the instructions (primarily memory.map) to be "always trap"?

It limits the ability of the WASM application to handle error conditions like out of memory gracefully. Consider, for example, that malloc is supposed to return null if it fails to allocate. Or consider a linear memory GC that can initiate an aggressive older generation collection if it finds itself unable to allocate (commit) more memory (not a hypothetical scenario: I am writing this on a machine where a variant of this mechanism allows multiple IDE instances to be simultaneously opened and the system to still work well).

Edit: memory.grow also doesn't trap on an OOM condition, it returns -1.

bvisness commented 2 months ago

Yeah, that's also a good point. Returning -1 could probably work just fine for memory.map as well.

I'm not sure that the other operations need to return error codes, but if they can reasonably fail under normal conditions, perhaps they should. Off the top of my head, though, I'm not aware though of any failures cases that would arise from correct use of system memory APIs after the memory has already been mapped.