Skip to content

Commit 89573b9

Browse files
committed
Btrfs: Only let very young transactions grow during commit
Commits are fairly expensive, and so btrfs has code to sit around for a while during the commit and let new writers come in. But, while we're sitting there, new delayed refs might be added, and those can be expensive to process as well. Unless the transaction is very very young, it makes sense to go ahead and let the commit finish without hanging around. The commit grow loop isn't as important as it used to be, the fsync logging code handles most performance critical syncs now. Signed-off-by: Chris Mason <chris.mason@oracle.com>
1 parent 66d7e85 commit 89573b9

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

fs/btrfs/transaction.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,8 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
972972
struct extent_io_tree *pinned_copy;
973973
DEFINE_WAIT(wait);
974974
int ret;
975+
int should_grow = 0;
976+
unsigned long now = get_seconds();
975977

976978
/* make a pass through all the delayed refs we have so far
977979
* any runnings procs may add more while we are here
@@ -1029,6 +1031,9 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
10291031
}
10301032
}
10311033

1034+
if (now < cur_trans->start_time || now - cur_trans->start_time < 1)
1035+
should_grow = 1;
1036+
10321037
do {
10331038
int snap_pending = 0;
10341039
joined = cur_trans->num_joined;
@@ -1041,7 +1046,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
10411046

10421047
if (cur_trans->num_writers > 1)
10431048
timeout = MAX_SCHEDULE_TIMEOUT;
1044-
else
1049+
else if (should_grow)
10451050
timeout = 1;
10461051

10471052
mutex_unlock(&root->fs_info->trans_mutex);
@@ -1051,12 +1056,14 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans,
10511056
BUG_ON(ret);
10521057
}
10531058

1054-
schedule_timeout(timeout);
1059+
smp_mb();
1060+
if (cur_trans->num_writers > 1 || should_grow)
1061+
schedule_timeout(timeout);
10551062

10561063
mutex_lock(&root->fs_info->trans_mutex);
10571064
finish_wait(&cur_trans->writer_wait, &wait);
10581065
} while (cur_trans->num_writers > 1 ||
1059-
(cur_trans->num_joined != joined));
1066+
(should_grow && cur_trans->num_joined != joined));
10601067

10611068
ret = create_pending_snapshots(trans, root->fs_info);
10621069
BUG_ON(ret);

0 commit comments

Comments
 (0)