From: Anthony Liguori <aliguori@us.ibm.com>
To: "qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Cc: kvm-devel <kvm@vger.kernel.org>
Subject: [Qemu-devel] [PATCH][RFC] Use writeback caching by default with qcow2
Date: Wed, 19 Nov 2008 14:24:53 -0600 [thread overview]
Message-ID: <49247615.6050105@us.ibm.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 567 bytes --]
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.
Regards,
Anthony Liguori
[-- Attachment #2: block-qcow2-default-caching.patch --]
[-- Type: text/x-patch, Size: 2769 bytes --]
Index: vl.c
===================================================================
--- vl.c (revision 5751)
+++ vl.c (working copy)
@@ -2225,7 +2225,7 @@
unit_id = -1;
translation = BIOS_ATA_TRANSLATION_AUTO;
index = -1;
- cache = 1;
+ cache = 3;
if (machine->use_scsi) {
type = IF_SCSI;
@@ -2496,6 +2496,8 @@
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);
Index: qemu-doc.texi
===================================================================
--- qemu-doc.texi (revision 5751)
+++ qemu-doc.texi (working copy)
@@ -289,6 +289,12 @@
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
Index: block-qcow2.c
===================================================================
--- block-qcow2.c (revision 5751)
+++ block-qcow2.c (working copy)
@@ -189,6 +189,14 @@
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;
Index: block.h
===================================================================
--- block.h (revision 5751)
+++ block.h (working copy)
@@ -49,8 +49,9 @@
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);
next reply other threads:[~2008-11-19 20:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-19 20:24 Anthony Liguori [this message]
2008-11-19 22:27 ` [Qemu-devel] [PATCH][RFC] Use writeback caching by default with qcow2 Stefan Berger
[not found] ` <gg325v$mfc$1@ger.gmane.org>
2008-11-20 9:55 ` [Qemu-devel] " Avi Kivity
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=49247615.6050105@us.ibm.com \
--to=aliguori@us.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).