]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/journal_reclaim.c
Update bcachefs sources to 841a95c29f4c bcachefs: fix userspace build errors
[bcachefs-tools-debian] / libbcachefs / journal_reclaim.c
index 658aaa2c3c6d753cc92f9a494466ddcef6181d31..60b9d357238754b5d1162570a593c26b690562f5 100644 (file)
@@ -3,6 +3,7 @@
 #include "bcachefs.h"
 #include "btree_key_cache.h"
 #include "btree_update.h"
+#include "btree_write_buffer.h"
 #include "buckets.h"
 #include "errcode.h"
 #include "error.h"
@@ -50,20 +51,23 @@ unsigned bch2_journal_dev_buckets_available(struct journal *j,
        return available;
 }
 
-static inline void journal_set_watermark(struct journal *j)
+void bch2_journal_set_watermark(struct journal *j)
 {
        struct bch_fs *c = container_of(j, struct bch_fs, journal);
        bool low_on_space = j->space[journal_space_clean].total * 4 <=
                j->space[journal_space_total].total;
        bool low_on_pin = fifo_free(&j->pin) < j->pin.size / 4;
-       unsigned watermark = low_on_space || low_on_pin
+       bool low_on_wb = bch2_btree_write_buffer_must_wait(c);
+       unsigned watermark = low_on_space || low_on_pin || low_on_wb
                ? BCH_WATERMARK_reclaim
                : BCH_WATERMARK_stripe;
 
        if (track_event_change(&c->times[BCH_TIME_blocked_journal_low_on_space],
                               &j->low_on_space_start, low_on_space) ||
            track_event_change(&c->times[BCH_TIME_blocked_journal_low_on_pin],
-                              &j->low_on_pin_start, low_on_pin))
+                              &j->low_on_pin_start, low_on_pin) ||
+           track_event_change(&c->times[BCH_TIME_blocked_write_buffer_full],
+                              &j->write_buffer_full_start, low_on_wb))
                trace_and_count(c, journal_full, c);
 
        swap(watermark, j->watermark);
@@ -230,7 +234,7 @@ void bch2_journal_space_available(struct journal *j)
        else
                clear_bit(JOURNAL_MAY_SKIP_FLUSH, &j->flags);
 
-       journal_set_watermark(j);
+       bch2_journal_set_watermark(j);
 out:
        j->cur_entry_sectors    = !ret ? j->space[journal_space_discarded].next_entry : 0;
        j->cur_entry_error      = ret;
@@ -303,6 +307,7 @@ void bch2_journal_reclaim_fast(struct journal *j)
         * all btree nodes got written out
         */
        while (!fifo_empty(&j->pin) &&
+              j->pin.front <= j->seq_ondisk &&
               !atomic_read(&fifo_peek_front(&j->pin).count)) {
                j->pin.front++;
                popped = true;
@@ -635,6 +640,7 @@ static u64 journal_seq_to_flush(struct journal *j)
 static int __bch2_journal_reclaim(struct journal *j, bool direct, bool kicked)
 {
        struct bch_fs *c = container_of(j, struct bch_fs, journal);
+       bool kthread = (current->flags & PF_KTHREAD) != 0;
        u64 seq_to_flush;
        size_t min_nr, min_key_cache, nr_flushed;
        unsigned flags;
@@ -650,7 +656,7 @@ static int __bch2_journal_reclaim(struct journal *j, bool direct, bool kicked)
        flags = memalloc_noreclaim_save();
 
        do {
-               if (kthread_should_stop())
+               if (kthread && kthread_should_stop())
                        break;
 
                if (bch2_journal_error(j)) {
@@ -816,6 +822,9 @@ static int journal_flush_done(struct journal *j, u64 seq_to_flush,
                               (1U << JOURNAL_PIN_btree), 0, 0, 0))
                *did_work = true;
 
+       if (seq_to_flush > journal_cur_seq(j))
+               bch2_journal_entry_close(j);
+
        spin_lock(&j->lock);
        /*
         * If journal replay hasn't completed, the unreplayed journal entries