I'm trying to implement a VM snapshot & resume feature in a VM manager app. For some reason, both saveMachineStateTo and restoreMachineStateFrom to save machine memory to a file and restore saved vzstate/memory back for a VM is taking a lot of time on my system (XCode 26.3, macOS 15.7.7). The test VM has only sizes in the range of 4-8GB RAM.
Any tips or tricky to speed it up, for example, do like a CoW on the RAM so VM can be briefly paused and quickly resumed after while streaming the RAM in background? Or, any other ways for example for RAM compression, dirty-page tracking, or live/background RAM streaming to a file?
Or, to instrument and dig deeper, what's taking time?
Thank you.
The short answer here is “No.”
I pinged the Virtualization team about this, and learnt some fascinating facts about how it works under the covers, but that doesn’t help with this problem. The Virtualization API is very high-level, and thus there’s not a lot wiggle room for you to explore improvements.
The speed is likely to be determined by the size of the guest’s RAM, and a few seconds is certainly expected. Is that inline with your “taking a lot of time” comment? Or is a way more than that?
Also, it’d definitely be worthwhile filing a bug about this. It seems likely that there’s stuff we could do to speed things up. If you do file a bug, there’s a few things I recommend that you do to improve its chances of gaining traction:
- If you have the time, try to reproduce the issue with Virtualization sample code. That’ll confirm that the bottleneck is in Apple stuff, and unrelated to your code.
- Then attach the tweaked sample to your bug. That’ll give us a clear understanding of your configuration. If you can’t do this, please describe the configuration in your bug’s text.
- Reproduce the problem and then trigger a sysdiagnose, to capture all the surrounding state.
- And for bonus extra credit, reproduce the problem again from within Instruments and include that trace.
Once you’re done, post your bug number, just for the record.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"