memory-control icon indicating copy to clipboard operation
memory-control copied to clipboard

Sub-proposal: `virtual` mode

Open bvisness opened this issue 1 year ago • 4 comments

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.

bvisness avatar Aug 16 '24 15:08 bvisness

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.

programmerjake avatar Sep 11 '24 19:09 programmerjake

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.

bvisness avatar Sep 11 '24 22:09 bvisness

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.

SingleAccretion avatar Sep 12 '24 11:09 SingleAccretion

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.

bvisness avatar Sep 12 '24 14:09 bvisness