From d5425a3b220a8b94ae2dd3c74af001a6b1216651 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Thu, 19 Nov 2020 21:40:03 -0500 Subject: bcachefs: Throttle updates when btree key cache is too dirty This is needed to ensure we don't deadlock because journal reclaim and thus memory reclaim isn't making forward progress. Signed-off-by: Kent Overstreet Signed-off-by: Kent Overstreet --- fs/bcachefs/btree_key_cache.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'fs/bcachefs/btree_key_cache.h') diff --git a/fs/bcachefs/btree_key_cache.h b/fs/bcachefs/btree_key_cache.h index 7723a2178430..d7d31a0662c3 100644 --- a/fs/bcachefs/btree_key_cache.h +++ b/fs/bcachefs/btree_key_cache.h @@ -5,11 +5,20 @@ static inline size_t bch2_nr_btree_keys_need_flush(struct bch_fs *c) { size_t nr_dirty = READ_ONCE(c->btree_key_cache.nr_dirty); size_t nr_keys = READ_ONCE(c->btree_key_cache.nr_dirty); - size_t max_dirty = 1024 + (nr_keys * 3) / 4; + size_t max_dirty = 4096 + nr_keys / 2; return max_t(ssize_t, 0, nr_dirty - max_dirty); } +static inline bool bch2_btree_key_cache_must_wait(struct bch_fs *c) +{ + size_t nr_dirty = READ_ONCE(c->btree_key_cache.nr_dirty); + size_t nr_keys = READ_ONCE(c->btree_key_cache.nr_dirty); + size_t max_dirty = 4096 + (nr_keys * 3) / 4; + + return nr_dirty > max_dirty; +} + struct bkey_cached * bch2_btree_key_cache_find(struct bch_fs *, enum btree_id, struct bpos); -- cgit v1.2.3