Skip to content
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

Avoid copies / blowing up the stack when initializing large structures #65

Open
abrestic-rivos opened this issue Aug 22, 2022 · 1 comment

Comments

@abrestic-rivos
Copy link
Collaborator

We have a few large structs (Vm, VmCpu) that we place in Page containers but, in the absence of guaranteed copy elision, we may end up with the struct being constructed on the stack and then copied into the page. And in fact, this is exactly what appears to be happening currently with VmCpu. This is going to become more of a problem as we add more per-vCPU state: vector state, PMU, IMSIC, etc.

We should consider initializing these structs in-place. Unfortunately Rust does not have support for a "placement new" or "emplace" so it looks like the best we can do right now is MaybeUninit + a bunch of unsafe.

@abrestic-rivos
Copy link
Collaborator Author

A couple notes:

  • Vm::finalize() and VmPages::finalize() effectively turn into a huge memcpy(). I don't see a good way to avoid this with the type-state pattern; we may need an alternate approach to type-safe Vm states.
  • The moveit crate, or something like it, might be of use to us here for in-place construction.

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

No branches or pull requests

1 participant