bcachefs: Fix for spinning in journal reclaim on startup
authorKent Overstreet <kent.overstreet@gmail.com>
Sat, 19 Dec 2020 20:39:10 +0000 (15:39 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:50 +0000 (17:08 -0400)
We normally avoid having too many dirty keys in the btree key cache, to
ensure that we can always shrink our caches to reclaim memory if needed.

But this check was causing us to go into an infinite loop on startup, in
the btree insert path before journal reclaim was started.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/btree_key_cache.h

index dad3e344dcf93fa4b01ae6daf16a6829eb79ec1d..2f8b5521718aa44613b764d7cb83cc3701b8e81f 100644 (file)
@@ -16,7 +16,8 @@ static inline bool bch2_btree_key_cache_must_wait(struct bch_fs *c)
        size_t nr_keys = READ_ONCE(c->btree_key_cache.nr_keys);
        size_t max_dirty = 4096 + (nr_keys * 3) / 4;
 
-       return nr_dirty > max_dirty;
+       return nr_dirty > max_dirty &&
+               test_bit(JOURNAL_RECLAIM_STARTED, &c->journal.flags);
 }
 
 struct bkey_cached *