#include "../fio_time.h"
#include "../lib/bloom.h"
-
-FILE *f_err;
-struct timeval *fio_tv = NULL;
-unsigned int fio_debug = 0;
-
-void __dprint(int type, const char *str, ...)
-{
-}
+#include "debug.h"
struct worker_thread {
pthread_t thread;
return ret;
}
-static int read_block(int fd, void *buf, off_t offset)
+static int __read_block(int fd, void *buf, off_t offset, size_t count)
{
ssize_t ret;
- ret = pread(fd, buf, blocksize, offset);
+ ret = pread(fd, buf, count, offset);
if (ret < 0) {
perror("pread");
return 1;
} else if (!ret)
return 1;
- else if (ret != blocksize) {
+ else if (ret != count) {
log_err("dedupe: short read on block\n");
return 1;
}
return 0;
}
+static int read_block(int fd, void *buf, off_t offset)
+{
+ return __read_block(fd, buf, offset, blocksize);
+}
+
static void add_item(struct chunk *c, struct item *i)
{
/*
fio_md5_final(&ctx);
}
+static unsigned int read_blocks(int fd, void *buf, off_t offset, size_t size)
+{
+ if (__read_block(fd, buf, offset, size))
+ return 0;
+
+ return size / blocksize;
+}
+
static int do_work(struct worker_thread *thread, void *buf)
{
unsigned int nblocks, i;
off_t offset;
- int err = 0, nitems = 0;
+ int nitems = 0;
uint64_t ndupes = 0;
struct item *items;
- nblocks = thread->size / blocksize;
offset = thread->cur_offset;
+
+ nblocks = read_blocks(thread->fd, buf, offset, min(thread->size, (uint64_t)chunk_size));
+ if (!nblocks)
+ return 1;
+
items = malloc(sizeof(*items) * nblocks);
for (i = 0; i < nblocks; i++) {
- if (read_block(thread->fd, buf, offset))
- break;
+ void *thisptr = buf + (i * blocksize);
+
if (items)
items[i].offset = offset;
- crc_buf(buf, items[i].hash);
+ crc_buf(thisptr, items[i].hash);
offset += blocksize;
nitems++;
}
free(items);
thread->items += nitems;
thread->dupes += ndupes;
- return err;
+ return 0;
}
static void *thread_fn(void *data)
struct worker_thread *thread = data;
void *buf;
- buf = fio_memalign(blocksize, blocksize);
+ buf = fio_memalign(blocksize, chunk_size);
do {
if (get_work(&thread->cur_offset, &thread->size)) {
} while (1);
thread->done = 1;
- fio_memfree(buf, blocksize);
+ fio_memfree(buf, chunk_size);
return NULL;
}
unsigned long nitems = 0;
uint64_t tdiff;
float perc;
- int some_done;
+ int some_done = 0;
int i;
for (i = 0; i < num_threads; i++) {
this_items *= blocksize;
tdiff = mtime_since_now(&last_tv);
if (tdiff) {
- this_items /= tdiff;
+ this_items = (this_items * 1000) / (tdiff * 1024);
printf("%3.2f%% done (%luKB/sec)\r", perc, this_items);
last_nitems = nitems;
fio_gettime(&last_tv, NULL);
if (use_bloom) {
uint64_t bloom_entries;
- bloom_entries = (3 * dev_size ) / (blocksize * 2);
+ bloom_entries = 8 * (dev_size / blocksize);
bloom = bloom_new(bloom_entries);
}
static void show_stat(uint64_t nextents, uint64_t nchunks)
{
- double perc;
+ double perc, ratio;
printf("Extents=%lu, Unique extents=%lu\n", (unsigned long) nextents, (unsigned long) nchunks);
- printf("De-dupe factor: %3.2f\n", (double) nextents / (double) nchunks);
+
+ if (nchunks) {
+ ratio = (double) nextents / (double) nchunks;
+ printf("De-dupe ratio: 1:%3.2f\n", ratio - 1.0);
+ } else
+ printf("De-dupe ratio: 1:infinite\n");
perc = 1.00 - ((double) nchunks / (double) nextents);
perc *= 100.0;
int main(int argc, char *argv[])
{
- uint64_t nextents, nchunks;
+ uint64_t nextents = 0, nchunks = 0;
int c, ret;
+ debug_init();
+
while ((c = getopt(argc, argv, "b:t:d:o:c:p:B:")) != -1) {
switch (c) {
case 'b':
ret = dedupe_check(argv[optind], &nextents, &nchunks);
- if (!bloom)
- iter_rb_tree(&nextents, &nchunks);
+ if (!ret) {
+ if (!bloom)
+ iter_rb_tree(&nextents, &nchunks);
- show_stat(nextents, nchunks);
+ show_stat(nextents, nchunks);
+ }
fio_mutex_remove(rb_lock);
- bloom_free(bloom);
+ if (bloom)
+ bloom_free(bloom);
scleanup();
return ret;
}