vmm: add mmap memory restore mode#1
Open
CMGS wants to merge 2 commits into
Open
Conversation
Restore guest RAM by mapping the snapshot memory file copy-on-write over the still-unconsumed private anonymous guest mappings, before any KVM memslot, device or thread consumes them. Nothing is copied up front, pages fault in from the page cache — so VMs restored from the same snapshot share it — and guest writes stay private per VM. Because the mapping is established at region-creation time rather than overlaid after the fact, it does not hit the mapping-identity problems that motivated removing the original 2020 CoW-restore path or rejecting an mmap overlay. Opt-in via memory_restore_mode=mmap; the default Copy path is unchanged. The overlay is confined to plain private-anonymous regions (checked per region via file_offset), re-applies the region reserve and THP policy, and rejects a snapshot file shorter than the saved ranges. Shared or hugepage RAM (global or per-zone), non-page-aligned or multi-region ranges, device passthrough, and NUMA-bound zones fall back to the eager copy. The snapshot file must remain on disk for the VM lifetime. Measured on a 16-core host (same binary, only memory_restore_mode switched, 3 interleaved rounds, 512MB guest): serial clone p50 54-58ms -> 22-35ms; 16-way burst per-clone p50 443-463ms -> 72-82ms (-82%), wall 456-478ms -> 87-108ms. Cloned VMs boot and exec normally.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a third
memory_restore_modevalue,mmap: restore guest RAM by mapping the snapshot memory file copy-on-write over the still-unconsumed private anonymous guest mappings, before any KVM memslot, device or thread consumes them. Nothing is copied up front, pages fault in from the page cache — so VMs restored from the same snapshot share it — and guest writes stay private per VM. Opt-in; the defaultcopypath is byte-for-byte unchanged.Why this does not hit the historical mmap objections
Constraint gate (falls back to eager copy, logged)
file_offset(); only plain private-anonymous regions are overlaid.--device/--user-device),--pvmemcontrol, KSM (mergeable=on), resizable RAM (hotplug_size), and zones with numa/reserve/mergeable/hotplug attributes. A purely staticid+sizezone takes the mmap path.prefaultis rejected;reserve/THP policy is re-applied to the mapped region.ondemand; documented).Evidence
cargo fmt --check0 diff;cargo clippy -p vmm --features kvm --all-targets -- -D warningsclean (alsokvm,pvmemcontrol); 4 unit tests cover CoW mapping + hole-reads-zero + CoW isolation, file-backed-region rejection, unaligned/spanning rejection, reserve/THP path.