Skip to content

migration: cut destination-side downtime on a big guest

Denis V. Lunev qemu-devel 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v2 Latest6 patches 0 repliesNew

Changes in v2 from the cover letter

- added patches 1 to 3, the dispatch-tree work; the batch runs inside the window patch 3 opens
- post_load_deferrable replaced by post_load_mr_update, a callback for region updates only (Peter)
- SynIC post_load split, patch 5, so VMBus still sees the SynIC state
- postcopy covered: the batch is made in the POSTCOPY_RUN handler before the bottom half which starts the guest is scheduled (Peter); the listen thread is not batched
- snapshot and xen loads batched the same way, COLO checkpoints not (Peter)
- the callback cannot fail; the abort on a failing hook is gone (Peter)
- documentation says the batch is one transaction and a lookup during it sees the old topology (Peter)
- APIC example dropped; the new callback cannot carry cross-thread work

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/6memory: publish a dispatch tree only once it is completesystem/memory-internal.h system/memory.c system/physmem.c+30 -170 replies
2/6physmem: pass the FlatView to address_space_translate_internalsystem/memory-internal.h system/physmem.c+12 -240 replies
3/6memory: stop building dispatch trees before the machine runsinclude/system/memory.h migration/savevm.c system/memory-internal.h +4 more+167 -50 replies
4/6migration: add post_load_mr_update to batch region remaps on loadinclude/migration/vmstate.h migration/savevm.c migration/vmstate.c +1 more+201 -00 replies
5/6hw/hyperv: split the SynIC page mapping from its state updatehw/hyperv/hyperv.c include/hw/hyperv/hyperv.h target/i386/kvm/hyperv-stub.c +2 more+76 -230 replies
6/6target/i386: batch the Hyper-V SynIC page remaps on loadtarget/i386/machine.c+7 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/6] migration: cut destination-side downtime on a big guest

v1 deferred the Hyper-V SynIC post_load so that it stopped forcing a flatview rebuild per vCPU. Measuring it showed the rebuild itself was the larger target: most of it is building the dispatch tree, which nothing translates through until a vCPU runs. Patches 1 to 3 stop building trees until the machine is about to run, for machine creation and an incoming stream alike. Patches 4 to 6 are v1 reworked after Peter's review: a device gets a separate post_load_mr_update callback which only maps or unmaps its regions, and a load batches those calls into one memory transaction after the device state has been read and before the guest can start.

The split is a correctness fix, not only an API change. v1 deferred the whole SynIC post_load, including the control bit VMBus reads in its own post_load to decide whether a SINT route gets a GSI. With a vmbus-bridge the destination would create the route without one, and the guest would get no further VMBus interrupts. Patch 5 separates state from mapping, patch 6 batches only the mapping.

The batch spans the whole load rather than one device, the alternative Chuang's series and the ToDo item point towards: a remap which repeats per vCPU sits in a per-vCPU section, so per-device batching would still rebuild once per vCPU. Unlike that series, the stream is not loaded inside the transaction: only callbacks which by contract resolve nothing share it, so no loader sees a stale view.

Measured on a 24-core EPYC 7443P restoring a captured stream of a Windows Server 2022 guest, median of three interleaved rounds. The metric is the sum of vmstate_downtime_load over the non-iterable sections plus everything deferred past the last section, so work moved to the end is not mistaken for work removed:

64 vCPU, 65 ports 4 vCPU, 16 ports
upstream 175 ms 25 ms
after patch 3 50 ms 10 ms
after patch 6 29 ms 9 ms

Patch 3 helps every guest; its saving tracks device count. Patch 6 scales with vCPUs: 21 ms on the large guest, 1 ms on the small one. Both guests map only the SynIC message page; one which also maps the event page saves about twice as much.

Patches 1 to 3 rest on no vCPU having run, so only the thread creating the machine or loading the stream, under the BQL, can reach a view without a tree; building one asserts the BQL. Postcopy starts the guest through vm_prepare_start() like any other start.

Tested on x86_64 with make check-unit, check-qtest-x86_64 and migration-test --full under KVM and forced onto TCG, where the subpage path runs; both include the postcopy cases. A guest which programs the SynIC from its boot sector comes back from save and restore with both pages mapped where they were.

v1: https://lore.kernel.org/qemu-devel/[email protected]/
Chuang Xu: https://lore.kernel.org/r/[email protected]
ToDo: https://wiki.qemu.org/ToDo/LiveMigration#Optimize_memory_updates_for_non-iterative_vmstates

Changes in v2:
- added patches 1 to 3, the dispatch-tree work; the batch runs inside the window patch 3 opens
- post_load_deferrable replaced by post_load_mr_update, a callback for region updates only (Peter)
- SynIC post_load split, patch 5, so VMBus still sees the SynIC state
- postcopy covered: the batch is made in the POSTCOPY_RUN handler before the bottom half which starts the guest is scheduled (Peter); the listen thread is not batched
- snapshot and xen loads batched the same way, COLO checkpoints not (Peter)
- the callback cannot fail; the abort on a failing hook is gone (Peter)
- documentation says the batch is one transaction and a lookup during it sees the old topology (Peter)
- APIC example dropped; the new callback cannot carry cross-thread work

CC Peter Xu <[email protected]>
CC Fabiano Rosas <[email protected]>
CC Paolo Bonzini <[email protected]>
CC Philippe Mathieu-Daude <[email protected]>
CC Zhao Liu <[email protected]>
CC Marcelo Tosatti <[email protected]>
CC Maciej S. Szmigiero <[email protected]>

Denis V. Lunev (6):
memory: publish a dispatch tree only once it is complete
physmem: pass the FlatView to address_space_translate_internal
memory: stop building dispatch trees before the machine runs
migration: add post_load_mr_update to batch region remaps on load hw/hyperv: split the SynIC page mapping from its state update target/i386: batch the Hyper-V SynIC page remaps on load

 hw/hyperv/hyperv.c            |  70 ++++++++++++++------
 include/hw/hyperv/hyperv.h    |   3 +
 include/migration/vmstate.h   |  30 +++++++++
 include/system/memory.h       |  19 ++++++
 migration/savevm.c            |  22 +++++++
 migration/vmstate.c           |  50 ++++++++++++++
 system/memory-internal.h      |  17 ++---
 system/memory.c               | 119 +++++++++++++++++++++++++++++++---
 system/physmem.c              |  78 +++++++++++++++-------
 system/runstate.c             |   3 +
 system/trace-events           |   1 +
 target/i386/kvm/hyperv-stub.c |   8 +++
 target/i386/kvm/hyperv.c      |  16 ++++-
 target/i386/kvm/hyperv.h      |   2 +
 target/i386/machine.c         |   8 ++-
 tests/unit/test-vmstate.c     | 109 +++++++++++++++++++++++++++++++
 16 files changed, 489 insertions(+), 66 deletions(-)
Signature · 1 line
2.53.0