summaryrefslogtreecommitdiff
path: root/fs/bcachefs/journal_io.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2022-12-01 21:59:25 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:09:47 -0400
commit230fa1c735496a2f89eb8bcc1471a46f0d917975 (patch)
treeb7f6f70aaf27932ed520fa295b0e87029cab7d1b /fs/bcachefs/journal_io.c
parentb9004e8576b1c2803ee7d7b3f28fbcc779f05ffb (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>
Diffstat (limited to 'fs/bcachefs/journal_io.c')
-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 a5c9524aa6e7..854a0685db09 100644
--- a/fs/bcachefs/journal_io.c
+++ b/fs/bcachefs/journal_io.c
@@ -986,7 +986,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;
@@ -1005,45 +1004,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] &&