Skip to content

Commit 7254555

Browse files
author
Kent Overstreet
committed
bcachefs: Add hysteresis to waiting on btree key cache flush
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 <[email protected]>
1 parent b2f11c6 commit 7254555

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

fs/bcachefs/btree_key_cache.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ static inline bool bch2_btree_key_cache_must_wait(struct bch_fs *c)
2020
return nr_dirty > max_dirty;
2121
}
2222

23+
static inline bool bch2_btree_key_cache_wait_done(struct bch_fs *c)
24+
{
25+
size_t nr_dirty = atomic_long_read(&c->btree_key_cache.nr_dirty);
26+
size_t nr_keys = atomic_long_read(&c->btree_key_cache.nr_keys);
27+
size_t max_dirty = 2048 + (nr_keys * 5) / 8;
28+
29+
return nr_dirty <= max_dirty;
30+
}
31+
2332
int bch2_btree_key_cache_journal_flush(struct journal *,
2433
struct journal_entry_pin *, u64);
2534

fs/bcachefs/btree_trans_commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ static inline int do_bch2_trans_commit(struct btree_trans *trans, unsigned flags
927927
static int journal_reclaim_wait_done(struct bch_fs *c)
928928
{
929929
int ret = bch2_journal_error(&c->journal) ?:
930-
!bch2_btree_key_cache_must_wait(c);
930+
bch2_btree_key_cache_wait_done(c);
931931

932932
if (!ret)
933933
journal_reclaim_kick(&c->journal);

0 commit comments

Comments
 (0)