Skip to content

Commit 2090303

Browse files
fdmananakdave
authored andcommitted
btrfs: avoid checking for RO block group twice during nocow writeback
During the nocow writeback path, we currently iterate the rbtree of block groups twice: once for checking if the target block group is RO with the call to btrfs_extent_readonly()), and once again for getting a nocow reference on the block group with a call to btrfs_inc_nocow_writers(). Since btrfs_inc_nocow_writers() already returns false when the target block group is RO, remove the call to btrfs_extent_readonly(). Not only we avoid searching the blocks group rbtree twice, it also helps reduce contention on the lock that protects it (specially since it is a spin lock and not a read-write lock). That may make a noticeable difference on very large filesystems, with thousands of allocated block groups. Reviewed-by: Anand Jain <anand.jain@oracle.com> Reviewed-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 3c17916 commit 2090303

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

fs/btrfs/inode.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,9 +1674,6 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode,
16741674
*/
16751675
btrfs_release_path(path);
16761676

1677-
/* If extent is RO, we must COW it */
1678-
if (btrfs_extent_readonly(fs_info, disk_bytenr))
1679-
goto out_check;
16801677
ret = btrfs_cross_ref_exist(root, ino,
16811678
found_key.offset -
16821679
extent_offset, disk_bytenr, false);
@@ -1723,6 +1720,7 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode,
17231720
WARN_ON_ONCE(freespace_inode);
17241721
goto out_check;
17251722
}
1723+
/* If the extent's block group is RO, we must COW */
17261724
if (!btrfs_inc_nocow_writers(fs_info, disk_bytenr))
17271725
goto out_check;
17281726
nocow = true;

0 commit comments

Comments
 (0)