summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-06-27 17:32:38 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:10:05 -0400
commitec14fc6010fdcc40e54e289afc657a676ce93e72 (patch)
treee8fba04ba538c638d926763706411559a43016a6
parent494036d862dfff1de9782492692da225479b7146 (diff)
bcachefs: Kill JOURNAL_WATERMARK
This unifies JOURNAL_WATERMARK with BCH_WATERMARK; we're working towards specifying watermarks once in the transaction commit path. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r--fs/bcachefs/alloc_types.h13
-rw-r--r--fs/bcachefs/btree_key_cache.c2
-rw-r--r--fs/bcachefs/btree_update.h4
-rw-r--r--fs/bcachefs/btree_update_interior.c6
-rw-r--r--fs/bcachefs/btree_update_leaf.c12
-rw-r--r--fs/bcachefs/btree_write_buffer.c2
-rw-r--r--fs/bcachefs/journal.c15
-rw-r--r--fs/bcachefs/journal.h26
-rw-r--r--fs/bcachefs/journal_io.c2
-rw-r--r--fs/bcachefs/journal_types.h15
-rw-r--r--fs/bcachefs/movinggc.c2
-rw-r--r--fs/bcachefs/recovery.c2
12 files changed, 46 insertions, 55 deletions
diff --git a/fs/bcachefs/alloc_types.h b/fs/bcachefs/alloc_types.h
index ddcaf0631a8b..c33a29954e59 100644
--- a/fs/bcachefs/alloc_types.h
+++ b/fs/bcachefs/alloc_types.h
@@ -17,12 +17,12 @@ struct bucket_alloc_state {
};
#define BCH_WATERMARKS() \
- x(reclaim) \
- x(btree_copygc) \
- x(btree) \
- x(copygc) \
+ x(stripe) \
x(normal) \
- x(stripe)
+ x(copygc) \
+ x(btree) \
+ x(btree_copygc) \
+ x(reclaim)
enum bch_watermark {
#define x(name) BCH_WATERMARK_##name,
@@ -31,6 +31,9 @@ enum bch_watermark {
BCH_WATERMARK_NR,
};
+#define BCH_WATERMARK_BITS 3
+#define BCH_WATERMARK_MASK ~(~0 << BCH_WATERMARK_BITS)
+
#define OPEN_BUCKETS_COUNT 1024
#define WRITE_POINT_HASH_NR 32
diff --git a/fs/bcachefs/btree_key_cache.c b/fs/bcachefs/btree_key_cache.c
index 5f00688d46f1..40847ec1e56e 100644
--- a/fs/bcachefs/btree_key_cache.c
+++ b/fs/bcachefs/btree_key_cache.c
@@ -652,7 +652,7 @@ static int btree_key_cache_flush_pos(struct btree_trans *trans,
BTREE_INSERT_NOFAIL|
BTREE_INSERT_USE_RESERVE|
(ck->journal.seq == journal_last_seq(j)
- ? JOURNAL_WATERMARK_reserved
+ ? BCH_WATERMARK_reclaim
: 0)|
commit_flags);
diff --git a/fs/bcachefs/btree_update.h b/fs/bcachefs/btree_update.h
index 8911a7f79f1c..8ecb87533cf3 100644
--- a/fs/bcachefs/btree_update.h
+++ b/fs/bcachefs/btree_update.h
@@ -23,8 +23,8 @@ void bch2_btree_insert_key_leaf(struct btree_trans *, struct btree_path *,
struct bkey_i *, u64);
enum btree_insert_flags {
- /* First two bits for journal watermark: */
- __BTREE_INSERT_NOFAIL = 2,
+ /* First bits for bch_watermark: */
+ __BTREE_INSERT_NOFAIL = BCH_WATERMARK_BITS,
__BTREE_INSERT_NOCHECK_RW,
__BTREE_INSERT_LAZY_RW,
__BTREE_INSERT_USE_RESERVE,
diff --git a/fs/bcachefs/btree_update_interior.c b/fs/bcachefs/btree_update_interior.c
index eb3319f97296..914cb80fc6d9 100644
--- a/fs/bcachefs/btree_update_interior.c
+++ b/fs/bcachefs/btree_update_interior.c
@@ -651,7 +651,7 @@ static void btree_update_nodes_written(struct btree_update *as)
BTREE_INSERT_NOCHECK_RW|
BTREE_INSERT_USE_RESERVE|
BTREE_INSERT_JOURNAL_RECLAIM|
- JOURNAL_WATERMARK_reserved,
+ BCH_WATERMARK_reclaim,
btree_update_nodes_written_trans(&trans, as));
bch2_trans_unlock(&trans);
@@ -1049,7 +1049,7 @@ bch2_btree_update_start(struct btree_trans *trans, struct btree_path *path,
? BCH_DISK_RESERVATION_NOFAIL : 0;
unsigned nr_nodes[2] = { 0, 0 };
unsigned update_level = level;
- int journal_flags = flags & JOURNAL_WATERMARK_MASK;
+ int journal_flags = flags & BCH_WATERMARK_MASK;
int ret = 0;
u32 restart_count = trans->restart_count;
@@ -2192,7 +2192,7 @@ static int __bch2_btree_node_update_key(struct btree_trans *trans,
BTREE_INSERT_NOCHECK_RW|
BTREE_INSERT_USE_RESERVE|
BTREE_INSERT_JOURNAL_RECLAIM|
- JOURNAL_WATERMARK_reserved);
+ BCH_WATERMARK_reclaim);
if (ret)
goto err;
diff --git a/fs/bcachefs/btree_update_leaf.c b/fs/bcachefs/btree_update_leaf.c
index 259e5e47d2a7..ce6ec28d8f60 100644
--- a/fs/bcachefs/btree_update_leaf.c
+++ b/fs/bcachefs/btree_update_leaf.c
@@ -320,7 +320,7 @@ bch2_trans_journal_preres_get_cold(struct btree_trans *trans, unsigned flags,
bch2_journal_preres_get(&trans->c->journal,
&trans->journal_preres,
trans->journal_preres_u64s,
- (flags & JOURNAL_WATERMARK_MASK)));
+ (flags & BCH_WATERMARK_MASK)));
}
static __always_inline int bch2_trans_journal_res_get(struct btree_trans *trans,
@@ -636,7 +636,7 @@ bch2_trans_commit_write_locked(struct btree_trans *trans, unsigned flags,
*/
if (likely(!(flags & BTREE_INSERT_JOURNAL_REPLAY))) {
ret = bch2_trans_journal_res_get(trans,
- (flags & JOURNAL_WATERMARK_MASK)|
+ (flags & BCH_WATERMARK_MASK)|
JOURNAL_RES_GET_NONBLOCK);
if (ret)
return ret;
@@ -885,7 +885,7 @@ static inline int do_bch2_trans_commit(struct btree_trans *trans, unsigned flags
ret = bch2_journal_preres_get(&c->journal,
&trans->journal_preres, trans->journal_preres_u64s,
- (flags & JOURNAL_WATERMARK_MASK)|JOURNAL_RES_GET_NONBLOCK);
+ (flags & BCH_WATERMARK_MASK)|JOURNAL_RES_GET_NONBLOCK);
if (unlikely(ret == -BCH_ERR_journal_preres_get_blocked))
ret = bch2_trans_journal_preres_get_cold(trans, flags, trace_ip);
if (unlikely(ret))
@@ -952,14 +952,14 @@ int bch2_trans_commit_error(struct btree_trans *trans, unsigned flags,
break;
case -BCH_ERR_journal_res_get_blocked:
if ((flags & BTREE_INSERT_JOURNAL_RECLAIM) &&
- !(flags & JOURNAL_WATERMARK_reserved)) {
+ (flags & BCH_WATERMARK_MASK) != BCH_WATERMARK_reclaim) {
ret = -BCH_ERR_journal_reclaim_would_deadlock;
break;
}
ret = drop_locks_do(trans,
bch2_trans_journal_res_get(trans,
- (flags & JOURNAL_WATERMARK_MASK)|
+ (flags & BCH_WATERMARK_MASK)|
JOURNAL_RES_GET_CHECK));
break;
case -BCH_ERR_btree_insert_need_journal_reclaim:
@@ -2048,7 +2048,7 @@ int bch2_journal_log_msg(struct bch_fs *c, const char *fmt, ...)
int ret;
va_start(args, fmt);
- ret = __bch2_fs_log_msg(c, JOURNAL_WATERMARK_reserved, fmt, args);
+ ret = __bch2_fs_log_msg(c, BCH_WATERMARK_reclaim, fmt, args);
va_end(args);
return ret;
}
diff --git a/fs/bcachefs/btree_write_buffer.c b/fs/bcachefs/btree_write_buffer.c
index 88c4b50dd70f..4003fa1f0319 100644
--- a/fs/bcachefs/btree_write_buffer.c
+++ b/fs/bcachefs/btree_write_buffer.c
@@ -232,7 +232,7 @@ slowpath:
commit_flags|
BTREE_INSERT_NOFAIL|
BTREE_INSERT_JOURNAL_RECLAIM|
- JOURNAL_WATERMARK_reserved,
+ BCH_WATERMARK_reclaim,
__bch2_btree_insert(trans, i->btree, &i->k, 0));
if (bch2_fs_fatal_err_on(ret, c, "%s: insert error %s", __func__, bch2_err_str(ret)))
break;
diff --git a/fs/bcachefs/journal.c b/fs/bcachefs/journal.c
index dc34aba2d259..f33ab45b7944 100644
--- a/fs/bcachefs/journal.c
+++ b/fs/bcachefs/journal.c
@@ -19,17 +19,12 @@
#include "journal_seq_blacklist.h"
#include "trace.h"
-#define x(n) #n,
-static const char * const bch2_journal_watermarks[] = {
- JOURNAL_WATERMARKS()
- NULL
-};
-
static const char * const bch2_journal_errors[] = {
+#define x(n) #n,
JOURNAL_ERRORS()
+#undef x
NULL
};
-#undef x
static inline bool journal_seq_unwritten(struct journal *j, u64 seq)
{
@@ -96,7 +91,7 @@ journal_error_check_stuck(struct journal *j, int error, unsigned flags)
if (!(error == JOURNAL_ERR_journal_full ||
error == JOURNAL_ERR_journal_pin_full) ||
nr_unwritten_journal_entries(j) ||
- (flags & JOURNAL_WATERMARK_MASK) != JOURNAL_WATERMARK_reserved)
+ (flags & BCH_WATERMARK_MASK) != BCH_WATERMARK_reclaim)
return stuck;
spin_lock(&j->lock);
@@ -440,7 +435,7 @@ retry:
return 0;
}
- if ((flags & JOURNAL_WATERMARK_MASK) < j->watermark) {
+ if ((flags & BCH_WATERMARK_MASK) < j->watermark) {
/*
* Don't want to close current journal entry, just need to
* invoke reclaim:
@@ -1292,7 +1287,7 @@ void __bch2_journal_debug_to_text(struct printbuf *out, struct journal *j)
prt_printf(out, "last_seq_ondisk:\t%llu\n", j->last_seq_ondisk);
prt_printf(out, "flushed_seq_ondisk:\t%llu\n", j->flushed_seq_ondisk);
prt_printf(out, "prereserved:\t\t%u/%u\n", j->prereserved.reserved, j->prereserved.remaining);
- prt_printf(out, "watermark:\t\t%s\n", bch2_journal_watermarks[j->watermark]);
+ prt_printf(out, "watermark:\t\t%s\n", bch2_watermarks[j->watermark]);
prt_printf(out, "each entry reserved:\t%u\n", j->entry_u64s_reserved);
prt_printf(out, "nr flush writes:\t%llu\n", j->nr_flush_writes);
prt_printf(out, "nr noflush writes:\t%llu\n", j->nr_noflush_writes);
diff --git a/fs/bcachefs/journal.h b/fs/bcachefs/journal.h
index 024cea9f5902..008a2e25a4fa 100644
--- a/fs/bcachefs/journal.h
+++ b/fs/bcachefs/journal.h
@@ -294,9 +294,14 @@ static inline void bch2_journal_res_put(struct journal *j,
int bch2_journal_res_get_slowpath(struct journal *, struct journal_res *,
unsigned);
-/* First two bits for JOURNAL_WATERMARK: */
-#define JOURNAL_RES_GET_NONBLOCK (1 << 2)
-#define JOURNAL_RES_GET_CHECK (1 << 3)
+/* First bits for BCH_WATERMARK: */
+enum journal_res_flags {
+ __JOURNAL_RES_GET_NONBLOCK = BCH_WATERMARK_BITS,
+ __JOURNAL_RES_GET_CHECK,
+};
+
+#define JOURNAL_RES_GET_NONBLOCK (1 << __JOURNAL_RES_GET_NONBLOCK)
+#define JOURNAL_RES_GET_CHECK (1 << __JOURNAL_RES_GET_CHECK)
static inline int journal_res_get_fast(struct journal *j,
struct journal_res *res,
@@ -317,7 +322,7 @@ static inline int journal_res_get_fast(struct journal *j,
EBUG_ON(!journal_state_count(new, new.idx));
- if ((flags & JOURNAL_WATERMARK_MASK) < j->watermark)
+ if ((flags & BCH_WATERMARK_MASK) < j->watermark)
return 0;
new.cur_entry_offset += res->u64s;
@@ -373,17 +378,17 @@ out:
static inline void journal_set_watermark(struct journal *j)
{
union journal_preres_state s = READ_ONCE(j->prereserved);
- unsigned watermark = JOURNAL_WATERMARK_any;
+ unsigned watermark = BCH_WATERMARK_stripe;
if (fifo_free(&j->pin) < j->pin.size / 4)
- watermark = max_t(unsigned, watermark, JOURNAL_WATERMARK_copygc);
+ watermark = max_t(unsigned, watermark, BCH_WATERMARK_copygc);
if (fifo_free(&j->pin) < j->pin.size / 8)
- watermark = max_t(unsigned, watermark, JOURNAL_WATERMARK_reserved);
+ watermark = max_t(unsigned, watermark, BCH_WATERMARK_reclaim);
if (s.reserved > s.remaining)
- watermark = max_t(unsigned, watermark, JOURNAL_WATERMARK_copygc);
+ watermark = max_t(unsigned, watermark, BCH_WATERMARK_copygc);
if (!s.remaining)
- watermark = max_t(unsigned, watermark, JOURNAL_WATERMARK_reserved);
+ watermark = max_t(unsigned, watermark, BCH_WATERMARK_reclaim);
if (watermark == j->watermark)
return;
@@ -426,13 +431,14 @@ static inline int bch2_journal_preres_get_fast(struct journal *j,
int d = new_u64s - res->u64s;
union journal_preres_state old, new;
u64 v = atomic64_read(&j->prereserved.counter);
+ enum bch_watermark watermark = flags & BCH_WATERMARK_MASK;
int ret;
do {
old.v = new.v = v;
ret = 0;
- if ((flags & JOURNAL_WATERMARK_reserved) ||
+ if (watermark == BCH_WATERMARK_reclaim ||
new.reserved + d < new.remaining) {
new.reserved += d;
ret = 1;
diff --git a/fs/bcachefs/journal_io.c b/fs/bcachefs/journal_io.c
index 8dc378674919..7d0dd1b1d5cf 100644
--- a/fs/bcachefs/journal_io.c
+++ b/fs/bcachefs/journal_io.c
@@ -1505,7 +1505,7 @@ static void journal_write_done(struct closure *cl)
* Must come before signaling write completion, for
* bch2_fs_journal_stop():
*/
- if (j->watermark)
+ if (j->watermark != BCH_WATERMARK_stripe)
journal_reclaim_kick(&c->journal);
/* also must come before signalling write completion: */
diff --git a/fs/bcachefs/journal_types.h b/fs/bcachefs/journal_types.h
index 8d8c0b3d5a30..42504e16acb6 100644
--- a/fs/bcachefs/journal_types.h
+++ b/fs/bcachefs/journal_types.h
@@ -154,19 +154,6 @@ enum journal_flags {
JOURNAL_NEED_FLUSH_WRITE,
};
-#define JOURNAL_WATERMARKS() \
- x(any) \
- x(copygc) \
- x(reserved)
-
-enum journal_watermark {
-#define x(n) JOURNAL_WATERMARK_##n,
- JOURNAL_WATERMARKS()
-#undef x
-};
-
-#define JOURNAL_WATERMARK_MASK 3
-
/* Reasons we may fail to get a journal reservation: */
#define JOURNAL_ERRORS() \
x(ok) \
@@ -191,7 +178,7 @@ struct journal {
struct {
union journal_res_state reservations;
- enum journal_watermark watermark;
+ enum bch_watermark watermark;
union journal_preres_state prereserved;
diff --git a/fs/bcachefs/movinggc.c b/fs/bcachefs/movinggc.c
index 5ea512968f4d..e1ca414047b1 100644
--- a/fs/bcachefs/movinggc.c
+++ b/fs/bcachefs/movinggc.c
@@ -202,7 +202,7 @@ static int bch2_copygc(struct btree_trans *trans,
{
struct bch_fs *c = trans->c;
struct data_update_opts data_opts = {
- .btree_insert_flags = BTREE_INSERT_USE_RESERVE|JOURNAL_WATERMARK_copygc,
+ .btree_insert_flags = BTREE_INSERT_USE_RESERVE|BCH_WATERMARK_copygc,
};
move_buckets buckets = { 0 };
struct move_bucket_in_flight *f;
diff --git a/fs/bcachefs/recovery.c b/fs/bcachefs/recovery.c
index 09c9d4058f82..16a99edb2ea8 100644
--- a/fs/bcachefs/recovery.c
+++ b/fs/bcachefs/recovery.c
@@ -664,7 +664,7 @@ static int bch2_journal_replay(struct bch_fs *c, u64 start_seq, u64 end_seq)
BTREE_INSERT_LAZY_RW|
BTREE_INSERT_NOFAIL|
(!k->allocated
- ? BTREE_INSERT_JOURNAL_REPLAY|JOURNAL_WATERMARK_reserved
+ ? BTREE_INSERT_JOURNAL_REPLAY|BCH_WATERMARK_reclaim
: 0),
bch2_journal_replay_key(&trans, k));
if (ret) {