Skip to content

Commit 74cd8ca

Browse files
fdmananakdave
authored andcommitted
btrfs: avoid unnecessary ref initialization when freeing log tree block
At btrfs_free_tree_block(), we are always initializing a delayed reference to drop the given extent buffer but we only use if it does not belong to a log root tree. So we are doing unnecessary work here and increasing the duration of a critical section as this is normally called while holding a lock on the parent tree block (if any) and while holding a log transaction open. So initialize the delayed reference only if the extent buffer is not from a log tree, avoiding unnecessary work and making the code also a bit easier to follow. Reviewed-by: Naohiro Aota <naohiro.aota@wdc.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 0e9e135 commit 74cd8ca

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

fs/btrfs/extent-tree.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3458,16 +3458,17 @@ void btrfs_free_tree_block(struct btrfs_trans_handle *trans,
34583458
u64 parent, int last_ref)
34593459
{
34603460
struct btrfs_fs_info *fs_info = trans->fs_info;
3461-
struct btrfs_ref generic_ref = { 0 };
34623461
struct btrfs_block_group *bg;
34633462
int ret;
34643463

3465-
btrfs_init_generic_ref(&generic_ref, BTRFS_DROP_DELAYED_REF,
3466-
buf->start, buf->len, parent, btrfs_header_owner(buf));
3467-
btrfs_init_tree_ref(&generic_ref, btrfs_header_level(buf),
3468-
root_id, 0, false);
3469-
34703464
if (root_id != BTRFS_TREE_LOG_OBJECTID) {
3465+
struct btrfs_ref generic_ref = { 0 };
3466+
3467+
btrfs_init_generic_ref(&generic_ref, BTRFS_DROP_DELAYED_REF,
3468+
buf->start, buf->len, parent,
3469+
btrfs_header_owner(buf));
3470+
btrfs_init_tree_ref(&generic_ref, btrfs_header_level(buf),
3471+
root_id, 0, false);
34713472
btrfs_ref_tree_mod(fs_info, &generic_ref);
34723473
ret = btrfs_add_delayed_tree_ref(trans, &generic_ref, NULL);
34733474
BUG_ON(ret); /* -ENOMEM */

0 commit comments

Comments
 (0)