bcachefs: bch2_journal_noflush_seq()
authorKent Overstreet <kent.overstreet@gmail.com>
Tue, 28 Dec 2021 04:51:48 +0000 (23:51 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:20 +0000 (17:09 -0400)
Add bch2_journal_noflush_seq(), for telling the journal that entries
before a given sequence number should not be flushes - to be used by an
upcoming allocator optimization.

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

index 4fadb41c4c1efc6fc8064e4ae3179a1d01c4cd57..3c7dce3b31c1b21e052a1d16ee9ea78e8d286adb 100644 (file)
@@ -704,6 +704,44 @@ int bch2_journal_flush(struct journal *j)
        return bch2_journal_flush_seq(j, seq);
 }
 
+/*
+ * bch2_journal_noflush_seq - tell the journal not to issue any flushes before
+ * @seq
+ */
+bool bch2_journal_noflush_seq(struct journal *j, u64 seq)
+{
+       struct bch_fs *c = container_of(j, struct bch_fs, journal);
+       u64 unwritten_seq;
+       bool ret = false;
+
+       if (!(c->sb.features & (1ULL << BCH_FEATURE_journal_no_flush)))
+               return false;
+
+       if (seq <= c->journal.flushed_seq_ondisk)
+               return false;
+
+       spin_lock(&j->lock);
+       if (seq <= c->journal.flushed_seq_ondisk)
+               goto out;
+
+       for (unwritten_seq = last_unwritten_seq(j);
+            unwritten_seq < seq;
+            unwritten_seq++) {
+               struct journal_buf *buf = journal_seq_to_buf(j, unwritten_seq);
+
+               /* journal write is already in flight, and was a flush write: */
+               if (unwritten_seq == last_unwritten_seq(j) && !buf->noflush)
+                       goto out;
+
+               buf->noflush = true;
+       }
+
+       ret = true;
+out:
+       spin_unlock(&j->lock);
+       return ret;
+}
+
 /* block/unlock the journal: */
 
 void bch2_journal_unblock(struct journal *j)
index 2cfb6c7f0d148100ca41c013f4786c391f6c4f10..17f9037b404ac9507dcf78890511558a90ef0fe5 100644 (file)
@@ -475,6 +475,7 @@ void bch2_journal_flush_async(struct journal *, struct closure *);
 
 int bch2_journal_flush_seq(struct journal *, u64);
 int bch2_journal_flush(struct journal *);
+bool bch2_journal_noflush_seq(struct journal *, u64);
 int bch2_journal_meta(struct journal *);
 
 void bch2_journal_halt(struct journal *);
index bda60509582504a4c9e2e926e3f366f06fcfccaa..4f8dd0130b37b37d4eb90545719566919f23ddf0 100644 (file)
@@ -1396,9 +1396,10 @@ void bch2_journal_write(struct closure *cl)
 
        spin_lock(&j->lock);
        if (c->sb.features & (1ULL << BCH_FEATURE_journal_no_flush) &&
-           !w->must_flush &&
-           (jiffies - j->last_flush_write) < msecs_to_jiffies(c->opts.journal_flush_delay) &&
-           test_bit(JOURNAL_MAY_SKIP_FLUSH, &j->flags)) {
+           (w->noflush ||
+            (!w->must_flush &&
+             (jiffies - j->last_flush_write) < msecs_to_jiffies(c->opts.journal_flush_delay) &&
+             test_bit(JOURNAL_MAY_SKIP_FLUSH, &j->flags)))) {
                w->noflush = true;
                SET_JSET_NO_FLUSH(jset, true);
                jset->last_seq  = 0;