From: Nikita Ofitserov <himi...@gmail.com>

Skip reading unnecessary leaf btree nodes unless running fsck.
For example, this should speed up version upgrade/downgrade when
rebuilding accounting information.

Signed-off-by: Nikita Ofitserov <himi...@gmail.com>
---
 fs/bcachefs/btree_gc.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/fs/bcachefs/btree_gc.c b/fs/bcachefs/btree_gc.c
index 
b89e12a3112868f175d028ce9745c8b4944ca747..c04e88ec5c0ac73c21f01db597b19d1b0c798299
 100644
--- a/fs/bcachefs/btree_gc.c
+++ b/fs/bcachefs/btree_gc.c
@@ -793,8 +793,21 @@ static int bch2_gc_btrees(struct bch_fs *c)
                if (IS_ERR_OR_NULL(bch2_btree_id_root(c, btree)->b))
                        continue;
 
-               /* We need to make sure every leaf node is readable before 
going RW */
-               ret = bch2_gc_btree(trans, &progress, btree, 0, true);
+
+               unsigned target_depth = BIT_ULL(btree) & 
btree_leaf_has_triggers_mask ? 0 : 1;
+
+               /*
+                * In fsck, we need to make sure every leaf node is readable
+                * before going RW, otherwise we can no longer rewind inside
+                * btree_lost_data to repair during the current fsck run.
+                *
+                * Otherwise, we can delay the repair to the next
+                * mount or offline fsck.
+                */
+               if (test_bit(BCH_FS_in_fsck, &c->flags))
+                       target_depth = 0;
+
+               ret = bch2_gc_btree(trans, &progress, btree, target_depth, 
true);
        }
 
        bch_err_fn(c, ret);

-- 
2.50.1



Reply via email to