summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2022-12-01 21:59:25 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2022-12-02 11:48:57 -0500
commit06de518acea81278abe3565ecc825e05b5259d2c (patch)
treedb01ec033e2dbcf355786a11b9e74f2f9360f5ef
parent00fed1b3dd37fb81900981545eeac93bb835a81d (diff)
bcachefs: Simplify journal read path
This just cleans up and simplifies the code that decides where to resume writing in the journal - when the code was originally written we weren't saving the precise location of every journal write found. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r--fs/bcachefs/journal_io.c31
1 files changed, 6 insertions, 25 deletions
diff --git a/fs/bcachefs/journal_io.c b/fs/bcachefs/journal_io.c
index f1dbf65afe77..2b1974a9f360 100644
--- a/fs/bcachefs/journal_io.c
+++ b/fs/bcachefs/journal_io.c
@@ -987,7 +987,6 @@ static void bch2_journal_read_device(struct closure *cl)
struct journal_replay *r, **_r;
struct genradix_iter iter;
struct journal_read_buf buf = { NULL, 0 };
- u64 min_seq = U64_MAX;
unsigned i;
int ret = 0;
@@ -1006,45 +1005,27 @@ static void bch2_journal_read_device(struct closure *cl)
goto err;
}
- /* Find the journal bucket with the highest sequence number: */
- for (i = 0; i < ja->nr; i++) {
- if (ja->bucket_seq[i] > ja->bucket_seq[ja->cur_idx])
- ja->cur_idx = i;
-
- min_seq = min(ja->bucket_seq[i], min_seq);
- }
-
- /*
- * If there's duplicate journal entries in multiple buckets (which
- * definitely isn't supposed to happen, but...) - make sure to start
- * cur_idx at the last of those buckets, so we don't deadlock trying to
- * allocate
- */
- while (ja->bucket_seq[ja->cur_idx] > min_seq &&
- ja->bucket_seq[ja->cur_idx] ==
- ja->bucket_seq[(ja->cur_idx + 1) % ja->nr])
- ja->cur_idx = (ja->cur_idx + 1) % ja->nr;
-
ja->sectors_free = ca->mi.bucket_size;
mutex_lock(&jlist->lock);
- genradix_for_each(&c->journal_entries, iter, _r) {
+ genradix_for_each_reverse(&c->journal_entries, iter, _r) {
r = *_r;
if (!r)
continue;
for (i = 0; i < r->nr_ptrs; i++) {
- if (r->ptrs[i].dev == ca->dev_idx &&
- sector_to_bucket(ca, r->ptrs[i].sector) == ja->buckets[ja->cur_idx]) {
+ if (r->ptrs[i].dev == ca->dev_idx) {
unsigned wrote = bucket_remainder(ca, r->ptrs[i].sector) +
vstruct_sectors(&r->j, c->block_bits);
- ja->sectors_free = min(ja->sectors_free,
- ca->mi.bucket_size - wrote);
+ ja->cur_idx = r->ptrs[i].bucket;
+ ja->sectors_free = ca->mi.bucket_size - wrote;
+ goto found;
}
}
}
+found:
mutex_unlock(&jlist->lock);
if (ja->bucket_seq[ja->cur_idx] &&