From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60460) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Upfr8-0003lI-45 for qemu-devel@nongnu.org; Thu, 20 Jun 2013 10:29:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Upfqz-0001SO-WA for qemu-devel@nongnu.org; Thu, 20 Jun 2013 10:28:58 -0400 Received: from nodalink.pck.nerim.net ([62.212.105.220]:37607 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Upfqz-0001S8-Ng for qemu-devel@nongnu.org; Thu, 20 Jun 2013 10:28:49 -0400 From: =?UTF-8?q?Beno=C3=AEt=20Canet?= Date: Thu, 20 Jun 2013 16:26:25 +0200 Message-Id: <1371738392-9594-18-git-send-email-benoit@irqsave.net> In-Reply-To: <1371738392-9594-1-git-send-email-benoit@irqsave.net> References: <1371738392-9594-1-git-send-email-benoit@irqsave.net> Subject: [Qemu-devel] [RFC V8 17/24] qcow2: Drop hash for a given cluster when dedup makes refcount > 2^16/2. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, =?UTF-8?q?Beno=C3=AEt=20Canet?= , stefanha@redhat.com A new physical cluster with the same hash value will be used for further occurrence of this hash. Signed-off-by: Benoit Canet --- 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