btrfs-progs: check: supplement extent backref list with rbtree
authorJeff Mahoney <jeffm@suse.com>
Tue, 25 Jul 2017 20:51:32 +0000 (16:51 -0400)
committerDavid Sterba <dsterba@suse.com>
Fri, 6 Oct 2017 11:41:01 +0000 (13:41 +0200)
commit756105181e57074ce9d232e397abc0121cbb6bf6
tree8f7fbb106fd5e2d4210a450a53387c63a3eb2f6c
parent530ca513078d2e8682647da707681a024fa3120b
btrfs-progs: check: supplement extent backref list with rbtree

For the pathlogical case, like xfstests generic/297 that creates a
large file consisting of one, repeating reflinked extent, fsck can
take hours.  The root cause is that calling find_data_backref while
iterating the extent records is an O(n^2) algorithm.  For my
example test run, n was 2*2^20 and fsck was at 8 hours and counting.

This patch supplements the list with an rbtree and drops the runtime
of that testcase to about 20 seconds.

A previous version of this patch introduced a regression that would
have corrupted file systems during repair.  It was traced to the
compare algorithm honoring ->bytes regardless of whether the
reference had been found and a failure to reinsert nodes after
the target reference was found.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
cmds-check.c