bcachefs: Optimize bch2_journal_flush_seq_async()
authorKent Overstreet <kent.overstreet@gmail.com>
Sat, 21 Nov 2020 00:27:57 +0000 (19:27 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:48 +0000 (17:08 -0400)
Avoid taking the journal lock if we don't have to.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/journal.c

index 27fcb378790b37d4f113c62f8c99a44555084354..759a04346cdec52320f8a2032eb2461f61e7527a 100644 (file)
@@ -547,12 +547,20 @@ out:
  * necessary
  */
 int bch2_journal_flush_seq_async(struct journal *j, u64 seq,
-                                 struct closure *parent)
+                                struct closure *parent)
 {
        struct journal_buf *buf;
        int ret = 0;
 
+       if (seq <= j->err_seq)
+               return -EIO;
+
+       if (seq <= j->seq_ondisk)
+               return 1;
+
        spin_lock(&j->lock);
+
+       /* Recheck under lock: */
        if (seq <= j->err_seq) {
                ret = -EIO;
                goto out;