From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L8Lut-0003o9-7Y for qemu-devel@nongnu.org; Thu, 04 Dec 2008 16:39:23 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L8Lus-0003nl-Ku for qemu-devel@nongnu.org; Thu, 04 Dec 2008 16:39:22 -0500 Received: from [199.232.76.173] (port=37438 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L8Lus-0003ni-H7 for qemu-devel@nongnu.org; Thu, 04 Dec 2008 16:39:22 -0500 Received: from savannah.gnu.org ([199.232.41.3]:36985 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1L8Lus-0007eG-6p for qemu-devel@nongnu.org; Thu, 04 Dec 2008 16:39:22 -0500 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1L8Lur-0003Ml-OB for qemu-devel@nongnu.org; Thu, 04 Dec 2008 21:39:21 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1L8Lur-0003Mg-DH for qemu-devel@nongnu.org; Thu, 04 Dec 2008 21:39:21 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Thu, 04 Dec 2008 21:39:21 +0000 Subject: [Qemu-devel] [5879] Use writeback caching by default with qcow2 Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 5879 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5879 Author: aliguori Date: 2008-12-04 21:39:21 +0000 (Thu, 04 Dec 2008) Log Message: ----------- 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 Modified Paths: -------------- trunk/block-qcow2.c trunk/block.h trunk/qemu-doc.texi trunk/vl.c Modified: trunk/block-qcow2.c =================================================================== --- trunk/block-qcow2.c 2008-12-04 21:34:52 UTC (rev 5878) +++ trunk/block-qcow2.c 2008-12-04 21:39:21 UTC (rev 5879) @@ -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; Modified: trunk/block.h =================================================================== --- trunk/block.h 2008-12-04 21:34:52 UTC (rev 5878) +++ trunk/block.h 2008-12-04 21:39:21 UTC (rev 5879) @@ -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); Modified: trunk/qemu-doc.texi =================================================================== --- trunk/qemu-doc.texi 2008-12-04 21:34:52 UTC (rev 5878) +++ trunk/qemu-doc.texi 2008-12-04 21:39:21 UTC (rev 5879) @@ -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 Modified: trunk/vl.c =================================================================== --- trunk/vl.c 2008-12-04 21:34:52 UTC (rev 5878) +++ trunk/vl.c 2008-12-04 21:39:21 UTC (rev 5879) @@ -2242,7 +2242,7 @@ 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 @@ 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);