Commit 4dc822d726376fd4369089f04eb8605d2f94b74f

Authored by aliguori
1 parent 0cd2df75

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>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5879 c046a42c-6fe2-441c-8c8c-71466251a162
block-qcow2.c
@@ -189,6 +189,14 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags) @@ -189,6 +189,14 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags)
189 int len, i, shift, ret; 189 int len, i, shift, ret;
190 QCowHeader header; 190 QCowHeader header;
191 191
  192 + /* Performance is terrible right now with cache=writethrough due mainly
  193 + * to reference count updates. If the user does not explicitly specify
  194 + * a caching type, force to writeback caching.
  195 + */
  196 + if ((flags & BDRV_O_CACHE_DEF)) {
  197 + flags |= BDRV_O_CACHE_WB;
  198 + flags &= ~BDRV_O_CACHE_DEF;
  199 + }
192 ret = bdrv_file_open(&s->hd, filename, flags); 200 ret = bdrv_file_open(&s->hd, filename, flags);
193 if (ret < 0) 201 if (ret < 0)
194 return ret; 202 return ret;
@@ -49,8 +49,9 @@ typedef struct QEMUSnapshotInfo { @@ -49,8 +49,9 @@ typedef struct QEMUSnapshotInfo {
49 bdrv_file_open()) */ 49 bdrv_file_open()) */
50 #define BDRV_O_NOCACHE 0x0020 /* do not use the host page cache */ 50 #define BDRV_O_NOCACHE 0x0020 /* do not use the host page cache */
51 #define BDRV_O_CACHE_WB 0x0040 /* use write-back caching */ 51 #define BDRV_O_CACHE_WB 0x0040 /* use write-back caching */
  52 +#define BDRV_O_CACHE_DEF 0x0080 /* use default caching */
52 53
53 -#define BDRV_O_CACHE_MASK (BDRV_O_NOCACHE | BDRV_O_CACHE_WB) 54 +#define BDRV_O_CACHE_MASK (BDRV_O_NOCACHE | BDRV_O_CACHE_WB | BDRV_O_CACHE_DEF)
54 55
55 void bdrv_info(void); 56 void bdrv_info(void);
56 void bdrv_info_stats(void); 57 void bdrv_info_stats(void);
qemu-doc.texi
@@ -289,6 +289,12 @@ The host page can be avoided entirely with @option{cache=none}. This will @@ -289,6 +289,12 @@ The host page can be avoided entirely with @option{cache=none}. This will
289 attempt to do disk IO directly to the guests memory. QEMU may still perform 289 attempt to do disk IO directly to the guests memory. QEMU may still perform
290 an internal copy of the data. 290 an internal copy of the data.
291 291
  292 +Some block drivers perform badly with @option{cache=writethrough}, most notably,
  293 +qcow2. If performance is more important than correctness,
  294 +@option{cache=writeback} should be used with qcow2. By default, if no explicit
  295 +caching is specified for a qcow2 disk image, @option{cache=writeback} will be
  296 +used. For all other disk types, @option{cache=writethrough} is the default.
  297 +
292 Instead of @option{-cdrom} you can use: 298 Instead of @option{-cdrom} you can use:
293 @example 299 @example
294 qemu -drive file=file,index=2,media=cdrom 300 qemu -drive file=file,index=2,media=cdrom
@@ -2242,7 +2242,7 @@ static int drive_init(struct drive_opt *arg, int snapshot, @@ -2242,7 +2242,7 @@ static int drive_init(struct drive_opt *arg, int snapshot,
2242 unit_id = -1; 2242 unit_id = -1;
2243 translation = BIOS_ATA_TRANSLATION_AUTO; 2243 translation = BIOS_ATA_TRANSLATION_AUTO;
2244 index = -1; 2244 index = -1;
2245 - cache = 1; 2245 + cache = 3;
2246 2246
2247 if (machine->use_scsi) { 2247 if (machine->use_scsi) {
2248 type = IF_SCSI; 2248 type = IF_SCSI;
@@ -2517,6 +2517,8 @@ static int drive_init(struct drive_opt *arg, int snapshot, @@ -2517,6 +2517,8 @@ static int drive_init(struct drive_opt *arg, int snapshot,
2517 bdrv_flags |= BDRV_O_NOCACHE; 2517 bdrv_flags |= BDRV_O_NOCACHE;
2518 else if (cache == 2) /* write-back */ 2518 else if (cache == 2) /* write-back */
2519 bdrv_flags |= BDRV_O_CACHE_WB; 2519 bdrv_flags |= BDRV_O_CACHE_WB;
  2520 + else if (cache == 3) /* not specified */
  2521 + bdrv_flags |= BDRV_O_CACHE_DEF;
2520 if (bdrv_open2(bdrv, file, bdrv_flags, drv) < 0 || qemu_key_check(bdrv, file)) { 2522 if (bdrv_open2(bdrv, file, bdrv_flags, drv) < 0 || qemu_key_check(bdrv, file)) {
2521 fprintf(stderr, "qemu: could not open disk image %s\n", 2523 fprintf(stderr, "qemu: could not open disk image %s\n",
2522 file); 2524 file);