Skip to content

Commit

Permalink
Merge branch 'memfree' of git://github.com/clobrother/duperemove
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Fasheh committed Apr 3, 2015
2 parents 210074b + 55be0db commit 70ad980
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions d_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ struct d_tree *digest_find(struct rb_root *root,
unsigned char *digest);

uint64_t digest_count(struct rb_root *root);
void digest_free(struct rb_root *root);

#endif /* __DTREE__ */
2 changes: 1 addition & 1 deletion duperemove.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
#include "btrfs-util.h"
#include "memstats.h"
#include "debug.h"
#include "d_tree.h"

#include "file_scan.h"
#include "find_dupes.h"
Expand Down Expand Up @@ -392,6 +391,7 @@ int main(int argc, char **argv)
goto out;
}

digest_free(&digest_tree);
if (debug) {
print_dupes_table(&res);
printf("\n\nRemoving overlapping extents\n\n");
Expand Down
1 change: 0 additions & 1 deletion file_scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,6 @@ static void csum_whole_file_swap(struct filerec *file,
int nb_hash = 0;
int matched = 0;

struct d_tree *d_tree;
GMutex *mutex;

csum_whole_file_init(&mutex, params, file, &fc);
Expand Down
22 changes: 21 additions & 1 deletion results-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,16 @@ static uint64_t extent_len(struct extent *extent)
return extent->e_parent->de_len;
}

static void remove_extent(struct results_tree *res, struct extent *extent)
static unsigned int remove_extent(struct results_tree *res, struct extent *extent)
{
struct dupe_extents *p = extent->e_parent;
struct rb_node *n;
unsigned int result;

again:
p->de_score -= p->de_len;
p->de_num_dupes--;
result = p->de_num_dupes;

list_del_init(&extent->e_list);
list_del_init(&extent->e_file_extents);
Expand All @@ -271,6 +273,7 @@ static void remove_extent(struct results_tree *res, struct extent *extent)
free_dupe_extents(p);
res->num_dupes--;
}
return result;
}

static int compare_extent(struct results_tree *res,
Expand Down Expand Up @@ -343,3 +346,20 @@ void init_results_tree(struct results_tree *res)
res->root = RB_ROOT;
res->num_dupes = 0;
}

void dupe_extents_free(struct dupe_extents *dext, struct results_tree *res)
{
struct extent *extent;
struct rb_node *n;
int count;

/*
* remove_extent will remove all stuff if there is less
* than one extent remaining
*/
do {
n = rb_first(&dext->de_extents_root);
extent = rb_entry(n, struct extent, e_node);
count = remove_extent(res, extent);
} while (count > 1);
}
1 change: 1 addition & 0 deletions results-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ int insert_result(struct results_tree *res, unsigned char *digest,
void remove_overlapping_extents(struct results_tree *res, struct filerec *file);

void init_results_tree(struct results_tree *res);
void dupe_extents_free(struct dupe_extents *dext, struct results_tree *res);

#endif /* __RESULTS_TREE__ */
9 changes: 9 additions & 0 deletions run_dedupe.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ struct dedupe_counts {
uint64_t fiemap_bytes;
};

static GMutex mutex;
static struct results_tree *results_tree;

static int dedupe_worker(struct dupe_extents *dext,
struct dedupe_counts *counts)
{
Expand All @@ -318,6 +321,10 @@ static int dedupe_worker(struct dupe_extents *dext,
return ret;
}

g_mutex_lock(&mutex);
dupe_extents_free(dext, results_tree);
g_mutex_unlock(&mutex);

g_mutex_lock(&dedupe_counts_mutex);
counts->fiemap_bytes += fiemap_bytes;
counts->kern_bytes += kern_bytes;
Expand All @@ -336,6 +343,8 @@ void dedupe_results(struct results_tree *res)
struct dedupe_counts counts = { 0ULL, };
GError *err = NULL;

results_tree = res;

print_dupes_table(res);

if (RB_EMPTY_ROOT(root)) {
Expand Down

0 comments on commit 70ad980

Please sign in to comment.