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/20260911142345.3999518-1-den@openvz.org/
Chuang Xu: https://lore.kernel.org/r/20230317081904.24389-1-xuchuangxclwt@bytedance.com
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 <peterx@redhat.com>
CC: Fabiano Rosas <farosas@suse.de>
CC: Paolo Bonzini <pbonzini@redhat.com>
CC: Philippe Mathieu-Daude <philmd@oss.qualcomm.com>
CC: Zhao Liu <zhao1.liu@intel.com>
CC: Marcelo Tosatti <mtosatti@redhat.com>
CC: Maciej S. Szmigiero <maciej.szmigiero@oracle.com>
Signed-off-by: Denis V. Lunev <den@virtuozzo.com>
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(-)
--
2.53.0