[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC V7 20/32] qcow2: Drop hash for a given cluster when de
From: |
Benoît Canet |
Subject: |
[Qemu-devel] [RFC V7 20/32] qcow2: Drop hash for a given cluster when dedup makes refcount > 2^16/2. |
Date: |
Fri, 15 Mar 2013 15:49:34 +0100 |
A new physical cluster with the same hash value will be used for further
occurrence of this hash.
Signed-off-by: Benoit Canet <address@hidden>
---
block/qcow2-dedup.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 49 insertions(+), 5 deletions(-)
diff --git a/block/qcow2-dedup.c b/block/qcow2-dedup.c
index 2aca01a..e017721 100644
--- a/block/qcow2-dedup.c
+++ b/block/qcow2-dedup.c
@@ -38,6 +38,8 @@ static int qcow2_dedup_read_write_hash(BlockDriverState *bs,
uint64_t *first_logical_sect,
uint64_t physical_sect,
bool write);
+static void qcow2_remove_hash_node(BlockDriverState *bs,
+ QCowHashNode *hash_node);
bool qcow2_must_deduplicate(BlockDriverState *bs)
{
@@ -416,6 +418,38 @@ static int
qcow2_clear_l2_copied_flag_if_needed(BlockDriverState *bs,
true);
}
+/* Force to use a new physical cluster and QCowHashNode when the refcount pass
+ * 2^16/2.
+ *
+ * @cluster_index: the index of the physical cluster
+ * @ret: 0 on success, -errno on error
+ */
+static int qcow2_dedup_refcount_half_max_reached(BlockDriverState *bs,
+ uint64_t cluster_index,
+ QCowHashNode *hash_node)
+{
+ int ret = 0;
+
+ /* mark this hash so we won't load it anymore at startup after writing it
*/
+ hash_node->first_logical_sect |= QCOW_DEDUP_FLAG_HALF_MAX_REFCOUNT;
+
+ /* write to disk */
+ ret = qcow2_dedup_read_write_hash(bs,
+ &hash_node->hash,
+ &hash_node->first_logical_sect,
+ hash_node->physical_sect,
+ true);
+
+ if (ret < 0) {
+ return ret;
+ }
+
+ /* remove the QCowHashNode from ram so we won't use it anymore for dedup */
+ qcow2_remove_hash_node(bs, hash_node);
+
+ return 0;
+}
+
/* This function deduplicate a cluster
*
* @logical_sect: The logical sector of the write
@@ -428,13 +462,23 @@ static int qcow2_deduplicate_cluster(BlockDriverState *bs,
{
BDRVQcowState *s = bs->opaque;
uint64_t cluster_index = hash_node->physical_sect / s->cluster_sectors;
- int ret = 0;
+ int refcount, ret = 0;
/* Increment the refcount of the cluster */
- ret = qcow2_update_cluster_refcount(bs,
- cluster_index,
- 1,
- false);
+ refcount = qcow2_update_cluster_refcount(bs,
+ cluster_index,
+ 1,
+ false);
+
+ if (refcount < 0) {
+ return ret;
+ }
+
+ if (refcount >= 0xFFFF/2) {
+ ret = qcow2_dedup_refcount_half_max_reached(bs,
+ cluster_index,
+ hash_node);
+ }
if (ret < 0) {
return ret;
--
1.7.10.4
- [Qemu-devel] [RFC V7 10/32] qcow2: Implement qcow2_compute_cluster_hash., (continued)
- [Qemu-devel] [RFC V7 10/32] qcow2: Implement qcow2_compute_cluster_hash., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 12/32] qcow2: Makes qcow2_alloc_cluster_link_l2 mark to deduplicate clusters., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 11/32] qcow2: Add qcow2_dedup_grow_table and use it., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 13/32] qcow2: make the deduplication forget a cluster hash when a cluster is to dedupe, Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 14/32] qcow2: Create qcow2_is_cluster_to_dedup., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 16/32] qcow2: Extract qcow2_do_table_init., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 15/32] qcow2: Load and save deduplication table header extension., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 17/32] qcow2-cache: Allow to choose table size at creation., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 21/32] qcow2: Remove hash when cluster is deleted., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 22/32] qcow2: Add qcow2_dedup_is_running to probe if dedup is running., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 20/32] qcow2: Drop hash for a given cluster when dedup makes refcount > 2^16/2.,
Benoît Canet <=
- [Qemu-devel] [RFC V7 24/32] qcow2: Serialize write requests when deduplication is activated., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 23/32] qcow2: Integrate deduplication in qcow2_co_writev loop., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 19/32] block: Add qcow2_dedup format and image creation code., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 25/32] qcow2: Adapt checking of QCOW_OFLAG_COPIED for dedup., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 26/32] qcow2: Add check_dedup_l2 in order to check l2 of dedup table., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 27/32] qcow2: Add verification of dedup table., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 30/32] qcow2: Add qcow2_dedup_init and qcow2_dedup_close., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 28/32] qcow2: Integrate SKEIN hash algorithm in deduplication., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 29/32] qcow: Set large dedup hash block size., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 32/32] qcow2: Enable the deduplication feature., Benoît Canet, 2013/03/15