From patchwork Wed May 26 18:13:14 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 53657 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id ADF9DB7D19 for ; Thu, 27 May 2010 04:50:21 +1000 (EST) Received: from localhost ([127.0.0.1]:44706 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OHLfh-0005Zz-Fw for incoming@patchwork.ozlabs.org; Wed, 26 May 2010 14:49:42 -0400 Received: from [140.186.70.92] (port=46865 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OHL5r-0007n6-0b for qemu-devel@nongnu.org; Wed, 26 May 2010 14:12:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OHL5o-0008PH-Vb for qemu-devel@nongnu.org; Wed, 26 May 2010 14:12:38 -0400 Received: from cantor.suse.de ([195.135.220.2]:52465 helo=mx1.suse.de) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OHL5o-0008Ma-Ms for qemu-devel@nongnu.org; Wed, 26 May 2010 14:12:36 -0400 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.221.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.suse.de (Postfix) with ESMTP id BAA2C992CF; Wed, 26 May 2010 20:12:30 +0200 (CEST) From: Alexander Graf To: qemu-devel@nongnu.org Date: Wed, 26 May 2010 20:13:14 +0200 Message-Id: <1274897594-4167-1-git-send-email-agraf@suse.de> X-Mailer: git-send-email 1.6.0.2 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 Cc: kwolf@redhat.com, hch@lst.de, aurelien@aurel32.net, avi@redhat.com Subject: [Qemu-devel] [PATCH] Default to cache=writeback X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org In the previous discussion Anthony brought up the fact that cache=writeback is safe enough considering data integrity. If so, I don't see a reason not to use it as default, as it speeds up things a lot. Keep in mind that most people will want to use cache=none anyways if they want to bypass the host cache. To stress my point, I ran the same test I did for cache=unsafe again to compare cache=write{through,back}. cache=writeback real 0m32.549s user 0m16.069s sys 0m6.152s cache=writethrough real 0m48.055s user 0m16.677s sys 0m8.045s Signed-off-by: Alexander Graf --- qemu-options.hx | 19 +++++++++---------- vl.c | 5 ++++- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/qemu-options.hx b/qemu-options.hx index cea9b72..b389f36 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -162,16 +162,15 @@ This option specifies the serial number to assign to the device. Specify the controller's PCI address (if=virtio only). @end table -By default, writethrough caching is used for all block device. This means that -the host page cache will be used to read and write data but write notification -will be sent to the guest only when the data has been reported as written by -the storage subsystem. - -Writeback caching will report data writes as completed as soon as the data is -present in the host page cache. This is safe as long as you trust your host. -If your host crashes or loses power, then the guest may experience data -corruption. When using the @option{-snapshot} option, writeback caching is -used by default. +By default, writeback caching is used for all block devices. It will report +data writes as completed as soon as the data is present in the host page +cache. This is safe as long as you trust your host. If your host crashes +or loses power, then the guest may experience data corruption. When using +the @option{-snapshot} option, writeback caching is always used. + +Writethrough caching means that the host page cache will be used to read +and write data but write notification will be sent to the guest only when +the data has been reported as written by the storage subsystem. The host page cache can be avoided entirely with @option{cache=none}. This will attempt to do disk IO directly to the guests memory. QEMU may still perform diff --git a/vl.c b/vl.c index bc15dd7..a70e487 100644 --- a/vl.c +++ b/vl.c @@ -917,11 +917,14 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque, bdrv_flags |= BDRV_O_CACHE_WB; bdrv_flags |= BDRV_O_NO_FLUSH; } else if (!strcmp(buf, "writethrough")) { - /* this is the default */ + /* no special flag needed */ } else { fprintf(stderr, "qemu: invalid cache option\n"); return NULL; } + } else { + /* default to writeback */ + bdrv_flags |= BDRV_O_CACHE_WB; } #ifdef CONFIG_LINUX_AIO