btrfs-progs: eliminate some unnecessary btrfs_lookup_extent_info() calls in walk_down...
authorWang Xiaoguang <wangxg.fnst@cn.fujitsu.com>
Tue, 16 Aug 2016 06:17:57 +0000 (14:17 +0800)
committerDavid Sterba <dsterba@suse.com>
Tue, 16 Aug 2016 14:02:03 +0000 (16:02 +0200)
commita13bfba3e21e0ce78965eb4725a4282c9cf9bb4a
treea0097f7f0b88bdd46ad44cc1c76dcef3d254a03c
parent9d2ea014f0cb5cd6fd3147f8779870fc63b39714
btrfs-progs: eliminate some unnecessary btrfs_lookup_extent_info() calls in walk_down_tree()

In walk_down_tree(), we may call btrfs_lookup_extent_info() for same tree
block many times, obviously unnecessary. Here we define a simple struct to
record whether we already have gotten tree block's refs:
        struct node_refs {
                u64 bytenr[BTRFS_MAX_LEVEL];
                u64 refs[BTRFS_MAX_LEVEL];
        };

I fill a disk partition with linux kernel source codes and use below
test script to have performance test.
#!/bin/bash

echo 3 > /proc/sys/vm/drop_caches
for ((i = 0; i < 20; i++)); do
time ./btrfsck  /dev/sdc5
done 2>&1 | grep real | awk -F "[ms]" '{run_time += $2} END{print run_time / 20}'

Before this patch, it averagely took 0.8447s for every btrfsck execution,
and with this patch, it averagely took 0.7807s.

Signed-off-by: Wang Xiaoguang <wangxg.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
cmds-check.c