qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC V8 17/24] qcow2: Drop hash for a given cluster when de


From: Benoît Canet
Subject: [Qemu-devel] [RFC V8 17/24] qcow2: Drop hash for a given cluster when dedup makes refcount > 2^16/2.
Date: Thu, 20 Jun 2013 16:26:25 +0200

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 |   20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/block/qcow2-dedup.c b/block/qcow2-dedup.c
index 2d2c15c..da4ad5c 100644
--- a/block/qcow2-dedup.c
+++ b/block/qcow2-dedup.c
@@ -305,12 +305,24 @@ static int qcow2_deduplicate_cluster(BlockDriverState *bs,
 {
     BDRVQcowState *s = bs->opaque;
     uint64_t cluster_index = hash_info->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);
+    refcount = qcow2_update_cluster_refcount(bs,
+                                             cluster_index,
+                                             1);
+
+    if (refcount < 0) {
+        return refcount;
+    }
+
+    /* if we reached half the max refcount delete the QCowHashInfo from the
+     * store so the next time this cluster will be seen it will be handled as
+     * new
+     */
+    if (refcount >= 0xFFFF/2) {
+        ret = qcow2_store_delete(bs, &s->key_value_store, hash_info);
+    }
 
     if (ret < 0) {
         return ret;
-- 
1.7.10.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]