Skip to content

Commit

Permalink
bcachefs: Fix assertion in bch2_btree_key_cache_drop()
Browse files Browse the repository at this point in the history
Turns out this assertion was something we could legitimately hit - add a
comment describing what's going on, and handle it.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
  • Loading branch information
koverstreet authored and Kent Overstreet committed Oct 22, 2023
1 parent ff7dc36 commit 45b033f
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions fs/bcachefs/btree_key_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -639,11 +639,22 @@ bool bch2_btree_insert_key_cached(struct btree_trans *trans,
void bch2_btree_key_cache_drop(struct btree_trans *trans,
struct btree_path *path)
{
struct bch_fs *c = trans->c;
struct bkey_cached *ck = (void *) path->l[0].b;

ck->valid = false;
BUG_ON(!ck->valid);

BUG_ON(test_bit(BKEY_CACHED_DIRTY, &ck->flags));
/*
* We just did an update to the btree, bypassing the key cache: the key
* cache key is now stale and must be dropped, even if dirty:
*/
if (test_bit(BKEY_CACHED_DIRTY, &ck->flags)) {
clear_bit(BKEY_CACHED_DIRTY, &ck->flags);
atomic_long_dec(&c->btree_key_cache.nr_dirty);
bch2_journal_pin_drop(&c->journal, &ck->journal);
}

ck->valid = false;
}

static unsigned long bch2_btree_key_cache_scan(struct shrinker *shrink,
Expand Down

0 comments on commit 45b033f

Please sign in to comment.