Skip to content

Commit 78d4295

Browse files
Ethan Lienkdave
authored andcommitted
btrfs: lift some btrfs_cross_ref_exist checks in nocow path
In nocow path, we check if the extent is snapshotted in btrfs_cross_ref_exist(). We can do the similar check earlier and avoid unnecessary search into extent tree. A fio test on a Intel D-1531, 16GB RAM, SSD RAID-5 machine as follows: [global] group_reporting time_based thread=1 ioengine=libaio bs=4k iodepth=32 size=64G runtime=180 numjobs=8 rw=randwrite [file1] filename=/mnt/nocow/testfile IOPS result: unpatched patched 1 fio round: 46670 46958 snapshot 2 fio round: 51826 54498 3 fio round: 59767 61289 After snapshot, the first fio get about 5% performance gain. As we continually write to the same file, all writes will resume to nocow mode and eventually we have no performance gain. Signed-off-by: Ethan Lien <ethanlien@synology.com> Reviewed-by: David Sterba <dsterba@suse.com> [ update comments ] Signed-off-by: David Sterba <dsterba@suse.com>
1 parent d195779 commit 78d4295

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

fs/btrfs/inode.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,13 @@ static noinline int run_delalloc_nocow(struct inode *inode,
13701370
btrfs_file_extent_encryption(leaf, fi) ||
13711371
btrfs_file_extent_other_encoding(leaf, fi))
13721372
goto out_check;
1373+
/*
1374+
* Do the same check as in btrfs_cross_ref_exist but
1375+
* without the unnecessary search.
1376+
*/
1377+
if (btrfs_file_extent_generation(leaf, fi) <=
1378+
btrfs_root_last_snapshot(&root->root_item))
1379+
goto out_check;
13731380
if (extent_type == BTRFS_FILE_EXTENT_REG && !force)
13741381
goto out_check;
13751382
if (btrfs_extent_readonly(fs_info, disk_bytenr))
@@ -7322,6 +7329,14 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
73227329
btrfs_file_extent_other_encoding(leaf, fi))
73237330
goto out;
73247331

7332+
/*
7333+
* Do the same check as in btrfs_cross_ref_exist but without the
7334+
* unnecessary search.
7335+
*/
7336+
if (btrfs_file_extent_generation(leaf, fi) <=
7337+
btrfs_root_last_snapshot(&root->root_item))
7338+
goto out;
7339+
73257340
backref_offset = btrfs_file_extent_offset(leaf, fi);
73267341

73277342
if (orig_start) {

0 commit comments

Comments
 (0)