Thanks to visit codestin.com
Credit goes to github.com

Skip to content

vmm: Transfer post-snapshot memory changes during live migration - #8361

Merged
rbradford merged 3 commits into
cloud-hypervisor:mainfrom
rbradford:202606/last-memory-after-snapshot
Jun 11, 2026
Merged

rbradford merged 3 commits into
cloud-hypervisor:mainfrom
rbradford:202606/last-memory-after-snapshot

Conversation

@rbradford

Copy link
Copy Markdown
Member

When taking the snapshot of a vhost-user device this can cause the backend to
force a drain of inflight I/O which could result in guest memory changes. Carry
out one more memory transfer after capturing the state but before sending it
since the protocol does not tolerate a memory update after the state has been
received.

  • virtio-devices: Move guest_memory to VhostUserCommon
  • virtio-devices: vhost_user: Save the dirty log before shutdown
  • vmm: Add a final memory pass after capturing snapshot

Rather than each device implementation holding a reference to the guest
memory move this to VhostUserCommon. This refactoring simplifies the
function signatures but also allows for methods that act on
VhostUserCommon that don't have the memory available to them.

Signed-off-by: Rob Bradford <[email protected]>
Query and save the dirty log before shutting down the vhost-user device.
This allows any final dirty memory ranges to be recorded before it
becomes impossible to do that as the vhost-user handle has been closed.
This is required to ensure that all memory writes have been correctly
recorded that may be triggered by inflight I/O drains from vhost-user
device state capture.

One small implementation wrinkle: with local migrations there is no
dirty logging (since we just pass the memory FD over the socket) so
calling dirty_log() would generate an error. As there is no clean way to
query if dirty logging has been started add a boolean to track if its
active.

Signed-off-by: Rob Bradford <[email protected]>
During migration send one final set of changed memory after capturing
the snapshot/state. This captures any memory changed as a side effect of
capturing that state. In particular with vhost-user capturing the device
state can lead to inflight requests being drained/flushed which could
change memory. As this is related to the snapshot account for this
memory transfer in the snapshot metrics.

No equivalent change is needed for snapshot as the memory is written
after the state is snapshotted.

Signed-off-by: Rob Bradford <[email protected]>
@rbradford
rbradford force-pushed the 202606/last-memory-after-snapshot branch from ba13875 to 1864ca7 Compare June 10, 2026 12:46
@rbradford
rbradford marked this pull request as ready for review June 10, 2026 14:03
@rbradford
rbradford requested a review from a team as a code owner June 10, 2026 14:03
@rbradford rbradford changed the title vmm: Capture any memory changes as a side effect of device snapshot vmm: Transfer post-snapshot memory changes during live migration Jun 10, 2026
@dgreid

dgreid commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

This took me a bit to understand, but TLDR, LGTM.

The issue is that pause is a pure pause(vring only) and doesn't stop the device(I/O continues). So the actual synchronous work stoppage ended up as part of snapshot.

I agree having these be asymmetrical smells. I feel like we're missing a state. pause is insufficient for snapshot, so currently there is a vhost-user stop tacked on to snapshot and pre-pause for block. What if we added an explicit step to flush/quiesce I/O pre-snapshot?

Comment thread virtio-devices/src/vhost_user/mod.rs
if self.migration_started {
// Local migration does not enable dirty logging.
if self.dirty_logging {
self.saved_dirty_log = Some(self.dirty_log()?);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a clever trick given we don't have access to the vhost-user device after it's been shutdown.
One other approach I can think of would be to update the shutdown() method to return Result<Option<MemoryRangeTable>>, but maybe that's not ideal as it would tie shutdown to migration semantics.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed - I thought this elegant but not too "clever" (in terms of being hard to understand).

@rbradford
rbradford added this pull request to the merge queue Jun 11, 2026
Comment thread vmm/src/lib.rs

// One final memory iteration to handle side effects from snapshot.
if !send_data_migration.local {
let memory_ranges = vm.dirty_log()?;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose the amount of memory here will always be fairly negligible?

Merged via the queue into cloud-hypervisor:main with commit 7042922 Jun 11, 2026
40 of 41 checks passed
@rbradford
rbradford deleted the 202606/last-memory-after-snapshot branch June 12, 2026 10:35
@github-project-automation github-project-automation Bot moved this from 🆕 New to ✅ Done in Cloud Hypervisor Roadmap Jul 8, 2026
@rbradford rbradford added the bug-fix Bug fix to include in release notes label Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix Bug fix to include in release notes

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

4 participants