diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2020-12-05 16:25:05 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 17:08:49 -0400 |
commit | 5d32c5bb076e76232e56fd44c537046abd54d32c (patch) | |
tree | a5df7839b857d7510fc23db234dea7a854d21177 /fs/bcachefs/journal_reclaim.c | |
parent | adbcada43fa79197224b5a522b1faaf222b43bcd (diff) | |
download | lwn-5d32c5bb076e76232e56fd44c537046abd54d32c.tar.gz lwn-5d32c5bb076e76232e56fd44c537046abd54d32c.zip |
bcachefs: Be more conservation about journal pre-reservations
- Try to always keep 1/8th of the journal free, on top of
pre-reservations
- Move the check for whether the journal is stuck to
bch2_journal_space_available, and make it only fire when there aren't
any journal writes in flight (that might free up space by updating
last_seq)
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/journal_reclaim.c')
-rw-r--r-- | fs/bcachefs/journal_reclaim.c | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/fs/bcachefs/journal_reclaim.c b/fs/bcachefs/journal_reclaim.c index a3d5405991b9..0fba832d3670 100644 --- a/fs/bcachefs/journal_reclaim.c +++ b/fs/bcachefs/journal_reclaim.c @@ -2,6 +2,7 @@ #include "bcachefs.h" #include "btree_key_cache.h" +#include "error.h" #include "journal.h" #include "journal_io.h" #include "journal_reclaim.h" @@ -159,7 +160,7 @@ void bch2_journal_space_available(struct journal *j) struct bch_fs *c = container_of(j, struct bch_fs, journal); struct bch_dev *ca; unsigned clean, clean_ondisk, total; - unsigned overhead, u64s_remaining = 0; + s64 u64s_remaining = 0; unsigned max_entry_size = min(j->buf[0].buf_size >> 9, j->buf[1].buf_size >> 9); unsigned i, nr_online = 0, nr_devs_want; @@ -208,22 +209,37 @@ void bch2_journal_space_available(struct journal *j) clean = j->space[journal_space_clean].total; total = j->space[journal_space_total].total; - if (!j->space[journal_space_discarded].next_entry) + if (!clean_ondisk && + j->reservations.idx == + j->reservations.unwritten_idx) { + char *buf = kmalloc(4096, GFP_ATOMIC); + + bch_err(c, "journal stuck"); + if (buf) { + __bch2_journal_debug_to_text(&_PBUF(buf, 4096), j); + pr_err("\n%s", buf); + kfree(buf); + } + + bch2_fatal_error(c); + ret = cur_entry_journal_stuck; + } else if (!j->space[journal_space_discarded].next_entry) ret = cur_entry_journal_full; else if (!fifo_free(&j->pin)) ret = cur_entry_journal_pin_full; - if ((clean - clean_ondisk <= total / 8) && + if ((j->space[journal_space_clean_ondisk].next_entry < + j->space[journal_space_clean_ondisk].total) && + (clean - clean_ondisk <= total / 8) && (clean_ondisk * 2 > clean )) set_bit(JOURNAL_MAY_SKIP_FLUSH, &j->flags); else clear_bit(JOURNAL_MAY_SKIP_FLUSH, &j->flags); - overhead = DIV_ROUND_UP(clean, max_entry_size) * - journal_entry_overhead(j); - u64s_remaining = clean << 6; - u64s_remaining = max_t(int, 0, u64s_remaining - overhead); - u64s_remaining /= 4; + u64s_remaining = (u64) clean << 6; + u64s_remaining -= (u64) total << 3; + u64s_remaining = max(0LL, u64s_remaining); + u64s_remaining /= 2; out: j->cur_entry_sectors = !ret ? j->space[journal_space_discarded].next_entry : 0; j->cur_entry_error = ret; @@ -572,6 +588,9 @@ static int __bch2_journal_reclaim(struct journal *j, bool direct) c->btree_cache.used * 3) min_nr = 1; + if (fifo_free(&j->pin) <= 32) + min_nr = 1; + min_nr = max(min_nr, bch2_nr_btree_keys_need_flush(c)); trace_journal_reclaim_start(c, |