Skip to content

Conversation

@Shillaker
Copy link
Collaborator

When an executor completes a function execution it calls reset on a Faaslet, which in turn calls reset on the wasm module.

A while ago I switched WAVM-based wasm modules to use a "base snapshot" to restore during reset, which avoids doing a (slow) memcpy of the whole memory. However, in PR #411 I accidentally removed this, so all WAVM-based wasm modules are doing a full memcpy at the end of each execution (as noted by @KubaSz offline).

This restores the snapshotting, which greatly reduces the reset time for modules, but does so at a per-function level in the Faaslet itself, which makes it potentially reusable in WAMR-based wasm modules too.

@Shillaker Shillaker self-assigned this Oct 11, 2021
@eigenraven
Copy link
Collaborator

One thing to take into consideration here is that when doing my migration work I had to add globals to the snapshotted state. I think for a successful execution the stack pointer (in global 0) at the end will be the same, but when migrating functions I had to add it to the snapshotted state to prevent memory corruption - the other mutable wasm structure is tables, but I'm pretty sure C compilers don't generate table mutations so it's not critical for snapshots to work properly.

@Shillaker
Copy link
Collaborator Author

Yes very good point; wherever we use the term "snapshot", we are currently referring only to a copy of the linear memory and not globals or the function table. As you say, the stack pointer should go back to zero after each execution, so ought not to be a problem in this instance where we're resetting after a completed execution. You're right that the table won't be changed under normal circumstances, but it will be modified when we perform dynamic linking. Migrating a function that has performed some dynamic linking would require adding the modified table to the snapshot, as well as loading the relevant dynamically linked modules on the target machine in advance of continuing execution.

@Shillaker Shillaker marked this pull request as ready for review October 12, 2021 10:54
@Shillaker Shillaker merged commit 10b1ba2 into master Oct 12, 2021
@Shillaker Shillaker deleted the snapshot-reset branch October 12, 2021 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants