[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC V5 20/62] qcow2: Drop hash for a given cluster when de
From: |
Benoît Canet |
Subject: |
[Qemu-devel] [RFC V5 20/62] qcow2: Drop hash for a given cluster when dedup makes refcount > 2^16/2. |
Date: |
Wed, 16 Jan 2013 16:47:59 +0100 |
A new physical cluster with the same hash value will be used for further
occurence of this hash.
---
block/qcow2-dedup.c | 32 ++++++++++++++++++++++++++++++++
block/qcow2-refcount.c | 3 +++
block/qcow2.h | 4 ++++
3 files changed, 39 insertions(+)
diff --git a/block/qcow2-dedup.c b/block/qcow2-dedup.c
index 25ecefa..9eba773 100644
--- a/block/qcow2-dedup.c
+++ b/block/qcow2-dedup.c
@@ -941,3 +941,35 @@ int qcow2_dedup_store_new_hashes(BlockDriverState *bs,
return ret;
}
+
+/* Force to use a new physical cluster and QCowHashNode when the refcount pass
+ * 2^16/2.
+ *
+ * @cluster_index: the index of the physical cluster
+ */
+void qcow2_dedup_refcount_half_max_reached(BlockDriverState *bs,
+ uint64_t cluster_index)
+{
+ BDRVQcowState *s = bs->opaque;
+ QCowHashNode *hash_node;
+ uint64_t physical_sect = cluster_index * s->cluster_sectors;
+
+ hash_node = g_tree_lookup(s->dedup_tree_by_sect, &physical_sect);
+
+ if (!hash_node) {
+ return;
+ }
+
+ /* mark this hash so we won't load it anymore at startup after writing it
*/
+ hash_node->first_logical_sect |= QCOW_FLAG_HALF_MAX_REFCOUNT;
+
+ /* write to disk */
+ qcow2_dedup_read_write_hash(bs,
+ &hash_node->hash,
+ &hash_node->first_logical_sect,
+ hash_node->physical_sect,
+ true);
+
+ /* remove the QCowHashNode from ram so we won't use it anymore for dedup */
+ qcow2_remove_hash_node(bs, hash_node);
+}
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index b1ad112..ac396c4 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -489,6 +489,9 @@ int QEMU_WARN_UNUSED_RESULT
update_refcount(BlockDriverState *bs,
ret = -EINVAL;
goto fail;
}
+ if (s->has_dedup && deduplication && refcount >= 0xFFFF/2) {
+ qcow2_dedup_refcount_half_max_reached(bs, cluster_index);
+ }
if (refcount == 0 && cluster_index < s->free_cluster_index) {
s->free_cluster_index = cluster_index;
}
diff --git a/block/qcow2.h b/block/qcow2.h
index 5c126be..ba10ed0 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -65,6 +65,8 @@
#define DEFAULT_CLUSTER_SIZE 65536
#define HASH_LENGTH 32
+/* indicate that this cluster refcount has reached its maximum value */
+#define QCOW_FLAG_HALF_MAX_REFCOUNT (1LL << 61)
/* indicate that the hash structure is empty and miss offset */
#define QCOW_FLAG_EMPTY (1LL << 62)
/* indicate that the cluster for this hash has QCOW_OFLAG_COPIED on disk */
@@ -499,5 +501,7 @@ int qcow2_dedup_store_new_hashes(BlockDriverState *bs,
int count,
uint64_t logical_sect,
uint64_t physical_sect);
+void qcow2_dedup_refcount_half_max_reached(BlockDriverState *bs,
+ uint64_t cluster_index);
#endif
--
1.7.10.4
- [Qemu-devel] [RFC V5 08/62] qcow2: Implement qcow2_compute_cluster_hash., (continued)
- [Qemu-devel] [RFC V5 08/62] qcow2: Implement qcow2_compute_cluster_hash., Benoît Canet, 2013/01/16
- [Qemu-devel] [RFC V5 07/62] qcow2: Add qcow2_dedup_store_new_hashes., Benoît Canet, 2013/01/16
- [Qemu-devel] [RFC V5 06/62] qcow2: Add qcow2_dedup and related functions, Benoît Canet, 2013/01/16
- [Qemu-devel] [RFC V5 10/62] qcow2: Add qcow2_dedup_grow_table and use it., Benoît Canet, 2013/01/16
- [Qemu-devel] [RFC V5 09/62] qcow2: Extract qcow2_dedup_grow_table, Benoît Canet, 2013/01/16
- [Qemu-devel] [RFC V5 11/62] qcow2: Makes qcow2_alloc_cluster_link_l2 mark to deduplicate clusters., Benoît Canet, 2013/01/16
- [Qemu-devel] [RFC V5 12/62] qcow2: make the deduplication forget a cluster hash when a cluster is to dedupe, Benoît Canet, 2013/01/16
- [Qemu-devel] [RFC V5 17/62] qcow2: Extract qcow2_add_feature and qcow2_remove_feature., Benoît Canet, 2013/01/16
- [Qemu-devel] [RFC V5 18/62] block: Add qemu-img dedup create option., Benoît Canet, 2013/01/16
- [Qemu-devel] [RFC V5 22/62] qcow2: Add qcow2_dedup_is_running to probe if dedup is running., Benoît Canet, 2013/01/16
- [Qemu-devel] [RFC V5 20/62] qcow2: Drop hash for a given cluster when dedup makes refcount > 2^16/2.,
Benoît Canet <=
- [Qemu-devel] [RFC V5 19/62] qcow2: Add a deduplication boolean to update_refcount., Benoît Canet, 2013/01/16
- [Qemu-devel] [RFC V5 27/62] qcow2: Add check_dedup_l2 in order to check l2 of dedup table., Benoît Canet, 2013/01/16
- [Qemu-devel] [RFC V5 30/62] qcow2: Add lazy refcounts to deduplication to prevent qcow2_cache_set_dependency loops, Benoît Canet, 2013/01/16
- [Qemu-devel] [RFC V5 29/62] qcow2: Integrate SKEIN hash algorithm in deduplication., Benoît Canet, 2013/01/16
- [Qemu-devel] [RFC V5 33/62] qemu-iotests: Filter dedup=on/off so existing tests don't break., Benoît Canet, 2013/01/16
- [Qemu-devel] [RFC V5 31/62] qcow2: Use large L2 table for deduplication., Benoît Canet, 2013/01/16
- [Qemu-devel] [RFC V5 32/62] qcow: Set large dedup hash block size., Benoît Canet, 2013/01/16
- [Qemu-devel] [RFC V5 34/62] qcow2: Add qcow2_dedup_init and qcow2_dedup_close., Benoît Canet, 2013/01/16
- [Qemu-devel] [RFC V5 36/62] qcow2: Enable the deduplication feature., Benoît Canet, 2013/01/16
- [Qemu-devel] [RFC V5 38/62] qcow2: Initialize deduplication metrics., Benoît Canet, 2013/01/16