From b71841e54343e7e7095dd8b66cae1e6e3fa6b8d5 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Tue, 22 Nov 2022 20:15:33 -0500 Subject: bcachefs: Bring back key cache for inodes The btree key cache now works for snapshots btrees, where doing a lookup requires searching through keys in older snapshots - we can finaly re-enable it for inodes. Signed-off-by: Kent Overstreet --- fs/bcachefs/inode.c | 28 ++++------------------------ fs/bcachefs/super.c | 3 --- 2 files changed, 4 insertions(+), 27 deletions(-) diff --git a/fs/bcachefs/inode.c b/fs/bcachefs/inode.c index 8860301e4af3..b1a0ed13728f 100644 --- a/fs/bcachefs/inode.c +++ b/fs/bcachefs/inode.c @@ -663,19 +663,8 @@ again: while ((k = bch2_btree_iter_peek(iter)).k && !(ret = bkey_err(k)) && bkey_lt(k.k->p, POS(0, max))) { - while (pos < iter->pos.offset) { - if (!bch2_btree_key_cache_find(c, BTREE_ID_inodes, POS(0, pos))) - goto found_slot; - - pos++; - } - - if (k.k->p.snapshot == snapshot && - !bkey_is_inode(k.k) && - !bch2_btree_key_cache_find(c, BTREE_ID_inodes, SPOS(0, pos, snapshot))) { - bch2_btree_iter_advance(iter); - continue; - } + if (pos < iter->pos.offset) + goto found_slot; /* * We don't need to iterate over keys in every snapshot once @@ -685,12 +674,8 @@ again: bch2_btree_iter_set_pos(iter, POS(0, pos)); } - while (!ret && pos < max) { - if (!bch2_btree_key_cache_find(c, BTREE_ID_inodes, POS(0, pos))) - goto found_slot; - - pos++; - } + if (!ret && pos < max) + goto found_slot; if (!ret && start == min) ret = -BCH_ERR_ENOSPC_inode_create; @@ -713,11 +698,6 @@ found_slot: return ret; } - /* We may have raced while the iterator wasn't pointing at pos: */ - if (bkey_is_inode(k.k) || - bch2_btree_key_cache_find(c, BTREE_ID_inodes, k.k->p)) - goto again; - *hint = k.k->p.offset; inode_u->bi_inum = k.k->p.offset; inode_u->bi_generation = bkey_generation(k); diff --git a/fs/bcachefs/super.c b/fs/bcachefs/super.c index 30818e838814..f474f2f298ac 100644 --- a/fs/bcachefs/super.c +++ b/fs/bcachefs/super.c @@ -743,9 +743,6 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts) bch2_opts_apply(&c->opts, opts); - /* key cache currently disabled for inodes, because of snapshots: */ - c->opts.inodes_use_key_cache = 0; - c->btree_key_cache_btrees |= 1U << BTREE_ID_alloc; if (c->opts.inodes_use_key_cache) c->btree_key_cache_btrees |= 1U << BTREE_ID_inodes; -- cgit v1.2.3