Message ID | 6bd1663678f119791c1e2b6071f4973f35dcf049.1715708811.git.fdmanana@suse.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | [v2] btrfs: reduce ordered_extent_lock section at btrfs_split_ordered_extent() | expand |
On Tue, May 14, 2024 at 06:54:18PM +0100, fdmanana@kernel.org wrote: > From: Filipe Manana <fdmanana@suse.com> > > There's no need to hold the root's ordered_extent_lock for so long at > btrfs_split_ordered_extent(). We don't need to hold it in order to modify > the inode's rb tree of ordered extents, to modify the trimmed ordered > extent and move checksums between the trimmed and the new ordered extent. > That's only increasing contention of the root's ordered_extent_lock for > other writes that are starting or completing. > > So lock the root's ordered_extent_lock only before we add the new ordered > extent to the root's ordered list and increment the root's counter for the > number of ordered extents. > > Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com>
diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c index c5bdd674f55c..e6025d9645f5 100644 --- a/fs/btrfs/ordered-data.c +++ b/fs/btrfs/ordered-data.c @@ -1181,8 +1181,7 @@ struct btrfs_ordered_extent *btrfs_split_ordered_extent( /* One ref for the tree. */ refcount_inc(&new->refs); - spin_lock_irq(&root->ordered_extent_lock); - spin_lock(&inode->ordered_tree_lock); + spin_lock_irq(&inode->ordered_tree_lock); /* Remove from tree once */ node = &ordered->rb_node; rb_erase(node, &inode->ordered_tree); @@ -1232,8 +1231,9 @@ struct btrfs_ordered_extent *btrfs_split_ordered_extent( btrfs_panic(fs_info, -EEXIST, "zoned: inconsistency in ordered tree at offset %llu", new->file_offset); - spin_unlock(&inode->ordered_tree_lock); + spin_unlock_irq(&inode->ordered_tree_lock); + spin_lock_irq(&root->ordered_extent_lock); list_add_tail(&new->root_extent_list, &root->ordered_extents); root->nr_ordered_extents++; spin_unlock_irq(&root->ordered_extent_lock);