Skip to content

Commit 789566d

Browse files
author
Kent Overstreet
committed
bcachefs: bch2_btree_key_cache_drop() now evicts
As part of improving btree key cache coherency, the bkey_cached.valid flag is going away. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent febc33c commit 789566d

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

fs/bcachefs/btree_key_cache.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,7 @@ void bch2_btree_key_cache_drop(struct btree_trans *trans,
792792
struct btree_path *path)
793793
{
794794
struct bch_fs *c = trans->c;
795+
struct btree_key_cache *bc = &c->btree_key_cache;
795796
struct bkey_cached *ck = (void *) path->l[0].b;
796797

797798
BUG_ON(!ck->valid);
@@ -806,7 +807,11 @@ void bch2_btree_key_cache_drop(struct btree_trans *trans,
806807
bch2_journal_pin_drop(&c->journal, &ck->journal);
807808
}
808809

809-
ck->valid = false;
810+
bkey_cached_evict(bc, ck);
811+
bkey_cached_free_fast(bc, ck);
812+
813+
mark_btree_node_locked(trans, path, 0, BTREE_NODE_UNLOCKED);
814+
btree_path_set_dirty(path, BTREE_ITER_NEED_TRAVERSE);
810815
}
811816

812817
static unsigned long bch2_btree_key_cache_scan(struct shrinker *shrink,

fs/bcachefs/btree_trans_commit.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ static inline void bch2_trans_unlock_write(struct btree_trans *trans)
137137
{
138138
if (likely(trans->write_locked)) {
139139
trans_for_each_update(trans, i)
140-
if (!same_leaf_as_prev(trans, i))
140+
if (btree_node_locked_type(trans->paths + i->path, i->level) ==
141+
BTREE_NODE_WRITE_LOCKED)
141142
bch2_btree_node_unlock_write_inlined(trans,
142143
trans->paths + i->path, insert_l(trans, i)->b);
143144
trans->write_locked = false;
@@ -777,14 +778,12 @@ bch2_trans_commit_write_locked(struct btree_trans *trans, unsigned flags,
777778
trans_for_each_update(trans, i) {
778779
struct btree_path *path = trans->paths + i->path;
779780

780-
if (!i->cached) {
781+
if (!i->cached)
781782
bch2_btree_insert_key_leaf(trans, path, i->k, trans->journal_res.seq);
782-
} else if (!i->key_cache_already_flushed)
783+
else if (!i->key_cache_already_flushed)
783784
bch2_btree_insert_key_cached(trans, flags, i);
784-
else {
785+
else
785786
bch2_btree_key_cache_drop(trans, path);
786-
btree_path_set_dirty(path, BTREE_ITER_NEED_TRAVERSE);
787-
}
788787
}
789788

790789
return 0;

0 commit comments

Comments
 (0)