* [Qemu-devel] [PATCH] qcow2-cache: conditionally call bdrv_flush() in qcow2_cache_flush()
@ 2014-11-07 1:30 Zhang Haoyu
2014-11-13 11:53 ` Stefan Hajnoczi
0 siblings, 1 reply; 2+ messages in thread
From: Zhang Haoyu @ 2014-11-07 1:30 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Stefan Hajnoczi
Needless to call bdrv_flush() in qcow2_cache_flush()
if no cache entry is dirty.
Signed-off-by: Zhang Haoyu <zhanghy@sangfor.com>
---
block/qcow2-cache.c | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)
diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c
index 904f6b1..09ee155 100644
--- a/block/qcow2-cache.c
+++ b/block/qcow2-cache.c
@@ -110,10 +110,6 @@ static int qcow2_cache_entry_flush(BlockDriverState *bs, Qcow2Cache *c, int i)
BDRVQcowState *s = bs->opaque;
int ret = 0;
- if (!c->entries[i].dirty || !c->entries[i].offset) {
- return 0;
- }
-
trace_qcow2_cache_entry_flush(qemu_coroutine_self(),
c == s->l2_table_cache, i);
@@ -166,19 +162,23 @@ int qcow2_cache_flush(BlockDriverState *bs, Qcow2Cache *c)
{
BDRVQcowState *s = bs->opaque;
int result = 0;
+ bool need_bdrv_flush = false;
int ret;
int i;
trace_qcow2_cache_flush(qemu_coroutine_self(), c == s->l2_table_cache);
for (i = 0; i < c->size; i++) {
- ret = qcow2_cache_entry_flush(bs, c, i);
- if (ret < 0 && result != -ENOSPC) {
- result = ret;
+ if (c->entries[i].dirty && c->entries[i].offset) {
+ ret = qcow2_cache_entry_flush(bs, c, i);
+ if (ret < 0 && result != -ENOSPC) {
+ result = ret;
+ }
+ need_bdrv_flush = true;
}
}
- if (result == 0) {
+ if (need_bdrv_flush && result == 0) {
ret = bdrv_flush(bs->file);
if (ret < 0) {
result = ret;
@@ -289,9 +289,11 @@ static int qcow2_cache_do_get(BlockDriverState *bs, Qcow2Cache *c,
return i;
}
- ret = qcow2_cache_entry_flush(bs, c, i);
- if (ret < 0) {
- return ret;
+ if (c->entries[i].dirty && c->entries[i].offset) {
+ ret = qcow2_cache_entry_flush(bs, c, i);
+ if (ret < 0) {
+ return ret;
+ }
}
trace_qcow2_cache_get_read(qemu_coroutine_self(),
--
1.7.12.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] qcow2-cache: conditionally call bdrv_flush() in qcow2_cache_flush()
2014-11-07 1:30 [Qemu-devel] [PATCH] qcow2-cache: conditionally call bdrv_flush() in qcow2_cache_flush() Zhang Haoyu
@ 2014-11-13 11:53 ` Stefan Hajnoczi
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Hajnoczi @ 2014-11-13 11:53 UTC (permalink / raw)
To: Zhang Haoyu; +Cc: Kevin Wolf, qemu-devel, Stefan Hajnoczi
[-- Attachment #1: Type: text/plain, Size: 815 bytes --]
On Fri, Nov 07, 2014 at 09:30:59AM +0800, Zhang Haoyu wrote:
> Needless to call bdrv_flush() in qcow2_cache_flush()
> if no cache entry is dirty.
Did you audit all qcow2 cache callers to make sure they don't rely on
the cache flush?
Maybe it's not safe to optimize it away if callers assume previously
written data will be persisted as part of qcow2 cache flushing.
We need to be very careful when optimizing out cache flushes so that we
don't introduce data integrity problems.
>
> Signed-off-by: Zhang Haoyu <zhanghy@sangfor.com>
> ---
> block/qcow2-cache.c | 24 +++++++++++++-----------
> 1 file changed, 13 insertions(+), 11 deletions(-)
Please post benchmark configuration and performance results, if you ran
any. Data makes performance optimization patches much more convincing.
[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-11-13 11:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-07 1:30 [Qemu-devel] [PATCH] qcow2-cache: conditionally call bdrv_flush() in qcow2_cache_flush() Zhang Haoyu
2014-11-13 11:53 ` Stefan Hajnoczi
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).