Skip to content

Commit 7c73ddb

Browse files
zhangyi089tytso
authored andcommitted
jbd2: speed up jbd2_transaction_committed()
jbd2_transaction_committed() is used to check whether a transaction with the given tid has already committed, it holds j_state_lock in read mode and check the tid of current running transaction and committing transaction, but holding the j_state_lock is expensive. We have already stored the sequence number of the most recently committed transaction in journal t->j_commit_sequence, we could do this check by comparing it with the given tid instead. If the given tid isn't smaller than j_commit_sequence, we can ensure that the given transaction has been committed. That way we could drop the expensive lock and achieve about 10% ~ 20% performance gains in concurrent DIOs on may virtual machine with 100G ramdisk. fio -filename=/mnt/foo -direct=1 -iodepth=10 -rw=$rw -ioengine=libaio \ -bs=4k -size=10G -numjobs=10 -runtime=60 -overwrite=1 -name=test \ -group_reporting Before: overwrite IOPS=88.2k, BW=344MiB/s read IOPS=95.7k, BW=374MiB/s rand overwrite IOPS=98.7k, BW=386MiB/s randread IOPS=102k, BW=397MiB/s After: overwrite IOPS=105k, BW=410MiB/s read IOPS=112k, BW=436MiB/s rand overwrite IOPS=104k, BW=404MiB/s randread IOPS=111k, BW=432MiB/s CC: Dave Chinner <[email protected]> Suggested-by: Dave Chinner <[email protected]> Link: https://lore.kernel.org/linux-ext4/[email protected]/ Signed-off-by: Zhang Yi <[email protected]> Reviewed-by: Jan Kara <[email protected]> Reviewed-by: Ritesh Harjani (IBM) <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 8262fe9 commit 7c73ddb

File tree

2 files changed

+2
-12
lines changed

2 files changed

+2
-12
lines changed

fs/jbd2/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)
11071107

11081108
commit_transaction->t_state = T_COMMIT_CALLBACK;
11091109
J_ASSERT(commit_transaction == journal->j_committing_transaction);
1110-
journal->j_commit_sequence = commit_transaction->t_tid;
1110+
WRITE_ONCE(journal->j_commit_sequence, commit_transaction->t_tid);
11111111
journal->j_committing_transaction = NULL;
11121112
commit_time = ktime_to_ns(ktime_sub(ktime_get(), start_time));
11131113

fs/jbd2/journal.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -775,17 +775,7 @@ EXPORT_SYMBOL(jbd2_fc_end_commit_fallback);
775775
/* Return 1 when transaction with given tid has already committed. */
776776
int jbd2_transaction_committed(journal_t *journal, tid_t tid)
777777
{
778-
int ret = 1;
779-
780-
read_lock(&journal->j_state_lock);
781-
if (journal->j_running_transaction &&
782-
journal->j_running_transaction->t_tid == tid)
783-
ret = 0;
784-
if (journal->j_committing_transaction &&
785-
journal->j_committing_transaction->t_tid == tid)
786-
ret = 0;
787-
read_unlock(&journal->j_state_lock);
788-
return ret;
778+
return tid_geq(READ_ONCE(journal->j_commit_sequence), tid);
789779
}
790780
EXPORT_SYMBOL(jbd2_transaction_committed);
791781

0 commit comments

Comments
 (0)