Skip to content

Commit 6c8e66e

Browse files
fdmananakdave
authored andcommitted
btrfs: avoid removal and re-insertion of split ordered extent
At btrfs_split_ordered_extent(), we are removing and re-inserting the ordered extent that we are trimming, but we don't need to since the trimming doesn't change its position in the red black tree because we don't have overlapping ordered extents (that would imply double allocation of extents) and we know the split length is smaller than the ordered extent's num_bytes field (we checked that early in the function). So drop the remove and re-insert code for the slit ordered extent. Reviewed-by: Josef Bacik <[email protected]> Reviewed-by: Qu Wenruo <[email protected]> Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: Filipe Manana <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 58b8247 commit 6c8e66e

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

fs/btrfs/ordered-data.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,13 +1266,13 @@ struct btrfs_ordered_extent *btrfs_split_ordered_extent(
12661266
*/
12671267
spin_lock_irq(&root->ordered_extent_lock);
12681268
spin_lock(&inode->ordered_tree_lock);
1269-
/* Remove from tree once */
1270-
node = &ordered->rb_node;
1271-
rb_erase(node, &inode->ordered_tree);
1272-
RB_CLEAR_NODE(node);
1273-
if (inode->ordered_tree_last == node)
1274-
inode->ordered_tree_last = NULL;
12751269

1270+
/*
1271+
* We don't have overlapping ordered extents (that would imply double
1272+
* allocation of extents) and we checked above that the split length
1273+
* does not cross the ordered extent's num_bytes field, so there's
1274+
* no need to remove it and re-insert it in the tree.
1275+
*/
12761276
ordered->file_offset += len;
12771277
ordered->disk_bytenr += len;
12781278
ordered->num_bytes -= len;
@@ -1302,14 +1302,6 @@ struct btrfs_ordered_extent *btrfs_split_ordered_extent(
13021302
offset += sum->len;
13031303
}
13041304

1305-
/* Re-insert the node */
1306-
node = tree_insert(&inode->ordered_tree, ordered->file_offset,
1307-
&ordered->rb_node);
1308-
if (node)
1309-
btrfs_panic(fs_info, -EEXIST,
1310-
"zoned: inconsistency in ordered tree at offset %llu",
1311-
ordered->file_offset);
1312-
13131305
node = tree_insert(&inode->ordered_tree, new->file_offset, &new->rb_node);
13141306
if (node)
13151307
btrfs_panic(fs_info, -EEXIST,

0 commit comments

Comments
 (0)