summaryrefslogtreecommitdiff
path: root/qemu
diff options
context:
space:
mode:
authoraliguori <aliguori>2008-12-04 21:39:21 +0000
committeraliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>2008-12-04 21:39:21 +0000
commite724781ef42d11c7de95b3df58fa61bbb3b1bf80 (patch)
tree6bc9f76c577689689ea9b780994cbe544a4e8a71 /qemu
parent17ef75d595aad352308f1dcd4a01117a483d8c4a (diff)
Use writeback caching by default with qcow2
qcow2 writes a cluster reference count on every cluster update. This causes performance to crater when using anything but cache=writeback. This is most noticeable when using savevm. Right now, qcow2 isn't a reliable format regardless of the type of cache your using because metadata is not updated in the correct order. Considering this, I think it's somewhat reasonable to use writeback caching by default with qcow2 files. It at least avoids the massive performance regression for users until we sort out the issues in qcow2. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'qemu')
-rw-r--r--qemu/block-qcow2.c8
-rw-r--r--qemu/block.h3
-rw-r--r--qemu/qemu-doc.texi6
-rw-r--r--qemu/vl.c4
4 files changed, 19 insertions, 2 deletions
diff --git a/qemu/block-qcow2.c b/qemu/block-qcow2.c
index c9d68af9..b3b5f8f0 100644
--- a/qemu/block-qcow2.c
+++ b/qemu/block-qcow2.c
@@ -189,6 +189,14 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags)
int len, i, shift, ret;
QCowHeader header;
+ /* Performance is terrible right now with cache=writethrough due mainly
+ * to reference count updates. If the user does not explicitly specify
+ * a caching type, force to writeback caching.
+ */
+ if ((flags & BDRV_O_CACHE_DEF)) {
+ flags |= BDRV_O_CACHE_WB;
+ flags &= ~BDRV_O_CACHE_DEF;
+ }
ret = bdrv_file_open(&s->hd, filename, flags);
if (ret < 0)
return ret;
diff --git a/qemu/block.h b/qemu/block.h
index 99d3a1e1..c3314a1d 100644
--- a/qemu/block.h
+++ b/qemu/block.h
@@ -49,8 +49,9 @@ typedef struct QEMUSnapshotInfo {
bdrv_file_open()) */
#define BDRV_O_NOCACHE 0x0020 /* do not use the host page cache */
#define BDRV_O_CACHE_WB 0x0040 /* use write-back caching */
+#define BDRV_O_CACHE_DEF 0x0080 /* use default caching */
-#define BDRV_O_CACHE_MASK (BDRV_O_NOCACHE | BDRV_O_CACHE_WB)
+#define BDRV_O_CACHE_MASK (BDRV_O_NOCACHE | BDRV_O_CACHE_WB | BDRV_O_CACHE_DEF)
void bdrv_info(void);
void bdrv_info_stats(void);
diff --git a/qemu/qemu-doc.texi b/qemu/qemu-doc.texi
index f2c56ce0..77170d3a 100644
--- a/qemu/qemu-doc.texi
+++ b/qemu/qemu-doc.texi
@@ -289,6 +289,12 @@ The host page can be avoided entirely with @option{cache=none}. This will
attempt to do disk IO directly to the guests memory. QEMU may still perform
an internal copy of the data.
+Some block drivers perform badly with @option{cache=writethrough}, most notably,
+qcow2. If performance is more important than correctness,
+@option{cache=writeback} should be used with qcow2. By default, if no explicit
+caching is specified for a qcow2 disk image, @option{cache=writeback} will be
+used. For all other disk types, @option{cache=writethrough} is the default.
+
Instead of @option{-cdrom} you can use:
@example
qemu -drive file=file,index=2,media=cdrom
diff --git a/qemu/vl.c b/qemu/vl.c
index 1cee2a79..00adb799 100644
--- a/qemu/vl.c
+++ b/qemu/vl.c
@@ -2242,7 +2242,7 @@ static int drive_init(struct drive_opt *arg, int snapshot,
unit_id = -1;
translation = BIOS_ATA_TRANSLATION_AUTO;
index = -1;
- cache = 1;
+ cache = 3;
if (machine->use_scsi) {
type = IF_SCSI;
@@ -2517,6 +2517,8 @@ static int drive_init(struct drive_opt *arg, int snapshot,
bdrv_flags |= BDRV_O_NOCACHE;
else if (cache == 2) /* write-back */
bdrv_flags |= BDRV_O_CACHE_WB;
+ else if (cache == 3) /* not specified */
+ bdrv_flags |= BDRV_O_CACHE_DEF;
if (bdrv_open2(bdrv, file, bdrv_flags, drv) < 0 || qemu_key_check(bdrv, file)) {
fprintf(stderr, "qemu: could not open disk image %s\n",
file);