]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/journal_reclaim.c
Update bcachefs sources to f70a3402188e bcachefs: Fix ca->oldest_gen allocation
[bcachefs-tools-debian] / libbcachefs / journal_reclaim.c
index 8de83e10375187803730214e3bee4c3cd425256c..9a584aaaa2eba9abadc7f2016a20c70834e0610c 100644 (file)
@@ -3,13 +3,14 @@
 #include "bcachefs.h"
 #include "btree_key_cache.h"
 #include "btree_update.h"
+#include "buckets.h"
 #include "errcode.h"
 #include "error.h"
 #include "journal.h"
 #include "journal_io.h"
 #include "journal_reclaim.h"
 #include "replicas.h"
-#include "super.h"
+#include "sb-members.h"
 #include "trace.h"
 
 #include <linux/kthread.h>
@@ -289,9 +290,8 @@ void bch2_journal_do_discards(struct journal *j)
  * entry, holding it open to ensure it gets replayed during recovery:
  */
 
-static void bch2_journal_reclaim_fast(struct journal *j)
+void bch2_journal_reclaim_fast(struct journal *j)
 {
-       struct journal_entry_pin_list temp;
        bool popped = false;
 
        lockdep_assert_held(&j->lock);
@@ -302,7 +302,7 @@ static void bch2_journal_reclaim_fast(struct journal *j)
         */
        while (!fifo_empty(&j->pin) &&
               !atomic_read(&fifo_peek_front(&j->pin).count)) {
-               fifo_pop(&j->pin, temp);
+               j->pin.front++;
                popped = true;
        }
 
@@ -310,19 +310,16 @@ static void bch2_journal_reclaim_fast(struct journal *j)
                bch2_journal_space_available(j);
 }
 
-void __bch2_journal_pin_put(struct journal *j, u64 seq)
+bool __bch2_journal_pin_put(struct journal *j, u64 seq)
 {
        struct journal_entry_pin_list *pin_list = journal_seq_pin(j, seq);
 
-       if (atomic_dec_and_test(&pin_list->count))
-               bch2_journal_reclaim_fast(j);
+       return atomic_dec_and_test(&pin_list->count);
 }
 
 void bch2_journal_pin_put(struct journal *j, u64 seq)
 {
-       struct journal_entry_pin_list *pin_list = journal_seq_pin(j, seq);
-
-       if (atomic_dec_and_test(&pin_list->count)) {
+       if (__bch2_journal_pin_put(j, seq)) {
                spin_lock(&j->lock);
                bch2_journal_reclaim_fast(j);
                spin_unlock(&j->lock);
@@ -345,7 +342,7 @@ static inline bool __journal_pin_drop(struct journal *j,
        list_del_init(&pin->list);
 
        /*
-        * Unpinning a journal entry make make journal_next_bucket() succeed, if
+        * Unpinning a journal entry may make journal_next_bucket() succeed, if
         * writing a new last_seq will now make another bucket available:
         */
        return atomic_dec_and_test(&pin_list->count) &&
@@ -418,6 +415,8 @@ void bch2_journal_pin_set(struct journal *j, u64 seq,
 
 /**
  * bch2_journal_pin_flush: ensure journal pin callback is no longer running
+ * @j:         journal object
+ * @pin:       pin to flush
  */
 void bch2_journal_pin_flush(struct journal *j, struct journal_entry_pin *pin)
 {
@@ -578,7 +577,11 @@ static u64 journal_seq_to_flush(struct journal *j)
 }
 
 /**
- * bch2_journal_reclaim - free up journal buckets
+ * __bch2_journal_reclaim - free up journal buckets
+ * @j:         journal object
+ * @direct:    direct or background reclaim?
+ * @kicked:    requested to run since we last ran?
+ * Returns:    0 on success, or -EIO if the journal has been shutdown
  *
  * Background journal reclaim writes out btree nodes. It should be run
  * early enough so that we never completely run out of journal buckets.
@@ -757,7 +760,7 @@ int bch2_journal_reclaim_start(struct journal *j)
                           "bch-reclaim/%s", c->name);
        ret = PTR_ERR_OR_ZERO(p);
        if (ret) {
-               bch_err(c, "error creating journal reclaim thread: %s", bch2_err_str(ret));
+               bch_err_msg(c, ret, "creating journal reclaim thread");
                return ret;
        }