dedup

data deduplication program
git clone git://git.2f30.org/dedup.git
Log | Files | Refs | README | LICENSE

commit 4b9498e7eb0396140d4e814f01e1bebb18c9aa77
parent 85ff1381801100535ac272abc6ff359e986f9bf2
Author: sin <sin@2f30.org>
Date:   Sat, 30 Mar 2019 16:31:37 +0000

Move index cache statistics to icache.c

Diffstat:
Mdedup.c | 11+++++------
Mdedup.h | 2++
Micache.c | 13+++++++++++++
3 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/dedup.c b/dedup.c @@ -33,8 +33,6 @@ static struct blk_hdr blk_hdr; static struct icache *icache; static int ifd; static int sfd; -static unsigned long long icache_hits; -static unsigned long long icache_misses; int verbose; char *argv0; @@ -51,6 +49,8 @@ print_md(FILE *fp, uint8_t *md, size_t size) static void print_stats(struct stats *st) { + unsigned long long hits, misses; + if (st->nr_blks == 0) return; @@ -68,8 +68,9 @@ print_stats(struct stats *st) (unsigned long long)st->max_blk_size); fprintf(stderr, "Number of unique blocks: %llu\n", (unsigned long long)st->nr_blks); - fprintf(stderr, "Index cache hits: %llu\n", icache_hits); - fprintf(stderr, "Index cache misses: %llu\n", icache_misses); + icache_stats(icache, &hits, &misses); + fprintf(stderr, "Index cache hits: %llu\n", hits); + fprintf(stderr, "Index cache hits: %llu\n", misses); } static struct snap * @@ -228,7 +229,6 @@ dedup_chunk(struct snap *snap, uint8_t *chunkp, size_t chunk_size) append_blk(compr_buf, &blk_desc); insert_icache(icache, &blk_desc); - icache_misses++; snap_hdr.st.dedup_size += blk_desc.size; snap_hdr.st.nr_blks++; @@ -239,7 +239,6 @@ dedup_chunk(struct snap *snap, uint8_t *chunkp, size_t chunk_size) snap_hdr.st.min_blk_size = blk_desc.size; } else { snap->blk_desc[snap->nr_blk_descs++] = blk_desc; - icache_hits++; } free(compr_buf); diff --git a/dedup.h b/dedup.h @@ -75,6 +75,8 @@ struct icache *alloc_icache(void); void free_icache(struct icache *icache); void insert_icache(struct icache *icache, struct blk_desc *desc); int lookup_icache(struct icache *icache, struct blk_desc *desc); +void icache_stats(struct icache *icache, unsigned long long *hits, + unsigned long long *misses); /* chunker.c */ struct chunker *alloc_chunker(int fd, size_t min_size, size_t max_size, diff --git a/icache.c b/icache.c @@ -16,6 +16,8 @@ RB_HEAD(icache_head, node); struct icache { struct icache_head nodes; + unsigned long long hits; + unsigned long long misses; }; static int @@ -93,8 +95,19 @@ lookup_icache(struct icache *icache, struct blk_desc *desc) key.desc = *desc; node = RB_FIND(icache_head, &icache->nodes, &key); if (node != NULL) { + icache->hits++; *desc = node->desc; return 0; } + icache->misses++; return -1; } + +void +icache_stats(struct icache *icache, unsigned long long *hits, + unsigned long long *misses) +{ + *hits = icache->hits; + *misses = icache->misses; +} +