[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH v2 2/4] qcow2: add qcow2_cache_discard
From: |
Pavel Butsykin |
Subject: |
[Qemu-block] [PATCH v2 2/4] qcow2: add qcow2_cache_discard |
Date: |
Tue, 13 Jun 2017 15:16:37 +0300 |
Whenever l2/refcount table clusters are discarded from the file we can
automatically drop unnecessary content of the cache tables. This reduces
the chance of eviction useful cache data and eliminates inconsistent data
in thecache with the data in the file.
Signed-off-by: Pavel Butsykin <address@hidden>
---
block/qcow2-cache.c | 21 +++++++++++++++++++++
block/qcow2-refcount.c | 5 +++++
block/qcow2.h | 1 +
3 files changed, 27 insertions(+)
diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c
index 1d25147392..7931edf237 100644
--- a/block/qcow2-cache.c
+++ b/block/qcow2-cache.c
@@ -411,3 +411,24 @@ void qcow2_cache_entry_mark_dirty(BlockDriverState *bs,
Qcow2Cache *c,
assert(c->entries[i].offset != 0);
c->entries[i].dirty = true;
}
+
+void qcow2_cache_discard(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset)
+{
+ int i;
+
+ for (i = 0; i < c->size; i++) {
+ if (c->entries[i].offset == offset) {
+ goto found; /* table offset */
+ }
+ }
+ return;
+
+found:
+ assert(c->entries[i].ref == 0);
+
+ c->entries[i].offset = 0;
+ c->entries[i].lru_counter = 0;
+ c->entries[i].dirty = false;
+
+ qcow2_cache_table_release(bs, c, i, 1);
+}
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 7c06061aae..576ab551d6 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -767,6 +767,11 @@ static int QEMU_WARN_UNUSED_RESULT
update_refcount(BlockDriverState *bs,
s->set_refcount(refcount_block, block_index, refcount);
if (refcount == 0 && s->discard_passthrough[type]) {
+ qcow2_cache_put(bs, s->refcount_block_cache, &refcount_block);
+ qcow2_cache_discard(bs, s->refcount_block_cache, offset);
+
+ qcow2_cache_discard(bs, s->l2_table_cache, offset);
+
update_refcount_discard(bs, cluster_offset, s->cluster_size);
}
}
diff --git a/block/qcow2.h b/block/qcow2.h
index 1801dc30dc..07faa6dc78 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -597,5 +597,6 @@ int qcow2_cache_get(BlockDriverState *bs, Qcow2Cache *c,
uint64_t offset,
int qcow2_cache_get_empty(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset,
void **table);
void qcow2_cache_put(BlockDriverState *bs, Qcow2Cache *c, void **table);
+void qcow2_cache_discard(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset);
#endif
--
2.13.0
[Qemu-block] [PATCH v2 2/4] qcow2: add qcow2_cache_discard,
Pavel Butsykin <=
[Qemu-block] [PATCH v2 3/4] qcow2: add shrink image support, Pavel Butsykin, 2017/06/13
- Re: [Qemu-block] [PATCH v2 3/4] qcow2: add shrink image support, Max Reitz, 2017/06/21
- Re: [Qemu-block] [PATCH v2 3/4] qcow2: add shrink image support, Pavel Butsykin, 2017/06/22
- Re: [Qemu-block] [PATCH v2 3/4] qcow2: add shrink image support, Max Reitz, 2017/06/23
- Re: [Qemu-block] [PATCH v2 3/4] qcow2: add shrink image support, Pavel Butsykin, 2017/06/26
- Re: [Qemu-block] [PATCH v2 3/4] qcow2: add shrink image support, Max Reitz, 2017/06/26
- Re: [Qemu-block] [PATCH v2 3/4] qcow2: add shrink image support, Pavel Butsykin, 2017/06/27
- Re: [Qemu-block] [PATCH v2 3/4] qcow2: add shrink image support, Max Reitz, 2017/06/28