@samitouri / QOSamiQemu / commits / 39ab94e414

migration: Remember total dirty bytes in mig_stats

Introduce this new counter to remember the total dirty bytes for the whole system. It will be used for query-migrate command to fetch system-wise remaining data. A prior attempt was made to not use this counter but query directly from all the modules in a QMP handler, but it exposed some complexity not only on migration state machine race conditions (where the query may be invoked anytime of the state machine), or on locking implications (where some of the query hooks may take BQL, which is illegal at least in a QMP handler). For more information, see: https://lore.kernel.org/r/aeZMtxqrKWAMKzdN@x1.local This oneliner will resolve everything, except that it is not as accurate. The hope is it is a worthwhile trade-off solution, after knowing above challenges. Now, there is one more reason we should make each invocation of save_live_iterate() to be lightweight, because this counter will only get updated once for each loop over all save_live_iterate() hooks when present. But that's always the goal. Reviewed-by: Juraj Marcin <jmarcin@redhat.com> Link: https://lore.kernel.org/r/20260421202110.306051-14-peterx@redhat.com Signed-off-by: Peter Xu <peterx@redhat.com>

Peter Xu committed Apr 21, 2026 at 16:21 UTC 39ab94e414f8abdc8412618ab16876499f69d27a
2 files changed +14
migration/migration-stats.h
+7
@@ -36,6 +36,13 @@ typedef struct {
36 * best-effort estimation on expected downtime.
37 */
38 uint64_t dirty_bytes_last_sync;
39 + /*
40 + * Number of bytes that were reported dirty now. This is an estimate
41 + * value and will be updated every time migration thread queries from
42 + * modules in an iteration loop. It is used to provide best-effort
43 + * estimation on total remaining data.
44 + */
45 + uint64_t dirty_bytes_total;
46 /*
47 * Number of pages dirtied per second.
48 */
migration/savevm.c
+7
@@ -1815,6 +1815,13 @@ void qemu_savevm_query_pending(MigPendingData *pending, bool exact)
1815 pending->total_bytes = pending->precopy_bytes +
1816 pending->stopcopy_bytes + pending->postcopy_bytes;
1817
1818 + /*
1819 + * Update system remaining dirty bytes whenever QEMU queries. It will
1820 + * make the value to be not as accurate, but should still be pretty
1821 + * close to reality when this got invoked frequently while iterating.
1822 + */
1823 + mig_stats.dirty_bytes_total = pending->total_bytes;
1824 +
1825 trace_qemu_savevm_query_pending(exact, pending->precopy_bytes,
1826 pending->stopcopy_bytes,
1827 pending->postcopy_bytes,