[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 21/24] qcow2: add qcow2_cache_discard
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 21/24] qcow2: add qcow2_cache_discard |
Date: |
Tue, 26 Sep 2017 16:21:30 +0200 |
From: Pavel Butsykin <address@hidden>
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 the cache with the data in the file.
Signed-off-by: Pavel Butsykin <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
Reviewed-by: John Snow <address@hidden>
Message-id: address@hidden
Signed-off-by: Max Reitz <address@hidden>
---
block/qcow2.h | 3 +++
block/qcow2-cache.c | 26 ++++++++++++++++++++++++++
block/qcow2-refcount.c | 20 ++++++++++++++++++--
3 files changed, 47 insertions(+), 2 deletions(-)
diff --git a/block/qcow2.h b/block/qcow2.h
index 96a8d43c17..52c374e9ed 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -649,6 +649,9 @@ 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_is_table_offset(BlockDriverState *bs, Qcow2Cache *c,
+ uint64_t offset);
+void qcow2_cache_discard(BlockDriverState *bs, Qcow2Cache *c, void *table);
/* qcow2-bitmap.c functions */
int qcow2_check_bitmaps_refcounts(BlockDriverState *bs, BdrvCheckResult *res,
diff --git a/block/qcow2-cache.c b/block/qcow2-cache.c
index 1d25147392..75746a7f43 100644
--- a/block/qcow2-cache.c
+++ b/block/qcow2-cache.c
@@ -411,3 +411,29 @@ void qcow2_cache_entry_mark_dirty(BlockDriverState *bs,
Qcow2Cache *c,
assert(c->entries[i].offset != 0);
c->entries[i].dirty = true;
}
+
+void *qcow2_cache_is_table_offset(BlockDriverState *bs, Qcow2Cache *c,
+ uint64_t offset)
+{
+ int i;
+
+ for (i = 0; i < c->size; i++) {
+ if (c->entries[i].offset == offset) {
+ return qcow2_cache_get_table_addr(bs, c, i);
+ }
+ }
+ return NULL;
+}
+
+void qcow2_cache_discard(BlockDriverState *bs, Qcow2Cache *c, void *table)
+{
+ int i = qcow2_cache_get_table_idx(bs, c, table);
+
+ 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 168fc32e7b..8c17c0e3aa 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -861,8 +861,24 @@ 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]) {
- update_refcount_discard(bs, cluster_offset, s->cluster_size);
+ if (refcount == 0) {
+ void *table;
+
+ table = qcow2_cache_is_table_offset(bs, s->refcount_block_cache,
+ offset);
+ if (table != NULL) {
+ qcow2_cache_put(bs, s->refcount_block_cache, &refcount_block);
+ qcow2_cache_discard(bs, s->refcount_block_cache, table);
+ }
+
+ table = qcow2_cache_is_table_offset(bs, s->l2_table_cache, offset);
+ if (table != NULL) {
+ qcow2_cache_discard(bs, s->l2_table_cache, table);
+ }
+
+ if (s->discard_passthrough[type]) {
+ update_refcount_discard(bs, cluster_offset, s->cluster_size);
+ }
}
}
--
2.13.5
- [Qemu-block] [PULL 11/24] block: Clean up some bad code in the vvfat driver, (continued)
- [Qemu-block] [PULL 11/24] block: Clean up some bad code in the vvfat driver, Kevin Wolf, 2017/09/26
- [Qemu-block] [PULL 14/24] block: Add reopen queue to bdrv_check_perm(), Kevin Wolf, 2017/09/26
- [Qemu-block] [PULL 15/24] block: Base permissions on rw state after reopen, Kevin Wolf, 2017/09/26
- [Qemu-block] [PULL 18/24] qemu-iotests: Test change-backing-file command, Kevin Wolf, 2017/09/26
- [Qemu-block] [PULL 16/24] block: reopen: Queue children after their parents, Kevin Wolf, 2017/09/26
- [Qemu-block] [PULL 19/24] iotests: fix 181: enable postcopy-ram capability on target, Kevin Wolf, 2017/09/26
- [Qemu-block] [PULL 22/24] qcow2: add shrink image support, Kevin Wolf, 2017/09/26
- [Qemu-block] [PULL 20/24] qemu-img: add --shrink flag for resize, Kevin Wolf, 2017/09/26
- [Qemu-block] [PULL 23/24] qemu-iotests: add shrinking image test, Kevin Wolf, 2017/09/26
- [Qemu-block] [PULL 24/24] block/qcow2-bitmap: fix use of uninitialized pointer, Kevin Wolf, 2017/09/26
- [Qemu-block] [PULL 21/24] qcow2: add qcow2_cache_discard,
Kevin Wolf <=
- Re: [Qemu-block] [PULL 00/24] Block layer patches, Peter Maydell, 2017/09/27