vmm: memory_manager: add userfaultfd demand-paged snapshot restore - #7800
Conversation
|
Requesting review from folks who I have seen active in previous similar conversations 🙏🏾 |
4b08c0e to
7b853b3
Compare
rbradford
left a comment
There was a problem hiding this comment.
Thanks for your contribution - just a quick review initially! Perhaps also split out the bindings and abstraction module into their own commits to make the changes that touch the common code easier to review.
(Could even go for further and move API changes out too.)
Also I don't see changes to ch-remote.
|
@rbradford Thanks for reviewing so promptly. We're hoping to get uffd in to CH to enable some really powerful features! |
Thank you for your contribution - i'm looking forward to seeing this feature land too. |
|
I thoroughly reviewed the code and added my comments. Overall very happy with the code, great work @shayonj . |
9555092 to
93e698f
Compare
|
Thank you for the reviews @rbradford and @DamianB-BitFlipper . I think I addressed all of them and left a few open for discussion.
This is also addressed now. Let me know if it's not clear.
I blelieve ch-remote delegates to I also ran a before/after comparison of a restore from snapshot on a GCE n2-standard-8 (2GB guest raw snapshot, 3 iterations each):
Showing some promising figures. |
9b2134b to
1e6d13a
Compare
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 being overlaid after the fact, it does not hit the mapping-identity problems that motivated removing the original 2020 CoW-restore path (a60b437) or rejecting an mmap overlay during the on-demand restore work (cloud-hypervisor#7800). 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), zones with numa/reserve/mergeable/ hotplug attributes, resizable RAM, KSM, pvmemcontrol and device passthrough fall back to the eager copy. The snapshot file must remain on disk and unchanged for the VM lifetime. Measured on a 16-core x86_64 host (512 MiB guests, same binary, only the mode switched, 3 interleaved rounds): single restore p50 54-58ms -> 22-35ms; 16 concurrent restores from one snapshot: per-restore p50 443-463ms -> 72-82ms, wall 456-478ms -> 87-108ms. Restored VMs boot and run normally. Signed-off-by: CMGS <[email protected]>
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 being overlaid after the fact, it does not hit the mapping-identity problems that motivated removing the original 2020 CoW-restore path (a60b437) or rejecting an mmap overlay during the on-demand restore work (cloud-hypervisor#7800). 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), zones with numa/reserve/mergeable/ hotplug attributes, resizable RAM, KSM, pvmemcontrol and device passthrough fall back to the eager copy. The snapshot file must remain on disk and unchanged for the VM lifetime. Measured on a 16-core x86_64 host (512 MiB guests, same binary, only the mode switched, 3 interleaved rounds): single restore p50 54-58ms -> 22-35ms; 16 concurrent restores from one snapshot: per-restore p50 443-463ms -> 72-82ms, wall 456-478ms -> 87-108ms. Restored VMs boot and run normally. Signed-off-by: CMGS <[email protected]>
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 being overlaid after the fact, it does not hit the mapping-identity problems that motivated removing the original 2020 CoW-restore path (a60b437) or rejecting an mmap overlay during the on-demand restore work (cloud-hypervisor#7800). 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), zones with numa/reserve/mergeable/ hotplug attributes, resizable RAM, KSM, pvmemcontrol and device passthrough fall back to the eager copy. The snapshot file must remain on disk and unchanged for the VM lifetime. Measured on a 16-core x86_64 host (512 MiB guests, same binary, only the mode switched, 3 interleaved rounds): single restore p50 54-58ms -> 22-35ms; 16 concurrent restores from one snapshot: per-restore p50 443-463ms -> 72-82ms, wall 456-478ms -> 87-108ms. Restored VMs boot and run normally. Signed-off-by: CMGS <[email protected]>
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 being overlaid after the fact, it does not hit the mapping-identity problems that motivated removing the original 2020 CoW-restore path (a60b437) or rejecting an mmap overlay during the on-demand restore work (cloud-hypervisor#7800). Opt-in via memory_restore_mode=copyonwrite; 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), zones with numa/reserve/ mergeable/hotplug attributes, resizable RAM, KSM, pvmemcontrol and device passthrough fall back to the eager copy. The snapshot file must remain on disk and unchanged for the VM lifetime. Measured on a 16-core x86_64 host (512 MiB guests, same binary, only the mode switched, 3 interleaved rounds): single restore p50 54-58ms -> 22-35ms; 16 concurrent restores from one snapshot: per-restore p50 443-463ms -> 72-82ms, wall 456-478ms -> 87-108ms. Restored VMs boot and run normally. Signed-off-by: CMGS <[email protected]>
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 being overlaid after the fact, it does not hit the mapping-identity problems that motivated removing the original 2020 CoW-restore path (a60b437) or rejecting an mmap overlay during the on-demand restore work (cloud-hypervisor#7800). Opt-in via memory_restore_mode=copyonwrite; 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), zones with numa/reserve/ mergeable/hotplug attributes, resizable RAM, KSM, pvmemcontrol and device passthrough fall back to the eager copy. The snapshot file must remain on disk and unchanged for the VM lifetime. Measured on a 16-core x86_64 host (512 MiB guests, same binary, only the mode switched, 3 interleaved rounds): single restore p50 54-58ms -> 22-35ms; 16 concurrent restores from one snapshot: per-restore p50 443-463ms -> 72-82ms, wall 456-478ms -> 87-108ms. Restored VMs boot and run normally. Signed-off-by: CMGS <[email protected]>
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 being overlaid after the fact, it does not hit the mapping-identity problems that motivated removing the original 2020 CoW-restore path (a60b437) or rejecting an mmap overlay during the on-demand restore work (cloud-hypervisor#7800). Opt-in via memory_restore_mode=copyonwrite; 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), zones with numa/reserve/ mergeable/hotplug attributes, resizable RAM, KSM, pvmemcontrol and device passthrough fall back to the eager copy. The snapshot file must remain on disk and unchanged for the VM lifetime. Measured on a 16-core x86_64 host (512 MiB guests, same binary, only the mode switched, 3 interleaved rounds): single restore p50 54-58ms -> 22-35ms; 16 concurrent restores from one snapshot: per-restore p50 443-463ms -> 72-82ms, wall 456-478ms -> 87-108ms. Restored VMs boot and run normally. Signed-off-by: CMGS <[email protected]>
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 being overlaid after the fact, it does not hit the mapping-identity problems that motivated removing the original 2020 CoW-restore path (a60b437) or rejecting an mmap overlay during the on-demand restore work (cloud-hypervisor#7800). Opt-in via memory_restore_mode=copyonwrite; 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), zones with numa/reserve/ mergeable/hotplug attributes, resizable RAM, KSM, pvmemcontrol and device passthrough fall back to the eager copy. The snapshot file must remain on disk and unchanged for the VM lifetime. Measured on a 16-core x86_64 host (512 MiB guests, same binary, only the mode switched, 3 interleaved rounds): single restore p50 54-58ms -> 22-35ms; 16 concurrent restores from one snapshot: per-restore p50 443-463ms -> 72-82ms, wall 456-478ms -> 87-108ms. Restored VMs boot and run normally. Signed-off-by: CMGS <[email protected]>
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 being overlaid after the fact, it does not hit the mapping-identity problems that motivated removing the original 2020 CoW-restore path (a60b437) or rejecting an mmap overlay during the on-demand restore work (cloud-hypervisor#7800). Opt-in via memory_restore_mode=copyonwrite; 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), zones with numa/reserve/ mergeable/hotplug attributes, resizable RAM, KSM, pvmemcontrol and device passthrough fall back to the eager copy. The snapshot file must remain on disk and unchanged for the VM lifetime. Measured on a 16-core x86_64 host (512 MiB guests, same binary, only the mode switched, 3 interleaved rounds): single restore p50 54-58ms -> 22-35ms; 16 concurrent restores from one snapshot: per-restore p50 443-463ms -> 72-82ms, wall 456-478ms -> 87-108ms. Restored VMs boot and run normally. Signed-off-by: CMGS <[email protected]>
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 being overlaid after the fact, it does not hit the mapping-identity problems that motivated removing the original 2020 CoW-restore path (a60b437) or rejecting an mmap overlay during the on-demand restore work (cloud-hypervisor#7800). Opt-in via memory_restore_mode=copyonwrite; 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), zones with numa/reserve/ mergeable/hotplug attributes, resizable RAM, KSM, pvmemcontrol and device passthrough fall back to the eager copy. The snapshot file must remain on disk and unchanged for the VM lifetime. Measured on a 16-core x86_64 host (512 MiB guests, same binary, only the mode switched, 3 interleaved rounds): single restore p50 54-58ms -> 22-35ms; 16 concurrent restores from one snapshot: per-restore p50 443-463ms -> 72-82ms, wall 456-478ms -> 87-108ms. Restored VMs boot and run normally. Signed-off-by: CMGS <[email protected]>
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 being overlaid after the fact, it does not hit the mapping-identity problems that motivated removing the original 2020 CoW-restore path (a60b437) or rejecting an mmap overlay during the on-demand restore work (cloud-hypervisor#7800). Opt-in via memory_restore_mode=copyonwrite; 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), zones with numa/reserve/ mergeable/hotplug attributes, resizable RAM, KSM, pvmemcontrol and device passthrough fall back to the eager copy. The snapshot file must remain on disk and unchanged for the VM lifetime. Measured on a 16-core x86_64 host (512 MiB guests, same binary, only the mode switched, 3 interleaved rounds): single restore p50 54-58ms -> 22-35ms; 16 concurrent restores from one snapshot: per-restore p50 443-463ms -> 72-82ms, wall 456-478ms -> 87-108ms. Restored VMs boot and run normally. Signed-off-by: CMGS <[email protected]>
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 being overlaid after the fact, it does not hit the mapping-identity problems that motivated removing the original 2020 CoW-restore path (a60b437) or rejecting an mmap overlay during the on-demand restore work (cloud-hypervisor#7800). Opt-in via memory_restore_mode=copyonwrite; 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), zones with numa/reserve/ mergeable/hotplug attributes, resizable RAM, KSM, pvmemcontrol and device passthrough fall back to the eager copy. The snapshot file must remain on disk and unchanged for the VM lifetime. Measured on a 16-core x86_64 host (512 MiB guests, same binary, only the mode switched, 3 interleaved rounds): single restore p50 54-58ms -> 22-35ms; 16 concurrent restores from one snapshot: per-restore p50 443-463ms -> 72-82ms, wall 456-478ms -> 87-108ms. Restored VMs boot and run normally. Signed-off-by: CMGS <[email protected]>
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 being overlaid after the fact, it does not hit the mapping-identity problems that motivated removing the original 2020 CoW-restore path (a60b437) or rejecting an mmap overlay during the on-demand restore work (cloud-hypervisor#7800). Opt-in via memory_restore_mode=copyonwrite; 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), zones with numa/reserve/ mergeable/hotplug attributes, resizable RAM, KSM, pvmemcontrol and device passthrough fall back to the eager copy. The snapshot file must remain on disk and unchanged for the VM lifetime. Measured on a 16-core x86_64 host (512 MiB guests, same binary, only the mode switched, 3 interleaved rounds): single restore p50 54-58ms -> 22-35ms; 16 concurrent restores from one snapshot: per-restore p50 443-463ms -> 72-82ms, wall 456-478ms -> 87-108ms. Restored VMs boot and run normally. Signed-off-by: CMGS <[email protected]>
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 being overlaid after the fact, it does not hit the mapping-identity problems that motivated removing the original 2020 CoW-restore path (a60b437) or rejecting an mmap overlay during the on-demand restore work (cloud-hypervisor#7800). Opt-in via memory_restore_mode=copyonwrite; 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), zones with numa/reserve/ mergeable/hotplug attributes, resizable RAM, KSM, pvmemcontrol and device passthrough fall back to the eager copy. The snapshot file must remain on disk and unchanged for the VM lifetime. Measured on a 16-core x86_64 host (512 MiB guests, same binary, only the mode switched, 3 interleaved rounds): single restore p50 54-58ms -> 22-35ms; 16 concurrent restores from one snapshot: per-restore p50 443-463ms -> 72-82ms, wall 456-478ms -> 87-108ms. Restored VMs boot and run normally. Signed-off-by: CMGS <[email protected]>
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 being overlaid after the fact, it does not hit the mapping-identity problems that motivated removing the original 2020 CoW-restore path (a60b437) or rejecting an mmap overlay during the on-demand restore work (cloud-hypervisor#7800). Opt-in via memory_restore_mode=copyonwrite; 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), zones with numa/reserve/ mergeable/hotplug attributes, resizable RAM, KSM, pvmemcontrol and device passthrough fall back to the eager copy. The snapshot file must remain on disk and unchanged for the VM lifetime. Measured on a 16-core x86_64 host (512 MiB guests, same binary, only the mode switched, 3 interleaved rounds): single restore p50 54-58ms -> 22-35ms; 16 concurrent restores from one snapshot: per-restore p50 443-463ms -> 72-82ms, wall 456-478ms -> 87-108ms. Restored VMs boot and run normally. Signed-off-by: CMGS <[email protected]>
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 being overlaid after the fact, it does not hit the mapping-identity problems that motivated removing the original 2020 CoW-restore path (a60b437) or rejecting an mmap overlay during the on-demand restore work (cloud-hypervisor#7800). Opt-in via memory_restore_mode=copyonwrite; 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), zones with numa/reserve/ mergeable/hotplug attributes, resizable RAM, KSM, pvmemcontrol and device passthrough fall back to the eager copy. The snapshot file must remain on disk and unchanged for the VM lifetime. Measured on a 16-core x86_64 host (512 MiB guests, same binary, only the mode switched, 3 interleaved rounds): single restore p50 54-58ms -> 22-35ms; 16 concurrent restores from one snapshot: per-restore p50 443-463ms -> 72-82ms, wall 456-478ms -> 87-108ms. Restored VMs boot and run normally. Signed-off-by: CMGS <[email protected]>
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 being overlaid after the fact, it does not hit the mapping-identity problems that motivated removing the original 2020 CoW-restore path (a60b437) or rejecting an mmap overlay during the on-demand restore work (cloud-hypervisor#7800). Opt-in via memory_restore_mode=copyonwrite; 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), zones with numa/reserve/ mergeable/hotplug attributes, resizable RAM, KSM, pvmemcontrol and device passthrough fall back to the eager copy. The snapshot file must remain on disk and unchanged for the VM lifetime. Measured on a 16-core x86_64 host (512 MiB guests, same binary, only the mode switched, 3 interleaved rounds): single restore p50 54-58ms -> 22-35ms; 16 concurrent restores from one snapshot: per-restore p50 443-463ms -> 72-82ms, wall 456-478ms -> 87-108ms. Restored VMs boot and run normally. Signed-off-by: CMGS <[email protected]>
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 being overlaid after the fact, it does not hit the mapping-identity problems that motivated removing the original 2020 CoW-restore path (a60b437) or rejecting an mmap overlay during the on-demand restore work (cloud-hypervisor#7800). Opt-in via memory_restore_mode=copyonwrite; 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), zones with numa/reserve/ mergeable/hotplug attributes, resizable RAM, KSM, pvmemcontrol and device passthrough fall back to the eager copy. The snapshot file must remain on disk and unchanged for the VM lifetime. Measured on a 16-core x86_64 host (512 MiB guests, same binary, only the mode switched, 3 interleaved rounds): single restore p50 54-58ms -> 22-35ms; 16 concurrent restores from one snapshot: per-restore p50 443-463ms -> 72-82ms, wall 456-478ms -> 87-108ms. Restored VMs boot and run normally. Signed-off-by: CMGS <[email protected]>
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 being overlaid after the fact, it does not hit the mapping-identity problems that motivated removing the original 2020 CoW-restore path (a60b437) or rejecting an mmap overlay during the on-demand restore work (cloud-hypervisor#7800). Opt-in via memory_restore_mode=copyonwrite; 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), zones with numa/reserve/ mergeable/hotplug attributes, resizable RAM, KSM, pvmemcontrol and device passthrough fall back to the eager copy. The snapshot file must remain on disk and unchanged for the VM lifetime. Measured on a 16-core x86_64 host (512 MiB guests, same binary, only the mode switched, 3 interleaved rounds): single restore p50 54-58ms -> 22-35ms; 16 concurrent restores from one snapshot: per-restore p50 443-463ms -> 72-82ms, wall 456-478ms -> 87-108ms. Restored VMs boot and run normally. Signed-off-by: CMGS <[email protected]>
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 being overlaid after the fact, it does not hit the mapping-identity problems that motivated removing the original 2020 CoW-restore path (a60b437) or rejecting an mmap overlay during the on-demand restore work (cloud-hypervisor#7800). Opt-in via memory_restore_mode=copyonwrite; 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), zones with numa/reserve/ mergeable/hotplug attributes, resizable RAM, KSM, pvmemcontrol and device passthrough fall back to the eager copy. The snapshot file must remain on disk and unchanged for the VM lifetime. Measured on a 16-core x86_64 host (512 MiB guests, same binary, only the mode switched, 3 interleaved rounds): single restore p50 54-58ms -> 22-35ms; 16 concurrent restores from one snapshot: per-restore p50 443-463ms -> 72-82ms, wall 456-478ms -> 87-108ms. Restored VMs boot and run normally. Signed-off-by: CMGS <[email protected]>
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 being overlaid after the fact, it does not hit the mapping-identity problems that motivated removing the original 2020 CoW-restore path (a60b437) or rejecting an mmap overlay during the on-demand restore work (cloud-hypervisor#7800). Opt-in via memory_restore_mode=copyonwrite; 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), zones with numa/reserve/ mergeable/hotplug attributes, resizable RAM, KSM, pvmemcontrol and device passthrough fall back to the eager copy. The snapshot file must remain on disk and unchanged for the VM lifetime. Measured on a 16-core x86_64 host (512 MiB guests, same binary, only the mode switched, 3 interleaved rounds): single restore p50 54-58ms -> 22-35ms; 16 concurrent restores from one snapshot: per-restore p50 443-463ms -> 72-82ms, wall 456-478ms -> 87-108ms. Restored VMs boot and run normally. Signed-off-by: CMGS <[email protected]>
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 being overlaid after the fact, it does not hit the mapping-identity problems that motivated removing the original 2020 CoW-restore path (a60b437) or rejecting an mmap overlay during the on-demand restore work (cloud-hypervisor#7800). Opt-in via memory_restore_mode=copyonwrite; 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), zones with numa/reserve/ mergeable/hotplug attributes, resizable RAM, KSM, pvmemcontrol and device passthrough fall back to the eager copy. The snapshot file must remain on disk and unchanged for the VM lifetime. Measured on a 16-core x86_64 host (512 MiB guests, same binary, only the mode switched, 3 interleaved rounds): single restore p50 54-58ms -> 22-35ms; 16 concurrent restores from one snapshot: per-restore p50 443-463ms -> 72-82ms, wall 456-478ms -> 87-108ms. Restored VMs boot and run normally. Signed-off-by: CMGS <[email protected]>
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 being overlaid after the fact, it does not hit the mapping-identity problems that motivated removing the original 2020 CoW-restore path (a60b437) or rejecting an mmap overlay during the on-demand restore work (cloud-hypervisor#7800). Opt-in via memory_restore_mode=copyonwrite; 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), zones with numa/reserve/ mergeable/hotplug attributes, resizable RAM, KSM, pvmemcontrol and device passthrough fall back to the eager copy. The snapshot file must remain on disk and unchanged for the VM lifetime. Measured on a 16-core x86_64 host (512 MiB guests, same binary, only the mode switched, 3 interleaved rounds): single restore p50 54-58ms -> 22-35ms; 16 concurrent restores from one snapshot: per-restore p50 443-463ms -> 72-82ms, wall 456-478ms -> 87-108ms. Restored VMs boot and run normally. Signed-off-by: CMGS <[email protected]>
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 being overlaid after the fact, it does not hit the mapping-identity problems that motivated removing the original 2020 CoW-restore path (a60b437) or rejecting an mmap overlay during the on-demand restore work (cloud-hypervisor#7800). Opt-in via memory_restore_mode=copyonwrite; 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), zones with numa/reserve/ mergeable/hotplug attributes, resizable RAM, KSM, pvmemcontrol and device passthrough fall back to the eager copy. The snapshot file must remain on disk and unchanged for the VM lifetime. Measured on a 16-core x86_64 host (512 MiB guests, same binary, only the mode switched, 3 interleaved rounds): single restore p50 54-58ms -> 22-35ms; 16 concurrent restores from one snapshot: per-restore p50 443-463ms -> 72-82ms, wall 456-478ms -> 87-108ms. Restored VMs boot and run normally. Signed-off-by: CMGS <[email protected]>
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 being overlaid after the fact, it does not hit the mapping-identity problems that motivated removing the original 2020 CoW-restore path (a60b437) or rejecting an mmap overlay during the on-demand restore work (cloud-hypervisor#7800). Opt-in via memory_restore_mode=copyonwrite; 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), zones with numa/reserve/ mergeable/hotplug attributes, resizable RAM, KSM, pvmemcontrol and device passthrough fall back to the eager copy. The snapshot file must remain on disk and unchanged for the VM lifetime. Measured on a 16-core x86_64 host (512 MiB guests, same binary, only the mode switched, 3 interleaved rounds): single restore p50 54-58ms -> 22-35ms; 16 concurrent restores from one snapshot: per-restore p50 443-463ms -> 72-82ms, wall 456-478ms -> 87-108ms. Restored VMs boot and run normally. Signed-off-by: CMGS <[email protected]>
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 being overlaid after the fact, it does not hit the mapping-identity problems that motivated removing the original 2020 CoW-restore path (a60b437) or rejecting an mmap overlay during the on-demand restore work (cloud-hypervisor#7800). Opt-in via memory_restore_mode=copyonwrite; 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), zones with numa/reserve/ mergeable/hotplug attributes, resizable RAM, KSM, pvmemcontrol and device passthrough fall back to the eager copy. The snapshot file must remain on disk and unchanged for the VM lifetime. Measured on a 16-core x86_64 host (512 MiB guests, same binary, only the mode switched, 3 interleaved rounds): single restore p50 54-58ms -> 22-35ms; 16 concurrent restores from one snapshot: per-restore p50 443-463ms -> 72-82ms, wall 456-478ms -> 87-108ms. Restored VMs boot and run normally. Signed-off-by: CMGS <[email protected]>
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 being overlaid after the fact, it does not hit the mapping-identity problems that motivated removing the original 2020 CoW-restore path (a60b437) or rejecting an mmap overlay during the on-demand restore work (cloud-hypervisor#7800). Opt-in via memory_restore_mode=copyonwrite; 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), zones with numa/reserve/ mergeable/hotplug attributes, resizable RAM, KSM, pvmemcontrol and device passthrough fall back to the eager copy. The snapshot file must remain on disk and unchanged for the VM lifetime. Measured on a 16-core x86_64 host (512 MiB guests, same binary, only the mode switched, 3 interleaved rounds): single restore p50 54-58ms -> 22-35ms; 16 concurrent restores from one snapshot: per-restore p50 443-463ms -> 72-82ms, wall 456-478ms -> 87-108ms. Restored VMs boot and run normally. Signed-off-by: CMGS <[email protected]>
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 being overlaid after the fact, it does not hit the mapping-identity problems that motivated removing the original 2020 CoW-restore path (a60b437) or rejecting an mmap overlay during the on-demand restore work (cloud-hypervisor#7800). Opt-in via memory_restore_mode=copyonwrite; 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), zones with numa/reserve/ mergeable/hotplug attributes, resizable RAM, KSM, pvmemcontrol and device passthrough fall back to the eager copy. The snapshot file must remain on disk and unchanged for the VM lifetime. Measured on a 16-core x86_64 host (512 MiB guests, same binary, only the mode switched, 3 interleaved rounds): single restore p50 54-58ms -> 22-35ms; 16 concurrent restores from one snapshot: per-restore p50 443-463ms -> 72-82ms, wall 456-478ms -> 87-108ms. Restored VMs boot and run normally. Signed-off-by: CMGS <[email protected]>
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 being overlaid after the fact, it does not hit the mapping-identity problems that motivated removing the original 2020 CoW-restore path (a60b437) or rejecting an mmap overlay during the on-demand restore work (cloud-hypervisor#7800). Opt-in via memory_restore_mode=copyonwrite; 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), zones with numa/reserve/ mergeable/hotplug attributes, resizable RAM, KSM, pvmemcontrol and device passthrough fall back to the eager copy. The snapshot file must remain on disk and unchanged for the VM lifetime. Measured on a 16-core x86_64 host (512 MiB guests, same binary, only the mode switched, 3 interleaved rounds): single restore p50 54-58ms -> 22-35ms; 16 concurrent restores from one snapshot: per-restore p50 443-463ms -> 72-82ms, wall 456-478ms -> 87-108ms. Restored VMs boot and run normally. Signed-off-by: CMGS <[email protected]>
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 being overlaid after the fact, it does not hit the mapping-identity problems that motivated removing the original 2020 CoW-restore path (a60b437) or rejecting an mmap overlay during the on-demand restore work (cloud-hypervisor#7800). Opt-in via memory_restore_mode=copyonwrite; 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), zones with numa/reserve/ mergeable/hotplug attributes, resizable RAM, KSM, pvmemcontrol and device passthrough fall back to the eager copy. The snapshot file must remain on disk and unchanged for the VM lifetime. Measured on a 16-core x86_64 host (512 MiB guests, same binary, only the mode switched, 3 interleaved rounds): single restore p50 54-58ms -> 22-35ms; 16 concurrent restores from one snapshot: per-restore p50 443-463ms -> 72-82ms, wall 456-478ms -> 87-108ms. Restored VMs boot and run normally. Signed-off-by: CMGS <[email protected]>
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 being overlaid after the fact, it does not hit the mapping-identity problems that motivated removing the original 2020 CoW-restore path (a60b437) or rejecting an mmap overlay during the on-demand restore work (cloud-hypervisor#7800). Opt-in via memory_restore_mode=copyonwrite; 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), zones with numa/reserve/ mergeable/hotplug attributes, resizable RAM, KSM, pvmemcontrol and device passthrough fall back to the eager copy. The snapshot file must remain on disk and unchanged for the VM lifetime. Measured on a 16-core x86_64 host (512 MiB guests, same binary, only the mode switched, 3 interleaved rounds): single restore p50 54-58ms -> 22-35ms; 16 concurrent restores from one snapshot: per-restore p50 443-463ms -> 72-82ms, wall 456-478ms -> 87-108ms. Restored VMs boot and run normally. Signed-off-by: CMGS <[email protected]>
This introduces a new
memory_restore_modeoption on the restore path that allows Cloud Hypervisor to populate guest memory lazily usinguserfaultfdinstead of reading the entire snapshot file into guest RAM before the VM resumes.Motivation
The existing restore path reads the full
memory-rangesfile into guest RAM before restore completes. For multi-gigabyte guests this front-loads a significant I/O cost and increases restore latency proportionally with guest memory size. This has been raised as a limitation in prior discussions around snapshot resume performance (#7623).Firecracker solves this by passing the
userfaultfdfile descriptor to an external handler process over a Unix socket, giving orchestrators full control over how pages are served. That model is powerful but requires an external component and introduces deployment complexity. This PR takes a simpler approach that keeps the handler entirely inside the VMM process, which is self-contained and requires no changes to the deployment model. For now, perhaps?Why userfaultfd instead of mmap
The natural first thought for lazy restore is to
mmap(MAP_PRIVATE)the snapshot file over the guest memory region. However, that replaces the existing memory mapping, which breaks subsystems that depend on the original mapping type and backing pages, including shared memory for vhost-user, VFIO DMA pinning, and KVM memory slots. Related discussions (#7624, #5749, #6110, #4069, #7302). Userfaultfd avoids this by intercepting page faults on the existing mapping and populating pages into it viaUFFDIO_COPY, preserving the original mapping type.How it works
When
memory_restore_mode=ondemandis specified on the restore command, the memory manager creates auserfaultfddescriptor after setting up guest memory but before populating it. It negotiates the kernel features required for the actual memory zone mapping types (requestingUFFD_FEATURE_MISSING_SHMEMfor shared memory zones andUFFD_FEATURE_MISSING_HUGETLBFSfor hugepage-backed zones) and registers each guest RAM range for missing-page fault interception. A handler thread is spawned that usesepollto wait for page fault events on theuserfaultfd. On each fault, it seeks into the snapshot file, reads the corresponding page, and resolves the fault withUFFDIO_COPY. The handler handles concurrent faults from multiple vCPUs by treatingEEXIST(page already resolved by a prior fault) as a benign race and waking any remaining blocked threads withUFFDIO_WAKE. Once all pages have been served the handler exits automatically, and it is also stopped cleanly on VM shutdown via an eventfd signal.If
memory_restore_modeis omitted the existing eager copy restore path is used, so there is no change to current behavior.Strict failure semantics
Went with the mindset that this is an explicit mode selection. If the user asks for
ondemandmode and theuserfaultfdcannot be created, the required kernel features are not available, or any region cannot be registered, restore fails immediately. Instead of silently falling back to eager copy, which would make behavior non-deterministic and make it harder to debug issues.Constraints
Prefaulting (
prefault=on) cannot be combined withondemandmode because the two are contradictory. This is validated early and produces a clear error message.Changes
The
RestoreConfigstruct gains amemory_restore_modefield with aMemoryRestoreModeenum (CopyorOndemand). This is a restore-time parameter, not VM hardware configuration, so it belongs inRestoreConfigrather than in the persisted VM config. The field is plumbed throughVmm::vm_restore,Vm::new, andMemoryManager::new_from_snapshotto the point where the restore strategy is dispatched. TheMemoryZonestruct now carriessharedandhugepagesmetadata from the zone configuration so the restore path can derive the exact userfaultfd features needed for the actual runtime mappings. A smalluserfaultfdconstants module provides the ioctl numbers and protocol constants, and a separateuffdmodule wraps the raw ioctls into safe Rust functions. The seccomp filter is updated to allow theuserfaultfdsyscall and the four uffd ioctls (UFFDIO_API,UFFDIO_COPY,UFFDIO_REGISTER,UFFDIO_WAKE) under the VMM thread profile. The OpenAPI spec is updated with the new enum field.Added integration tests for coverage in a separate commit.