-
Notifications
You must be signed in to change notification settings - Fork 290
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
Add support for fully hibernate-able Wasm instances #968
Comments
Hi @mamidon , thank you for the feature request. Wasmi currently supports resumable functions to a limited extend when used as library. It should be possible to support fuel metering for resumable functions in Wasmi in order to make it possible to use fuel as a kind of ticker and refuel the process continuously. Would this satisfy your use case? I am hesistant to add this functionality to the Wasmi CLI though since that would require to come up with binary formats and (de)serialisation support which is hard to get right and a huge amount of work imo. |
Howdy @Robbepop, I have no particular requests for Wasmi's CLI, the above was just an example of what would be possible. My only requirement (spec wise, obviously this is your project!) is the ability to serialize state between calls. This implies storing all abstract WebAssembly state (Store, Instance memory, etc) plus enough Wasmi specific state to rehydrate. Supporting resumable functions 'just' means more state to persist & restore. Using the library as an example, loosely this might look like:
You're correct that figuring out exactly what all this state is & how to serialize it is a heavy lift. I'd be happy to work out a detailed design (including what supporting resumable functions requires) and with your sign off, subsequently contribute the implementation. WRT preformance regressions, I don't think this should be a problem -- serializing & deserializing should happen out of band to WASM execution, although I'm not so certain that support for resumable functions won't require runtime book keeping. |
Okay, I see the difference is that resumable functions only persist state of a single execution and what you want is to persist the state of an entire Wasm instance. Also this is probably not going to support resumable functions as to not introduce inefficiencies in the executor. Also I think it is fine not to support resumable function calls as a resumable function call is simply one that was stopped but all of its altered state has been written down when it did. And this state is what we capture. Maybe it is possible to support resumable functions without introducing performance regressions. At this point though I would not want to promise you to merge any of that. So in the worst case you'd end up with a fork of Wasmi that supports hibernatable Wasm instances and I am sure it would work. In the best case the work is great, docs are fine, it does not introduce perf regressions and we find it useful enough for the greater community to merge it to Wasmi. Currently Wasmi So under these conditions feel free to do the work and let's see where this is heading. :) |
Outstanding, I hope you've had a wonderful Easter weekend! I got the memo last week that I'm going to be laid off, so I'll sort out my |
I am sorry to hear about your job situation and wish you all the best to sort it out. Feel free to re-open when you are ready again. |
Don't worry, I've already got a few interview loops going. I'm just a stickler for remote, and refused to return to office lol. |
'Right, I'm back on this. I think I've got a reasonable approach, from the POV of WASM standards. Persisting a WASM Instance, between function calls -- no state on the implicit stack, is equivalent to taking the module definition and changing it as follows:
I think that's about it. Roughly, the public API in WASMI might look like:
Actually persisting the module to disk is left as an exercise to the reader, but it should be straightforward to create a fully valid WASM file with all the segments, or one which doesn't have redundant data (like code) if you have the original module file. |
I am trying to use WASM for video game modding, so I will have to persist instance state across save&load sooner or later. But I'm not sure I understand what the problem is, can't you just save the instance's memory as bytes and then load those bytes later? You can do that right now with the existing memory API (assuming the host can (re)allocate memory of arbitrary size). I have no idea how resumable functions work, though. I have thought about two use cases: first, host imported function could "return early", returning the execution flow directly to the caller without going through the wasm code, while informing the caller that this has happened. The caller could then resume from that point at a later time. This could be very useful for setting debugging breakpoints. Second, when running out out of fuel, the caller would once again be infromed that this has heppened and could resume from that point after inserting more fuel. I have no idea if fuel works like this, I have never used it yet. If I understand this correctly, the issue is then to correctly persist these "save points" from which the host can resume later? |
I'm looking to build a runtime, based on WebAssembly, which provides image-like semantics. This requires persisting the state of WASM instance(s) across process boundaries.
If
wasmi_cli
were to support this, it might look sort of like this:whereas today, without persisting runtime state you'd get something like this:
This doesn't actually require pre-emption, which seems to be blocked, 'just' the ability to serialize instance runtime state & create an instance via that state vs. the usual module -> link -> instantiate flow.
Is this something WASMI would be interested in supporting? If so, I'd be happy to contribute it myself.
The text was updated successfully, but these errors were encountered: