From: Kent Overstreet Date: Tue, 27 Apr 2021 18:02:00 +0000 (-0400) Subject: bcachefs: Change bch2_btree_key_cache_count() to exclude dirty keys X-Git-Tag: io_uring-6.7-2023-11-10~119^2~1601 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=baa6502905df0acb94afbf6c93f51a1f2aa4c7ca;p=linux-2.6-block.git bcachefs: Change bch2_btree_key_cache_count() to exclude dirty keys We're seeing livelocks that appear to be due to bch2_btree_key_cache_scan repeatedly scanning and blocking other tasks from using the key cache lock - we probably shouldn't be reporting objects that can't actually be freed yet. Signed-off-by: Kent Overstreet Signed-off-by: Kent Overstreet --- diff --git a/fs/bcachefs/btree_key_cache.c b/fs/bcachefs/btree_key_cache.c index f8b9ca4dfb2b..221cb0f46db0 100644 --- a/fs/bcachefs/btree_key_cache.c +++ b/fs/bcachefs/btree_key_cache.c @@ -646,8 +646,10 @@ static unsigned long bch2_btree_key_cache_count(struct shrinker *shrink, struct bch_fs *c = container_of(shrink, struct bch_fs, btree_key_cache.shrink); struct btree_key_cache *bc = &c->btree_key_cache; + long nr = atomic_long_read(&bc->nr_keys) - + atomic_long_read(&bc->nr_dirty); - return atomic_long_read(&bc->nr_keys); + return max(0L, nr); } void bch2_fs_btree_key_cache_exit(struct btree_key_cache *bc)