Linux Btrfs filesystem development
 help / color / mirror / Atom feed
* [PATCH] btrfs: reduce ordered_extent_lock section at btrfs_split_ordered_extent()
@ 2024-05-14 14:28 fdmanana
  2024-05-14 17:54 ` [PATCH v2] " fdmanana
  0 siblings, 1 reply; 5+ messages in thread
From: fdmanana @ 2024-05-14 14:28 UTC (permalink / raw)
  To: linux-btrfs

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>
---
 fs/btrfs/ordered-data.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
index c5bdd674f55c..a6c2b4e5edf1 100644
--- a/fs/btrfs/ordered-data.c
+++ b/fs/btrfs/ordered-data.c
@@ -1181,7 +1181,6 @@ 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);
 	/* Remove from tree once */
 	node = &ordered->rb_node;
@@ -1234,6 +1233,7 @@ struct btrfs_ordered_extent *btrfs_split_ordered_extent(
 			new->file_offset);
 	spin_unlock(&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);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-05-29 15:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-14 14:28 [PATCH] btrfs: reduce ordered_extent_lock section at btrfs_split_ordered_extent() fdmanana
2024-05-14 17:54 ` [PATCH v2] " fdmanana
2024-05-28 22:22   ` David Sterba
2024-05-29 11:51     ` Filipe Manana
2024-05-29 15:16       ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox