[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] PATCH: Disable QEMU drive caching



QEMU defaults to allowing the host OS to cache all disk I/O. THis has a
couple of problems

 - It is a waste of memory because the guest already caches I/O ops
 - It is unsafe on host OS crash - all unflushed guest I/O will be
   lost, and there's no ordering guarentees, so metadata updates could
   be flushe to disk, while the journal updates were not. Say goodbye
   to your filesystem.
 - It makes benchmarking more or less impossible / worthless because
   what the benchmark things are disk writes just sit around in memory
   so guest disk performance appears to exceed host diskperformance.

This patch disables caching on all QEMU guests. NB, Xen has long done this
for both PV & HVM guests - QEMU only gained this ability when -drive was
introduced, and sadly kept the default to unsafe cache=on settings.

Daniel

diff -r 4a0ccc9dc530 src/qemu_conf.c
--- a/src/qemu_conf.c	Wed Oct 08 11:53:45 2008 +0100
+++ b/src/qemu_conf.c	Wed Oct 08 11:59:33 2008 +0100
@@ -460,6 +460,8 @@
         flags |= QEMUD_CMD_FLAG_DRIVE;
     if (strstr(help, "boot=on"))
         flags |= QEMUD_CMD_FLAG_DRIVE_BOOT;
+    if (strstr(help, "cache=on"))
+        flags |= QEMUD_CMD_FLAG_DRIVE_CACHE;
     if (version >= 9000)
         flags |= QEMUD_CMD_FLAG_VNC_COLON;
 
@@ -959,13 +961,15 @@
                 break;
             }
 
-            snprintf(opt, PATH_MAX, "file=%s,if=%s,%sindex=%d%s",
+            snprintf(opt, PATH_MAX, "file=%s,if=%s,%sindex=%d%s%s",
                      disk->src ? disk->src : "", bus,
                      media ? media : "",
                      idx,
                      bootable &&
                      disk->device == VIR_DOMAIN_DISK_DEVICE_DISK
-                     ? ",boot=on" : "");
+                     ? ",boot=on" : "",
+                     qemuCmdFlags & QEMUD_CMD_FLAG_DRIVE_BOOT
+                     ? ",cache=off" : "");
 
             ADD_ARG_LIT("-drive");
             ADD_ARG_LIT(opt);
diff -r 4a0ccc9dc530 src/qemu_conf.h
--- a/src/qemu_conf.h	Wed Oct 08 11:53:45 2008 +0100
+++ b/src/qemu_conf.h	Wed Oct 08 11:59:33 2008 +0100
@@ -44,7 +44,8 @@
     QEMUD_CMD_FLAG_NO_REBOOT      = (1 << 2),
     QEMUD_CMD_FLAG_DRIVE          = (1 << 3),
     QEMUD_CMD_FLAG_DRIVE_BOOT     = (1 << 4),
-    QEMUD_CMD_FLAG_NAME           = (1 << 5),
+    QEMUD_CMD_FLAG_DRIVE_CACHE    = (1 << 5),
+    QEMUD_CMD_FLAG_NAME           = (1 << 6),
 };
 
 /* Main driver state */

-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]