Skip to content

Commit c2b2c7d

Browse files
author
Kent Overstreet
committed
bcachefs: Tweak btree cache helpers for use by btree node scan
btree node scan needs to not use the btree node cache: that causes interference from prior failed reads and parallel workers. Instead we need to allocate btree nodes that don't live in the btree cache, so that we can call bch2_btree_node_read_done() directly. This patch tweaks the low level helpers so they don't touch the btree cache lists. Cc: Nikita Ofitserov <[email protected]> Reviewed-by: Nikita Ofitserov <[email protected]> Reported-and-tested-by: Edoardo Codeglia <[email protected]> Signed-off-by: Kent Overstreet <[email protected]>
1 parent c72d628 commit c2b2c7d

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

fs/bcachefs/btree_cache.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ void bch2_btree_node_to_freelist(struct bch_fs *c, struct btree *b)
8585
six_unlock_intent(&b->c.lock);
8686
}
8787

88-
static void __btree_node_data_free(struct btree_cache *bc, struct btree *b)
88+
void __btree_node_data_free(struct btree *b)
8989
{
9090
BUG_ON(!list_empty(&b->list));
9191
BUG_ON(btree_node_hashed(b));
@@ -112,16 +112,17 @@ static void __btree_node_data_free(struct btree_cache *bc, struct btree *b)
112112
munmap(b->aux_data, btree_aux_data_bytes(b));
113113
#endif
114114
b->aux_data = NULL;
115-
116-
btree_node_to_freedlist(bc, b);
117115
}
118116

119117
static void btree_node_data_free(struct btree_cache *bc, struct btree *b)
120118
{
121119
BUG_ON(list_empty(&b->list));
122120
list_del_init(&b->list);
121+
122+
__btree_node_data_free(b);
123+
123124
--bc->nr_freeable;
124-
__btree_node_data_free(bc, b);
125+
btree_node_to_freedlist(bc, b);
125126
}
126127

127128
static int bch2_btree_cache_cmp_fn(struct rhashtable_compare_arg *arg,
@@ -185,10 +186,7 @@ static struct btree *__btree_node_mem_alloc(struct bch_fs *c, gfp_t gfp)
185186

186187
struct btree *__bch2_btree_node_mem_alloc(struct bch_fs *c)
187188
{
188-
struct btree_cache *bc = &c->btree_cache;
189-
struct btree *b;
190-
191-
b = __btree_node_mem_alloc(c, GFP_KERNEL);
189+
struct btree *b = __btree_node_mem_alloc(c, GFP_KERNEL);
192190
if (!b)
193191
return NULL;
194192

@@ -198,8 +196,6 @@ struct btree *__bch2_btree_node_mem_alloc(struct bch_fs *c)
198196
}
199197

200198
bch2_btree_lock_init(&b->c, 0, GFP_KERNEL);
201-
202-
__bch2_btree_node_to_freelist(bc, b);
203199
return b;
204200
}
205201

@@ -524,7 +520,8 @@ static unsigned long bch2_btree_cache_scan(struct shrinker *shrink,
524520
--touched;;
525521
} else if (!btree_node_reclaim(c, b)) {
526522
__bch2_btree_node_hash_remove(bc, b);
527-
__btree_node_data_free(bc, b);
523+
__btree_node_data_free(b);
524+
btree_node_to_freedlist(bc, b);
528525

529526
freed++;
530527
bc->nr_freed++;
@@ -652,9 +649,12 @@ int bch2_fs_btree_cache_init(struct bch_fs *c)
652649

653650
bch2_recalc_btree_reserve(c);
654651

655-
for (i = 0; i < bc->nr_reserve; i++)
656-
if (!__bch2_btree_node_mem_alloc(c))
652+
for (i = 0; i < bc->nr_reserve; i++) {
653+
struct btree *b = __bch2_btree_node_mem_alloc(c);
654+
if (!b)
657655
goto err;
656+
__bch2_btree_node_to_freelist(bc, b);
657+
}
658658

659659
list_splice_init(&bc->live[0].list, &bc->freeable);
660660

fs/bcachefs/btree_cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ void bch2_btree_node_update_key_early(struct btree_trans *, enum btree_id, unsig
3030
void bch2_btree_cache_cannibalize_unlock(struct btree_trans *);
3131
int bch2_btree_cache_cannibalize_lock(struct btree_trans *, struct closure *);
3232

33+
void __btree_node_data_free(struct btree *);
3334
struct btree *__bch2_btree_node_mem_alloc(struct bch_fs *);
3435
struct btree *bch2_btree_node_mem_alloc(struct btree_trans *, bool);
3536

fs/bcachefs/debug.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,6 @@ void __bch2_btree_verify(struct bch_fs *c, struct btree *b)
153153
c->verify_data = __bch2_btree_node_mem_alloc(c);
154154
if (!c->verify_data)
155155
goto out;
156-
157-
list_del_init(&c->verify_data->list);
158156
}
159157

160158
BUG_ON(b->nsets != 1);

0 commit comments

Comments
 (0)