]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/journal.h
Update bcachefs sources to 7958ebe324 bcachefs: Fix alloc_v4_backpointers()
[bcachefs-tools-debian] / libbcachefs / journal.h
index 7fee0c05aa7d72069b49ff6a3872ec04d8ac33e8..ee37f90aa6b369097170d85ea2b3fe35c69d56ea 100644 (file)
@@ -29,8 +29,8 @@
  *
  * Synchronous updates are specified by passing a closure (@flush_cl) to
  * bch2_btree_insert() or bch_btree_insert_node(), which then pass that parameter
- * down to the journalling code. That closure will will wait on the journal
- * write to complete (via closure_wait()).
+ * down to the journalling code. That closure will wait on the journal write to
+ * complete (via closure_wait()).
  *
  * If the index update wasn't synchronous, the journal entry will be
  * written out after 10 ms have elapsed, by default (the delay_ms field
  */
 
 #include <linux/hash.h>
+#include <linux/prefetch.h>
 
 #include "journal_types.h"
 
@@ -146,8 +147,6 @@ static inline u64 journal_last_unwritten_seq(struct journal *j)
        return j->seq_ondisk + 1;
 }
 
-void bch2_journal_set_has_inum(struct journal *, u64, u64);
-
 static inline int journal_state_count(union journal_res_state s, int idx)
 {
        switch (idx) {
@@ -201,9 +200,9 @@ journal_res_entry(struct journal *j, struct journal_res *res)
        return vstruct_idx(j->buf[res->idx].data, res->offset);
 }
 
-static inline unsigned journal_entry_set(struct jset_entry *entry, unsigned type,
+static inline unsigned journal_entry_init(struct jset_entry *entry, unsigned type,
                                          enum btree_id id, unsigned level,
-                                         const void *data, unsigned u64s)
+                                         unsigned u64s)
 {
        entry->u64s     = cpu_to_le16(u64s);
        entry->btree_id = id;
@@ -212,32 +211,33 @@ static inline unsigned journal_entry_set(struct jset_entry *entry, unsigned type
        entry->pad[0]   = 0;
        entry->pad[1]   = 0;
        entry->pad[2]   = 0;
-       memcpy_u64s_small(entry->_data, data, u64s);
-
        return jset_u64s(u64s);
 }
 
-static inline void bch2_journal_add_entry(struct journal *j, struct journal_res *res,
-                                         unsigned type, enum btree_id id,
-                                         unsigned level,
+static inline unsigned journal_entry_set(struct jset_entry *entry, unsigned type,
+                                         enum btree_id id, unsigned level,
                                          const void *data, unsigned u64s)
 {
-       unsigned actual = journal_entry_set(journal_res_entry(j, res),
-                              type, id, level, data, u64s);
+       unsigned ret = journal_entry_init(entry, type, id, level, u64s);
+
+       memcpy_u64s_small(entry->_data, data, u64s);
+       return ret;
+}
+
+static inline struct jset_entry *
+bch2_journal_add_entry(struct journal *j, struct journal_res *res,
+                        unsigned type, enum btree_id id,
+                        unsigned level, unsigned u64s)
+{
+       struct jset_entry *entry = journal_res_entry(j, res);
+       unsigned actual = journal_entry_init(entry, type, id, level, u64s);
 
        EBUG_ON(!res->ref);
        EBUG_ON(actual > res->u64s);
 
        res->offset     += actual;
        res->u64s       -= actual;
-}
-
-static inline void bch2_journal_add_keys(struct journal *j, struct journal_res *res,
-                                       enum btree_id id, unsigned level,
-                                       const struct bkey_i *k)
-{
-       bch2_journal_add_entry(j, res, BCH_JSET_ENTRY_btree_keys,
-                              id, level, k, k->k.u64s);
+       return entry;
 }
 
 static inline bool journal_entry_empty(struct jset *j)
@@ -285,7 +285,7 @@ static inline void bch2_journal_res_put(struct journal *j,
        while (res->u64s)
                bch2_journal_add_entry(j, res,
                                       BCH_JSET_ENTRY_btree_keys,
-                                      0, 0, NULL, 0);
+                                      0, 0, 0);
 
        bch2_journal_buf_put(j, res->idx);
 
@@ -305,15 +305,26 @@ static inline int journal_res_get_fast(struct journal *j,
 {
        union journal_res_state old, new;
        u64 v = atomic64_read(&j->reservations.counter);
+       unsigned u64s, offset;
 
        do {
                old.v = new.v = v;
 
+               /*
+                * Round up the end of the journal reservation to the next
+                * cacheline boundary:
+                */
+               u64s = res->u64s;
+               offset = sizeof(struct jset) / sizeof(u64) +
+                         new.cur_entry_offset + u64s;
+               u64s += ((offset - 1) & ((SMP_CACHE_BYTES / sizeof(u64)) - 1)) + 1;
+
+
                /*
                 * Check if there is still room in the current journal
                 * entry:
                 */
-               if (new.cur_entry_offset + res->u64s > j->cur_entry_u64s)
+               if (new.cur_entry_offset + u64s > j->cur_entry_u64s)
                        return 0;
 
                EBUG_ON(!journal_state_count(new, new.idx));
@@ -321,7 +332,7 @@ static inline int journal_res_get_fast(struct journal *j,
                if ((flags & JOURNAL_WATERMARK_MASK) < j->watermark)
                        return 0;
 
-               new.cur_entry_offset += res->u64s;
+               new.cur_entry_offset += u64s;
                journal_state_inc(&new);
 
                /*
@@ -338,8 +349,15 @@ static inline int journal_res_get_fast(struct journal *j,
 
        res->ref        = true;
        res->idx        = old.idx;
+       res->u64s       = u64s;
        res->offset     = old.cur_entry_offset;
        res->seq        = le64_to_cpu(j->buf[old.idx].data->seq);
+
+       offset = res->offset;
+       while (offset < res->offset + res->u64s) {
+               prefetchw(vstruct_idx(j->buf[res->idx].data, offset));
+               offset += SMP_CACHE_BYTES / sizeof(u64);
+       }
        return 1;
 }
 
@@ -461,7 +479,7 @@ static inline int bch2_journal_preres_get(struct journal *j,
                return 0;
 
        if (flags & JOURNAL_RES_GET_NONBLOCK)
-               return -EAGAIN;
+               return -BCH_ERR_journal_preres_get_blocked;
 
        return __bch2_journal_preres_get(j, res, new_u64s, flags);
 }
@@ -479,7 +497,6 @@ 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 *);
-int bch2_journal_log_msg(struct journal *, const char *, ...);
 
 void bch2_journal_halt(struct journal *);