bcachefs: Add an option for btree node mem ptr optimization
authorKent Overstreet <kent.overstreet@gmail.com>
Mon, 26 Jul 2021 19:52:41 +0000 (15:52 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:09 +0000 (17:09 -0400)
bch2_btree_node_ptr_v2 has a field for stashing a pointer to the in
memory btree node; this is safe because we clear this field when reading
in nodes from disk and we never free in memory btree nodes - but, we
have bug reports that indicate something might be faulty with this
optimization, so let's add an option for it.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
fs/bcachefs/btree_cache.c
fs/bcachefs/opts.h

index 6d5cf2a5a1590568bb83487aa46d689fc14cd4d8..818b8df063da83d6bd6e49e0b0ff1ce0a2701866 100644 (file)
@@ -767,9 +767,11 @@ struct btree *bch2_btree_node_get(struct btree_trans *trans, struct btree_iter *
 
        EBUG_ON(level >= BTREE_MAX_DEPTH);
 
-       b = btree_node_mem_ptr(k);
-       if (b)
-               goto lock_node;
+       if (c->opts.btree_node_mem_ptr_optimization) {
+               b = btree_node_mem_ptr(k);
+               if (b)
+                       goto lock_node;
+       }
 retry:
        b = btree_cache_find(bc, k);
        if (unlikely(!b)) {
@@ -902,9 +904,11 @@ struct btree *bch2_btree_node_get_noiter(struct bch_fs *c,
 
        EBUG_ON(level >= BTREE_MAX_DEPTH);
 
-       b = btree_node_mem_ptr(k);
-       if (b)
-               goto lock_node;
+       if (c->opts.btree_node_mem_ptr_optimization) {
+               b = btree_node_mem_ptr(k);
+               if (b)
+                       goto lock_node;
+       }
 retry:
        b = btree_cache_find(bc, k);
        if (unlikely(!b)) {
index 2cba0e137b58995c9016e034651de3da51779130..0799c9d2bee0e303a21140552d3aa98bda52a33f 100644 (file)
@@ -178,6 +178,11 @@ enum opt_type {
          OPT_BOOL(),                                                   \
          BCH_SB_INODES_USE_KEY_CACHE,  true,                           \
          NULL,         "Use the btree key cache for the inodes btree") \
+       x(btree_node_mem_ptr_optimization, u8,                          \
+         OPT_MOUNT|OPT_RUNTIME,                                        \
+         OPT_BOOL(),                                                   \
+         NO_SB_OPT,                    true,                           \
+         NULL,         "Stash pointer to in memory btree node in btree ptr")\
        x(gc_reserve_percent,           u8,                             \
          OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME,                             \
          OPT_UINT(5, 21),                                              \