Btrfs-progs: fsck: reduce memory usage for extents check

Steps to reproduce:

 # mkfs.btrfs -f /dev/sda9 -b 2g
 # mount /dev/sda9 /mnt
 # dd if=/dev/zero of=/mnt/data bs=4k oflag=direct
 # btrfs file df /mnt

    Data, single: total=1.66GiB, used=1.66GiB
    System, single: total=4.00MiB, used=16.00KiB
    Metadata, single: total=200.00MiB, used=67.88MiB

For a filesystem without snapshots, 70M metadata, extent
checking eats max memory about 110M, this is a nightmare
for some system with low memory.

It is very likely that extent record can be freed quickly
for a filesystem without snapshots, improve this by trying
if it can free memory after adding data/tree backrefs.

This patch reduces max memory cost from 110M to 40M for
extents checking for the above case.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
This commit is contained in:
Wang Shilong 2014-06-20 19:09:07 +08:00 committed by David Sterba
parent 72ced9950a
commit 5e94319406

View File

@ -2829,6 +2829,7 @@ static int add_tree_backref(struct cache_tree *extent_cache, u64 bytenr,
}
back->node.found_extent_tree = 1;
}
maybe_free_extent_rec(extent_cache, rec);
return 0;
}
@ -2895,6 +2896,7 @@ static int add_data_backref(struct cache_tree *extent_cache, u64 bytenr,
back->num_refs = num_refs;
back->node.found_extent_tree = 1;
}
maybe_free_extent_rec(extent_cache, rec);
return 0;
}