]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
bcachefs: Add hysteresis to waiting on btree key cache flush
authorKent Overstreet <kent.overstreet@linux.dev>
Sat, 10 Aug 2024 18:40:09 +0000 (14:40 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Wed, 14 Aug 2024 03:00:34 +0000 (23:00 -0400)
This helps ensure key cache reclaim isn't contending with threads
waiting for the key cache to be helped, and fixes a severe performance
bug.

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

index e6b2cd0dd2c1afc2a21c628763422c2a2a314f69..113309f6291868a01a487be6ca3f00c11117d5e9 100644 (file)
@@ -20,6 +20,15 @@ static inline bool bch2_btree_key_cache_must_wait(struct bch_fs *c)
        return nr_dirty > max_dirty;
 }
 
+static inline bool bch2_btree_key_cache_wait_done(struct bch_fs *c)
+{
+       size_t nr_dirty = atomic_long_read(&c->btree_key_cache.nr_dirty);
+       size_t nr_keys = atomic_long_read(&c->btree_key_cache.nr_keys);
+       size_t max_dirty = 2048 + (nr_keys * 5) / 8;
+
+       return nr_dirty <= max_dirty;
+}
+
 int bch2_btree_key_cache_journal_flush(struct journal *,
                                struct journal_entry_pin *, u64);
 
index cca336fe46e9b44bd887de63c3bbd1aca2f52202..f567bfb828508ac8c34f0f79e11ac8f7d5bed98b 100644 (file)
@@ -927,7 +927,7 @@ static inline int do_bch2_trans_commit(struct btree_trans *trans, unsigned flags
 static int journal_reclaim_wait_done(struct bch_fs *c)
 {
        int ret = bch2_journal_error(&c->journal) ?:
-               !bch2_btree_key_cache_must_wait(c);
+               bch2_btree_key_cache_wait_done(c);
 
        if (!ret)
                journal_reclaim_kick(&c->journal);