Skip to content

Commit d4e839d

Browse files
committed
jbd2: add transaction to checkpoint list earlier
We don't otherwise need j_list_lock during the rest of commit phase #7, so add the transaction to the checkpoint list at the very end of commit phase #6. This allows us to drop j_list_lock earlier, which is a good thing since it is a super hot lock. Signed-off-by: "Theodore Ts'o" <[email protected]>
1 parent 42cf345 commit d4e839d

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

fs/jbd2/commit.c

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,25 @@ void jbd2_journal_commit_transaction(journal_t *journal)
10651065
goto restart_loop;
10661066
}
10671067

1068+
/* Add the transaction to the checkpoint list
1069+
* __journal_remove_checkpoint() can not destroy transaction
1070+
* under us because it is not marked as T_FINISHED yet */
1071+
if (journal->j_checkpoint_transactions == NULL) {
1072+
journal->j_checkpoint_transactions = commit_transaction;
1073+
commit_transaction->t_cpnext = commit_transaction;
1074+
commit_transaction->t_cpprev = commit_transaction;
1075+
} else {
1076+
commit_transaction->t_cpnext =
1077+
journal->j_checkpoint_transactions;
1078+
commit_transaction->t_cpprev =
1079+
commit_transaction->t_cpnext->t_cpprev;
1080+
commit_transaction->t_cpnext->t_cpprev =
1081+
commit_transaction;
1082+
commit_transaction->t_cpprev->t_cpnext =
1083+
commit_transaction;
1084+
}
1085+
spin_unlock(&journal->j_list_lock);
1086+
10681087
/* Done with this transaction! */
10691088

10701089
jbd_debug(3, "JBD2: commit phase 7\n");
@@ -1103,24 +1122,6 @@ void jbd2_journal_commit_transaction(journal_t *journal)
11031122

11041123
write_unlock(&journal->j_state_lock);
11051124

1106-
if (journal->j_checkpoint_transactions == NULL) {
1107-
journal->j_checkpoint_transactions = commit_transaction;
1108-
commit_transaction->t_cpnext = commit_transaction;
1109-
commit_transaction->t_cpprev = commit_transaction;
1110-
} else {
1111-
commit_transaction->t_cpnext =
1112-
journal->j_checkpoint_transactions;
1113-
commit_transaction->t_cpprev =
1114-
commit_transaction->t_cpnext->t_cpprev;
1115-
commit_transaction->t_cpnext->t_cpprev =
1116-
commit_transaction;
1117-
commit_transaction->t_cpprev->t_cpnext =
1118-
commit_transaction;
1119-
}
1120-
spin_unlock(&journal->j_list_lock);
1121-
/* Drop all spin_locks because commit_callback may be block.
1122-
* __journal_remove_checkpoint() can not destroy transaction
1123-
* under us because it is not marked as T_FINISHED yet */
11241125
if (journal->j_commit_callback)
11251126
journal->j_commit_callback(journal, commit_transaction);
11261127

@@ -1131,7 +1132,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)
11311132
write_lock(&journal->j_state_lock);
11321133
spin_lock(&journal->j_list_lock);
11331134
commit_transaction->t_state = T_FINISHED;
1134-
/* Recheck checkpoint lists after j_list_lock was dropped */
1135+
/* Check if the transaction can be dropped now that we are finished */
11351136
if (commit_transaction->t_checkpoint_list == NULL &&
11361137
commit_transaction->t_checkpoint_io_list == NULL) {
11371138
__jbd2_journal_drop_transaction(journal, commit_transaction);

0 commit comments

Comments
 (0)