]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
jbd2: speed up jbd2_transaction_committed()
authorZhang Yi <yi.zhang@huawei.com>
Mon, 20 May 2024 13:18:31 +0000 (21:18 +0800)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 5 Jul 2024 16:45:36 +0000 (12:45 -0400)
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 <david@fromorbit.com>
Suggested-by: Dave Chinner <david@fromorbit.com>
Link: https://lore.kernel.org/linux-ext4/ZjILCPNZRHeazSqV@dread.disaster.area/
Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Link: https://patch.msgid.link/20240520131831.2910790-1-yi.zhang@huaweicloud.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/jbd2/commit.c
fs/jbd2/journal.c

index 6d3fc992287d8ebab0e3f6e93a96eaf5a88a576e..ec5ed7eb193870885b9e318549594dfd5a1cfa16 100644 (file)
@@ -1107,7 +1107,7 @@ restart_loop:
 
        commit_transaction->t_state = T_COMMIT_CALLBACK;
        J_ASSERT(commit_transaction == journal->j_committing_transaction);
-       journal->j_commit_sequence = commit_transaction->t_tid;
+       WRITE_ONCE(journal->j_commit_sequence, commit_transaction->t_tid);
        journal->j_committing_transaction = NULL;
        commit_time = ktime_to_ns(ktime_sub(ktime_get(), start_time));
 
index 8d782a88aee1079bbd2ff5a90eceb67be0722860..25ef4fc8066787afe20c03db93a8358df2174122 100644 (file)
@@ -775,17 +775,7 @@ EXPORT_SYMBOL(jbd2_fc_end_commit_fallback);
 /* Return 1 when transaction with given tid has already committed. */
 int jbd2_transaction_committed(journal_t *journal, tid_t tid)
 {
-       int ret = 1;
-
-       read_lock(&journal->j_state_lock);
-       if (journal->j_running_transaction &&
-           journal->j_running_transaction->t_tid == tid)
-               ret = 0;
-       if (journal->j_committing_transaction &&
-           journal->j_committing_transaction->t_tid == tid)
-               ret = 0;
-       read_unlock(&journal->j_state_lock);
-       return ret;
+       return tid_geq(READ_ONCE(journal->j_commit_sequence), tid);
 }
 EXPORT_SYMBOL(jbd2_transaction_committed);