QCOW2 deduplication metrics
RFC 3/14 qcow2: Collect unaligned writes missing data reads metric.
In reply to Benoît Canet--- block/qcow2-dedup.c | 2 ++ 1 file changed, 2 insertions(+)
block/qcow2-dedup.c +2 -0
@@ -130,6 +130,7 @@ int qcow2_dedup_read_missing_and_concatenate(BlockDriverState *bs,/* read beginning */ if (cluster_beginning_nr) { + s->dedup_metrics.missing_data_reads++; ret = qcow2_read_cluster_data(bs, *data, cluster_beginning_sector,
@@ -153,6 +154,7 @@ int qcow2_dedup_read_missing_and_concatenate(BlockDriverState *bs,/* read and add ending */ if (cluster_ending_nr) { + s->dedup_metrics.missing_data_reads++; ret = qcow2_read_cluster_data(bs, *data + (cluster_beginning_nr +
Signature · 1 line
1.7.10.4
RFC 2/14 qcow2: Initialize deduplication metrics.
In reply to Benoît Canet--- block/qcow2-dedup.c | 2 ++ 1 file changed, 2 insertions(+)
block/qcow2-dedup.c +2 -0
@@ -1272,6 +1272,8 @@ int qcow2_dedup_init(BlockDriverState *bs) s->has_dedup = true; +memset (&s->dedup_metrics,0 ,sizeof (s->dedup_metrics)); + ret =qcow2_dedup_alloc (bs);if (ret <0 ) {
Signature · 1 line
1.7.10.4
RFC 5/14 qcow2: Collect undeduplicated cluster metric.
In reply to Benoît Canet--- block/qcow2-dedup.c | 2 ++ 1 file changed, 2 insertions(+)
block/qcow2-dedup.c +2 -0
@@ -524,6 +524,7 @@ static int qcow2_count_next_non_dedupable_clusters(BlockDriverState *bs, uint8_t *data, int left_to_process) { +BDRVQcowState *s = bs->opaque;int i;int ret =0 ;QCowHashNode *hash_node;
@@ -546,6 +547,7 @@ static int qcow2_count_next_non_dedupable_clusters(BlockDriverState *bs,qcow2_build_and_insert_hash_node (bs, &ds->phash.hash);add_hash_to_undedupable_list (bs, ds); + s->dedup_metrics.non_deduplicated_clusters++; }return i;
Signature · 1 line
1.7.10.4
RFC 1/14 qcow2: Add deduplication metrics structures.
In reply to Benoît Canet--- block/qcow2.h | 3 ++- include/block/block.h | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-)
block/qcow2.h +2 -1
@@ -237,9 +237,10 @@ typedef struct BDRVQcowState {int32_t dedup_table_size;GTree *dedup_tree_by_hash;GTree *dedup_tree_by_sect; +CoMutex dedup_lock; +BlockDeduplicationMetrics dedup_metrics;CoMutex lock; -CoMutex dedup_lock;uint32_t crypt_method;/* current crypt method, 0 if no key yet */ uint32_t crypt_method_header;
include/block/block.h +11 -0
@@ -12,6 +12,17 @@typedef struct BlockDriver BlockDriver ;typedef struct BlockJob BlockJob ; +typedef struct { +uint64_t deduplicated_clusters; +uint64_t non_deduplicated_clusters; +uint64_t missing_data_reads;/* reads used to complete partials clusters */ +uint64_t ram_hash_creations;/* RAM based lookup */ +uint64_t ram_hash_deletions;/* RAM based lookup */ +uint64_t ram_usage;/* RAM usage in bytes */ +uint64_t deleted_clusters;/* number of deleted clusters */ +uint64_t refcount_overflows;/* number of refcount overflows */ +}BlockDeduplicationMetrics ; + typedef struct BlockDriverInfo { /* in bytes, 0 if irrelevant */ int cluster_size;
Signature · 1 line
1.7.10.4
RFC 4/14 qcow2: Collect deduplicated cluster metric.
In reply to Benoît Canet--- block/qcow2-dedup.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
block/qcow2-dedup.c +8 -4
@@ -400,10 +400,14 @@ static int qcow2_deduplicate_cluster(BlockDriverState *bs, }/* Increment the refcount of the cluster */ -return update_refcount (bs, - (hash_node->physical_sect / - s->cluster_sectors) << s->cluster_bits, -1 ,1 , true); + ret =update_refcount (bs, + (hash_node->physical_sect / + s->cluster_sectors) << s->cluster_bits, +1 ,1 , true); + + s->dedup_metrics.deduplicated_clusters++; + +return ret; }/* This function tries to deduplicate a given cluster.
Signature · 1 line
1.7.10.4
cover QCOW2 deduplication metrics
This patchset implements QMP metrics for the qcow2 deduplication.
It applies on top of the "QCOW2 deduplication core functionality" patchset.
Benoît Canet (14):
qcow2: Add deduplication metrics structures.
qcow2: Initialize deduplication metrics.
qcow2: Collect unaligned writes missing data reads metric.
qcow2: Collect deduplicated cluster metric.
qcow2: Collect undeduplicated cluster metric.
qcow2: Count QCowHashNode creation metrics.
qcow2: Count QCowHashNode removal from tree for metrics.
qcow2: Count cluster deleted metric
qcow2: Count deduplication refcount overflow metric.
qapi: Add support for deduplication infos in qapi-schema.json.
block: Add deduplication metrics to BlockDriverInfo.
qcow2: Add qcow2_dedup_update_metrics to compute dedup RAM usage.
qcow2: returns deduplication metrics and status via bdrv_get_info()
qapi: Return virtual block device deduplication metrics in QMP
block.c | 36 ++++++++++++++++++++++++++++++++++++ block/qcow2-dedup.c | 36 ++++++++++++++++++++++++++++++++---- block/qcow2.c | 4 ++++ block/qcow2.h | 4 +++- include/block/block.h | 14 ++++++++++++++ qapi-schema.json | 40 +++++++++++++++++++++++++++++++++++++++- 6 files changed, 128 insertions(+), 6 deletions(-)
Signature · 1 line
1.7.10.4
RFC 8/14 qcow2: Count cluster deleted metric
--- block/qcow2-dedup.c | 1 + 1 file changed, 1 insertion(+)
block/qcow2-dedup.c +1 -0
@@ -991,6 +991,7 @@ void qcow2_dedup_refcount_zero_reached(BlockDriverState *bs,/* remove from ram if present so we won't dedup with it anymore */ qcow2_remove_hash_node_by_sector (bs, physical_sect); + s->dedup_metrics.deleted_clusters++; }/* Force to use a new physical cluster and QCowHashNode when the refcount pass
Signature · 1 line
1.7.10.4
RFC 9/14 qcow2: Count deduplication refcount overflow metric.
In reply to Benoît Canet--- block/qcow2-dedup.c | 1 + 1 file changed, 1 insertion(+)
block/qcow2-dedup.c +1 -0
@@ -1024,6 +1024,7 @@ void qcow2_dedup_refcount_half_max_reached(BlockDriverState *bs,/* remove the QCowHashNode from ram so we won't use it anymore for dedup */ qcow2_remove_hash_node (bs, hash_node); + s->dedup_metrics.refcount_overflows++; }bool qcow2_dedup_is_running (BlockDriverState *bs)
Signature · 1 line
1.7.10.4
RFC 7/14 qcow2: Count QCowHashNode removal from tree for metrics.
In reply to Benoît Canet--- block/qcow2-dedup.c | 1 + 1 file changed, 1 insertion(+)
block/qcow2-dedup.c +1 -0
@@ -841,6 +841,7 @@ static void qcow2_remove_hash_node(BlockDriverState *bs,BDRVQcowState *s = bs->opaque;g_tree_remove (s->dedup_tree_by_sect, &hash_node->physical_sect);g_tree_remove (s->dedup_tree_by_hash, &hash_node->hash); + s->dedup_metrics.ram_hash_deletions++; }/* This function removes a hash_node from the trees given a physical sector
Signature · 1 line
1.7.10.4
RFC 6/14 qcow2: Count QCowHashNode creation metrics.
In reply to Benoît Canet--- block/qcow2-dedup.c | 2 ++ 1 file changed, 2 insertions(+)
block/qcow2-dedup.c +2 -0
@@ -289,6 +289,7 @@ static void qcow2_build_and_insert_hash_node(BlockDriverState *bs,QCOW_FLAG_EMPTY , QCOW_FLAG_EMPTY);g_tree_insert (s->dedup_tree_by_hash, &hash_node->hash, hash_node); + s->dedup_metrics.ram_hash_creations++; }/*
@@ -1043,6 +1044,7 @@ static void qcow2_dedup_insert_hash_node(BlockDriverState *bs,g_tree_insert (s->dedup_tree_by_hash, &hash_node->hash, hash_node);g_tree_insert (s->dedup_tree_by_sect, &hash_node->physical_sect, hash_node); + s->dedup_metrics.ram_hash_creations++; }/* This load the QCowHashNode corresponding to a given cluster index into ram
Signature · 1 line
1.7.10.4
RFC 11/14 block: Add deduplication metrics to BlockDriverInfo.
In reply to Benoît Canet--- include/block/block.h | 3 +++ 1 file changed, 3 insertions(+)
include/block/block.h +3 -0
@@ -29,6 +29,9 @@ typedef struct BlockDriverInfo {/* offset at which the VM state can be saved (0 if not possible) */ int64_t vm_state_offset;bool is_dirty; +bool has_dedup; +bool dedup_running; +BlockDeduplicationMetrics dedup_metrics; } BlockDriverInfo; typedef struct BlockFragInfo {
Signature · 1 line
1.7.10.4
RFC 12/14 qcow2: Add qcow2_dedup_update_metrics to compute dedup RAM usage.
In reply to Benoît Canet--- block/qcow2-dedup.c | 13 +++++++++++++ block/qcow2.h | 1 + 2 files changed, 14 insertions(+)
block/qcow2-dedup.c +13 -0
@@ -1311,3 +1311,16 @@ void qcow2_dedup_close(BlockDriverState *bs) {qcow2_dedup_free (bs); } + +#define GTREE_NODE_SIZE sizeof(int) * 5 + +void qcow2_dedup_update_metrics (BlockDriverState *bs) +{ +BDRVQcowState *s = bs->opaque; + +uint64_t nb_hashs = s->dedup_metrics.ram_hash_creations - + s->dedup_metrics.ram_hash_deletions; + + s->dedup_metrics.ram_usage = nb_hashs *GTREE_NODE_SIZE *2 ; + s->dedup_metrics.ram_usage += nb_hashs *sizeof (QCowHashNode); +}
block/qcow2.h +1 -0
@@ -510,5 +510,6 @@ void qcow2_dedup_refcount_half_max_reached(BlockDriverState *bs,bool qcow2_dedup_is_running (BlockDriverState *bs);int qcow2_dedup_init (BlockDriverState *bs);void qcow2_dedup_close (BlockDriverState *bs); +void qcow2_dedup_update_metrics (BlockDriverState *bs);#endif
Signature · 1 line
1.7.10.4
RFC 10/14 qapi: Add support for deduplication infos in qapi-schema.json.
In reply to Benoît Canet--- qapi-schema.json | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-)
qapi-schema.json +39 -1
@@ -720,6 +720,40 @@ { 'command': 'query-block', 'returns': ['BlockInfo'] } ## +# @BlockDeviceDedupInfo +# +# Statistics of the deduplication on a virtual block device implementing it +# since QEMU startup. +# +# @deduplicated-clusters: Number of clusters which where deduplicated. +# +# @non-deduplicated-clusters: Number of clusters which where not deduplicated. +# +# @missing-data-reads: Number of reads which where done to complete +# unaligned or sub cluster sized writes. +# +# @ram-hash-creations: Number of cluster hash created in RAM. +# +# @ram-hash-deletions: Number of cluster hash deleted in RAM. +# +# @ram-usage: Number of bytes of RAM used. +# +# @deleted-clusters: Number of deleted cluster when refcount < 0 +# +# @refcount-overflows: Number of refcount overflows +# +# @running: True if deduplication is running +# +# Since: 1.5.0 +## +{ 'type': 'BlockDeviceDedupInfo', + 'data': {'deduplicated-clusters': 'int', 'non-deduplicated-clusters': 'int', + 'missing-data-reads': 'int', 'ram-hash-creations': 'int', + 'ram-hash-deletions': 'int', 'ram-usage': 'int', + 'deleted-clusters': 'int', 'refcount-overflows': 'int', + 'running': 'bool' } } + +## # @BlockDeviceStats: # # Statistics of a virtual block device or a block backing device.
@@ -747,13 +781,17 @@ # growable sparse files (like qcow2) that are used on top # of a physical device. # +# @deduplication: #optional @BlockDeviceDedupInfo describing deduplication +# metrics (since 1.5) +# # Since: 0.14.0 ## { 'type': 'BlockDeviceStats', 'data': {'rd_bytes': 'int', 'wr_bytes': 'int', 'rd_operations': 'int', 'wr_operations': 'int', 'flush_operations': 'int', 'flush_total_time_ns': 'int', 'wr_total_time_ns': 'int', - 'rd_total_time_ns': 'int', 'wr_highest_offset': 'int' } } + 'rd_total_time_ns': 'int', 'wr_highest_offset': 'int', + '*deduplication': 'BlockDeviceDedupInfo' } } ## # @BlockStats:
Signature · 1 line
1.7.10.4
RFC 13/14 qcow2: returns deduplication metrics and status via bdrv_get_info()
In reply to Benoît Canet--- block/qcow2.c | 4 ++++ 1 file changed, 4 insertions(+)
block/qcow2.c +4 -0
@@ -1868,6 +1868,10 @@ static int qcow2_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)BDRVQcowState *s = bs->opaque; bdi->cluster_size = s->cluster_size; bdi->vm_state_offset =qcow2_vm_state_offset (s); + bdi->has_dedup = s->has_dedup; + bdi->dedup_running = s->dedup_status ==QCOW_DEDUP_STARTED ; +qcow2_dedup_update_metrics (bs); +memcpy (&bdi->dedup_metrics, &s->dedup_metrics,sizeof (bdi->dedup_metrics));return 0 ; }
Signature · 1 line
1.7.10.4
RFC 14/14 qapi: Return virtual block device deduplication metrics in QMP
In reply to Benoît Canet--- block.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
block.c +36 -0
@@ -2921,6 +2921,40 @@ BlockInfoList *qmp_query_block(Error **errp)return head; } +static void bdrv_get_dedup_metrics (const BlockDriverState *bs, +BlockDeviceStats *stats) +{ +BlockDriverInfo bdi; + +if (bdrv_get_info ((BlockDriverState *) bs, &bdi) <0 ) { +return ; + } + +if (!bdi.has_dedup) { +return ; + } + + stats->has_deduplication = true; + stats->deduplication =g_malloc0 (sizeof (*stats->deduplication)); + stats->deduplication->deduplicated_clusters = + bdi.dedup_metrics.deduplicated_clusters; + stats->deduplication->non_deduplicated_clusters = + bdi.dedup_metrics.non_deduplicated_clusters; + stats->deduplication->missing_data_reads = + bdi.dedup_metrics.missing_data_reads; + stats->deduplication->ram_hash_creations = + bdi.dedup_metrics.ram_hash_creations; + stats->deduplication->ram_hash_deletions = + bdi.dedup_metrics.ram_hash_deletions; + stats->deduplication->ram_usage = + bdi.dedup_metrics.ram_usage; + stats->deduplication->deleted_clusters = + bdi.dedup_metrics.deleted_clusters; + stats->deduplication->refcount_overflows = + bdi.dedup_metrics.refcount_overflows; + stats->deduplication->running = bdi.dedup_running; +} +BlockStats *bdrv_query_stats (const BlockDriverState *bs) {BlockStats *s;
@@ -2943,6 +2977,8 @@ BlockStats *bdrv_query_stats(const BlockDriverState *bs) s->stats->rd_total_time_ns = bs->total_time_ns[BDRV_ACCT_READ ]; s->stats->flush_total_time_ns = bs->total_time_ns[BDRV_ACCT_FLUSH ]; +bdrv_get_dedup_metrics (bs, s->stats); +if (bs->file) { s->has_parent = true; s->parent =bdrv_query_stats (bs->file);
Signature · 1 line
1.7.10.4
Re: [Qemu-devel] [RFC V1 10/14] qapi: Add support for deduplication infos in qapi-schema.json.
In reply to Benoît CanetReview
Quoted 7 lines · Benoît Canet
--- qapi-schema.json | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-)(quoted diff) +2
-0+# +# @deleted-clusters: Number of deleted cluster when refcount < 0
Is it really when refcount goes negative, or when it reaches zero? Overall it seems nice.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [RFC V1 12/14] qcow2: Add qcow2_dedup_update_metrics to compute dedup RAM usage.
In reply to Benoît CanetQuoted 10 lines · Benoît Canet
--- block/qcow2-dedup.c | 13 +++++++++++++ block/qcow2.h | 1 + 2 files changed, 14 insertions(+)block/qcow2-dedup.c +0
-0
block/qcow2-dedup.c void qcow2_dedup_close(BlockDriverState *bs) · line 1315
Quoted 5 lines
block/qcow2-dedup.c +2
-0@@ -1311,3 +1311,16 @@ void qcow2_dedup_close(BlockDriverState *bs) {qcow2_dedup_free (bs); } + +#define GTREE_NODE_SIZE sizeof(int) * 5
Improperly parenthesized. Also, this feels like a magic number, is there an actual sizeof(struct) you could use instead of hand-computing how much is used per node?
block/qcow2-dedup.c void qcow2_dedup_close(BlockDriverState *bs) · line 1324
Quoted 9 lines
block/qcow2-dedup.c +9
-0+ +void qcow2_dedup_update_metrics (BlockDriverState *bs) +{ +BDRVQcowState *s = bs->opaque; + +uint64_t nb_hashs = s->dedup_metrics.ram_hash_creations - + s->dedup_metrics.ram_hash_deletions; + + s->dedup_metrics.ram_usage = nb_hashs *GTREE_NODE_SIZE *2 ;
But you got lucky that order of operations didn't care about the missing () here.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [RFC V1 12/14] qcow2: Add qcow2_dedup_update_metrics to compute dedup RAM usage.
Quoted 6 lines · Eric Blake
Quoted 5 lines · Benoît Canet
--- block/qcow2-dedup.c | 13 +++++++++++++ block/qcow2.h | 1 + 2 files changed, 14 insertions(+)
Quoted 14 lines
block/qcow2-dedup.c void qcow2_dedup_close(BlockDriverState *bs) · line 1315
Quoted 10 lines
block/qcow2-dedup.c +2
-0@@ -1311,3 +1311,16 @@ void qcow2_dedup_close(BlockDriverState *bs) {qcow2_dedup_free (bs); } + +#define GTREE_NODE_SIZE sizeof(int) * 5Improperly parenthesized. Also, this feels like a magic number, is there an actual sizeof(struct) you could use instead of hand-computing how much is used per node?
No the glib implementation totally hide it's structures.
Re: [Qemu-devel] [RFC V1 10/14] qapi: Add support for deduplication infos in qapi-schema.json.
In reply to Benoît CanetQuoted 1 line
+# @running: True if deduplication is running
Internally QCOW2 deduplication state switch between STOPPED, STARTING, RUNNING and STOPPING.
Should the running field be a status field reflecting all theses states in a string for example ?
Or is the boolean ok ?
Regards
Benoît
Re: [Qemu-devel] [RFC V1 10/14] qapi: Add support for deduplication infos in qapi-schema.json.
Quoted 8 lines · Benoît Canet
Quoted 1 line
+# @running: True if deduplication is running
Internally QCOW2 deduplication state switch between STOPPED, STARTING, RUNNING and STOPPING.
Should the running field be a status field reflecting all theses states in a string for example ?
Or is the boolean ok ?
Outputting an enum of all four states may be the best for debugging purposes.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [RFC V1 12/14] qcow2: Add qcow2_dedup_update_metrics to compute dedup RAM usage.
In reply to Benoît CanetQuoted 22 lines · Benoît Canet
Quoted 6 lines · Eric Blake
Quoted 5 lines · Benoît Canet
--- block/qcow2-dedup.c | 13 +++++++++++++ block/qcow2.h | 1 + 2 files changed, 14 insertions(+)Quoted 14 lines
block/qcow2-dedup.c void qcow2_dedup_close(BlockDriverState *bs) · line 1315
Quoted 10 lines
block/qcow2-dedup.c +2
-0@@ -1311,3 +1311,16 @@ void qcow2_dedup_close(BlockDriverState *bs) {qcow2_dedup_free (bs); } + +#define GTREE_NODE_SIZE sizeof(int) * 5Improperly parenthesized. Also, this feels like a magic number, is there an actual sizeof(struct) you could use instead of hand-computing how much is used per node?
Quoted 1 line
No the glib implementation totally hide it's structures.
Also, are you sure that this value is correct on both 32-bit and 64-bit machines, or does a gtree node include a void* which changes how much memory it uses based on platform? Even adding a comment pointing to the internal glib implementation that you were copying from would be helpful, so that it doesn't feel quite so magic.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org