From patchwork Mon Jun 20 15:19:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev" X-Patchwork-Id: 638068 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rYFGV53V1z9t0n for ; Tue, 21 Jun 2016 01:32:18 +1000 (AEST) Received: from localhost ([::1]:44382 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bF1BQ-0001wa-6S for incoming@patchwork.ozlabs.org; Mon, 20 Jun 2016 11:32:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41930) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bF0z9-00054b-P0 for qemu-devel@nongnu.org; Mon, 20 Jun 2016 11:19:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bF0z6-0006MJ-3C for qemu-devel@nongnu.org; Mon, 20 Jun 2016 11:19:34 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:35439 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bF0z5-0006LJ-M5 for qemu-devel@nongnu.org; Mon, 20 Jun 2016 11:19:32 -0400 Received: from irbis.sw.ru ([10.30.2.139]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id u5KFJIG5008716; Mon, 20 Jun 2016 18:19:19 +0300 (MSK) From: "Denis V. Lunev" To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Mon, 20 Jun 2016 18:19:18 +0300 Message-Id: <1466435958-308-1-git-send-email-den@openvz.org> X-Mailer: git-send-email 2.1.4 X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH 1/1] block: ignore flush requests when storage is clean X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , Evgeny Yakovlev , Max Reitz , Stefan Hajnoczi , den@openvz.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Evgeny Yakovlev Some guests (win2008 server for example) do a lot of unnecessary flushing when underlying media has not changed. This adds additional overhead on host when calling fsync/fdatasync. This change introduces a dirty flag in BlockDriverState which is set in bdrv_set_dirty and is checked in bdrv_co_flush. This allows us to avoid unnessesary flushing when storage is clean. The problem with excessive flushing was found by a performance test which does parallel directory tree creation (from 2 processes). Results improved from 0.424 loops/sec to 0.432 loops/sec. Each loop creates 10^3 directories with 10 files in each. Signed-off-by: Evgeny Yakovlev Signed-off-by: Denis V. Lunev CC: Kevin Wolf CC: Max Reitz CC: Stefan Hajnoczi CC: Fam Zheng --- block.c | 1 + block/dirty-bitmap.c | 3 +++ block/io.c | 6 ++++++ include/block/block_int.h | 1 + 4 files changed, 11 insertions(+) diff --git a/block.c b/block.c index b331eb9..1a4e154 100644 --- a/block.c +++ b/block.c @@ -2591,6 +2591,7 @@ int bdrv_truncate(BlockDriverState *bs, int64_t offset) bdrv_dirty_bitmap_truncate(bs); bdrv_parent_cb_resize(bs); } + bs->dirty = true; /* file node sync is needed after truncate */ return ret; } diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 4902ca5..ad208ad 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -370,6 +370,9 @@ void bdrv_set_dirty(BlockDriverState *bs, int64_t cur_sector, } hbitmap_set(bitmap->bitmap, cur_sector, nr_sectors); } + + /* Set global block driver dirty flag */ + bs->dirty = true; } /** diff --git a/block/io.c b/block/io.c index ebdb9d8..ef372d2 100644 --- a/block/io.c +++ b/block/io.c @@ -2234,6 +2234,12 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs) } } + /* Check if storage is actually dirty before flushing to disk */ + if (!bs->dirty) { + goto flush_parent; + } + bs->dirty = false; + /* But don't actually force it to the disk with cache=unsafe */ if (bs->open_flags & BDRV_O_NO_FLUSH) { goto flush_parent; diff --git a/include/block/block_int.h b/include/block/block_int.h index 688c6be..a62943b 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -417,6 +417,7 @@ struct BlockDriverState { int sg; /* if true, the device is a /dev/sg* */ int copy_on_read; /* if true, copy read backing sectors into image note this is a reference count */ + bool dirty; bool probed; BlockDriver *drv; /* NULL means no media */