[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 23/31] qcow2: avoid extra flushes in qcow2
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 23/31] qcow2: avoid extra flushes in qcow2 |
Date: |
Wed, 8 Jun 2016 11:16:49 +0200 |
From: "Denis V. Lunev" <address@hidden>
The problem with excessive flushing was found by a couple of performance
tests:
- parallel directory tree creation (from 2 processes)
- 32 cached writes + fsync at the end in a loop
For the first one results improved from 2.6 loops/sec to 3.5 loops/sec.
Each loop creates 10^3 directories with 10 files in each.
For the second one results improved from ~600 fsync/sec to ~1100
fsync/sec. Though, it was run on SSD so it probably won't show such
performance gain on rotational media.
qcow2_cache_flush() calls bdrv_flush() unconditionally after writing
cache entries of a particular cache. This can lead to as many as
2 additional fdatasyncs inside bdrv_flush.
We can simply skip all fdatasync calls inside qcow2_co_flush_to_os
as bdrv_flush for sure will do the job. These flushes are necessary to
keep the right order of writes to the different caches. Though this is
not necessary in the current code base as this ordering is ensured through
the flush in qcow2_cache_flush_dependency().
Signed-off-by: Denis V. Lunev <address@hidden>
CC: Pavel Borzenkov <address@hidden>
CC: Kevin Wolf <address@hidden>
CC: Max Reitz <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/qcow2-cache.c | 11 +++++++++--
block/qcow2.c | 4 ++--
block/qcow2.h | 1 +
3 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c
index 0fe8eda..208a060 100644
--- a/block/qcow2-cache.c
+++ b/block/qcow2-cache.c
@@ -226,7 +226,7 @@ static int qcow2_cache_entry_flush(BlockDriverState *bs,
Qcow2Cache *c, int i)
return 0;
}
-int qcow2_cache_flush(BlockDriverState *bs, Qcow2Cache *c)
+int qcow2_cache_write(BlockDriverState *bs, Qcow2Cache *c)
{
BDRVQcow2State *s = bs->opaque;
int result = 0;
@@ -242,8 +242,15 @@ int qcow2_cache_flush(BlockDriverState *bs, Qcow2Cache *c)
}
}
+ return result;
+}
+
+int qcow2_cache_flush(BlockDriverState *bs, Qcow2Cache *c)
+{
+ int result = qcow2_cache_write(bs, c);
+
if (result == 0) {
- ret = bdrv_flush(bs->file->bs);
+ int ret = bdrv_flush(bs->file->bs);
if (ret < 0) {
result = ret;
}
diff --git a/block/qcow2.c b/block/qcow2.c
index 5e26c3d..6f5fb81 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2813,14 +2813,14 @@ static coroutine_fn int
qcow2_co_flush_to_os(BlockDriverState *bs)
int ret;
qemu_co_mutex_lock(&s->lock);
- ret = qcow2_cache_flush(bs, s->l2_table_cache);
+ ret = qcow2_cache_write(bs, s->l2_table_cache);
if (ret < 0) {
qemu_co_mutex_unlock(&s->lock);
return ret;
}
if (qcow2_need_accurate_refcounts(s)) {
- ret = qcow2_cache_flush(bs, s->refcount_block_cache);
+ ret = qcow2_cache_write(bs, s->refcount_block_cache);
if (ret < 0) {
qemu_co_mutex_unlock(&s->lock);
return ret;
diff --git a/block/qcow2.h b/block/qcow2.h
index a063a3c..7db9795 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -583,6 +583,7 @@ int qcow2_cache_destroy(BlockDriverState* bs, Qcow2Cache
*c);
void qcow2_cache_entry_mark_dirty(BlockDriverState *bs, Qcow2Cache *c,
void *table);
int qcow2_cache_flush(BlockDriverState *bs, Qcow2Cache *c);
+int qcow2_cache_write(BlockDriverState *bs, Qcow2Cache *c);
int qcow2_cache_set_dependency(BlockDriverState *bs, Qcow2Cache *c,
Qcow2Cache *dependency);
void qcow2_cache_depends_on_flush(Qcow2Cache *c);
--
1.8.3.1
- [Qemu-devel] [PULL 09/31] block: Switch bdrv_write_zeroes() to byte interface, (continued)
- [Qemu-devel] [PULL 09/31] block: Switch bdrv_write_zeroes() to byte interface, Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 21/31] block: assert that bs->request_alignment is a power of 2, Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 15/31] raw-posix: Convert to bdrv_co_pwrite_zeroes(), Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 18/31] block: Kill bdrv_co_write_zeroes(), Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 04/31] qemu-iotests: Test one more spot for optimizing write_zeroes, Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 13/31] gluster: Convert to bdrv_co_pwrite_zeroes(), Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 12/31] blkreplay: Convert to bdrv_co_pwrite_zeroes(), Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 16/31] raw_bsd: Convert to bdrv_co_pwrite_zeroes(), Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 14/31] qed: Convert to bdrv_co_pwrite_zeroes(), Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 28/31] qemu-img bench: Sequential writes, Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 23/31] qcow2: avoid extra flushes in qcow2,
Kevin Wolf <=
- [Qemu-devel] [PULL 27/31] qemu-img bench, Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 24/31] block: Fix bdrv_all_delete_snapshot() error handling, Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 25/31] blockdev: clean up error handling in do_open_tray, Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 20/31] migration/block: Convert saving to BlockBackend, Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 29/31] qemu-img bench: Make start offset configurable, Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 22/31] raw-posix: Fetch max sectors for host block device, Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 26/31] block: Don't emulate natively supported pwritev flags, Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 31/31] qemu-img bench: Add --flush-interval, Kevin Wolf, 2016/06/08
- [Qemu-devel] [PULL 30/31] qemu-img bench: Implement -S (step size), Kevin Wolf, 2016/06/08
- Re: [Qemu-devel] [PULL 00/31] Block layer patches, Peter Maydell, 2016/06/08