Commit 59d35c51 authored by Filipe Manana's avatar Filipe Manana Committed by David Sterba

btrfs: release path earlier at can_nocow_extent()

At can_nocow_extent(), we are releasing the path only after checking if
the block group that has the target extent is read only, and after
checking if there's delalloc in the range in case our extent is a
preallocated extent. The read only extent check can be expensive if we
have a very large filesystem with many block groups, as well as the
check for delalloc in the inode's io_tree in case the io_tree is big
due to IO on other file ranges.

Our path is holding a read lock on a leaf and there's no need to keep
the lock while doing those two checks, so release the path before doing
them, immediately after the last use of the leaf.
Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent c1a548db
...@@ -7197,6 +7197,8 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len, ...@@ -7197,6 +7197,8 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
*ram_bytes = btrfs_file_extent_ram_bytes(leaf, fi); *ram_bytes = btrfs_file_extent_ram_bytes(leaf, fi);
} }
btrfs_release_path(path);
if (btrfs_extent_readonly(fs_info, disk_bytenr)) if (btrfs_extent_readonly(fs_info, disk_bytenr))
goto out; goto out;
...@@ -7214,8 +7216,6 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len, ...@@ -7214,8 +7216,6 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
} }
} }
btrfs_release_path(path);
/* /*
* look for other files referencing this extent, if we * look for other files referencing this extent, if we
* find any we must cow * find any we must cow
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment