[libvirt] [PATCH] Bypass caching in saving VM memory upon external memory snapshot.

fuweiwei fuweiwei2 at huawei.com
Thu Aug 25 07:46:01 UTC 2016

From: Fuweiwei <fuweiwei2 at huawei.com>

Currently in qemu-kvm platform, the process of making an external memory 
snapshot is based on the "migration-to-file" sheme. It will use the system 
cache to speed up dumping. However, it will make external disk snapshots
afterwards, which must wait for the completion of flushing the dirty pages 
to the snapshot file. i.e. In virFileWrapperFdClose() after qemuMigrationToFile(),
it should wait until the libvirt_iohelper thread finishes fdatasync and exits.
During this time, the VM is paused (since it is suspended from the last iteration
of migration-to-file, to the completion of disk snapshots).

Assuming saving 4GB dirty memory at 200MB/s fdatasync speed, the VM will pause
for up to 20s, which is unfriendly to guests.

So I propose that it may be better to bypass caching upon external memory 
snapshot, via the VIR_DOMAIN_SAVE_BYPASS_CACHE flag. As a result, it may avoid
long-term fdatasync in libvirt_iohelper thread and achieve seemless VM suspend.

Signed-off-by: Fuweiwei <fuweiwei2 at huawei.com>
 src/qemu/qemu_driver.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 2089359..f954c23 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -14117,7 +14117,8 @@ qemuDomainSnapshotCreateActiveExternal(virConnectPtr conn,
             goto cleanup;
         if ((ret = qemuDomainSaveMemory(driver, vm, snap->def->file,
-                                        xml, compressed, resume, 0,
+                                        xml, compressed, resume,
+                                        VIR_DOMAIN_SAVE_BYPASS_CACHE,
                                         QEMU_ASYNC_JOB_SNAPSHOT)) < 0)
             goto cleanup;

More information about the libvir-list mailing list