Skip to content

Commit d52c1bc

Browse files
Liu BoChris Mason
Liu Bo
authored and
Chris Mason
committed
Btrfs: avoid heavy operations in btrfs_commit_super
The 'git blame' history shows that, the old transaction commit code has to do twice to ensure roots are updated and we have to flush metadata and super block manually, however, right now all of these can be handled well inside the transaction commit code without extra efforts. And the error handling part remains same with the current code, -- 'return to caller once we get error'. This saves us a transaction commit and a flush of super block, which are both heavy operations according to ftrace output analysis. Signed-off-by: Liu Bo <[email protected]> Signed-off-by: Josef Bacik <[email protected]> Signed-off-by: Chris Mason <[email protected]>
1 parent ba69994 commit d52c1bc

File tree

1 file changed

+1
-20
lines changed

1 file changed

+1
-20
lines changed

fs/btrfs/disk-io.c

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3517,7 +3517,6 @@ int btrfs_cleanup_fs_roots(struct btrfs_fs_info *fs_info)
35173517
int btrfs_commit_super(struct btrfs_root *root)
35183518
{
35193519
struct btrfs_trans_handle *trans;
3520-
int ret;
35213520

35223521
mutex_lock(&root->fs_info->cleaner_mutex);
35233522
btrfs_run_delayed_iputs(root);
@@ -3531,25 +3530,7 @@ int btrfs_commit_super(struct btrfs_root *root)
35313530
trans = btrfs_join_transaction(root);
35323531
if (IS_ERR(trans))
35333532
return PTR_ERR(trans);
3534-
ret = btrfs_commit_transaction(trans, root);
3535-
if (ret)
3536-
return ret;
3537-
/* run commit again to drop the original snapshot */
3538-
trans = btrfs_join_transaction(root);
3539-
if (IS_ERR(trans))
3540-
return PTR_ERR(trans);
3541-
ret = btrfs_commit_transaction(trans, root);
3542-
if (ret)
3543-
return ret;
3544-
ret = btrfs_write_and_wait_transaction(NULL, root);
3545-
if (ret) {
3546-
btrfs_error(root->fs_info, ret,
3547-
"Failed to sync btree inode to disk.");
3548-
return ret;
3549-
}
3550-
3551-
ret = write_ctree_super(NULL, root, 0);
3552-
return ret;
3533+
return btrfs_commit_transaction(trans, root);
35533534
}
35543535

35553536
int close_ctree(struct btrfs_root *root)

0 commit comments

Comments
 (0)