bcachefs: Reduce would_deadlock restarts
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 11 Jan 2024 04:47:04 +0000 (23:47 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 21 Jan 2024 11:01:45 +0000 (06:01 -0500)
We don't have to take locks in any particular ordering - we'll make
forward progress just fine - but if we try to stick to an ordering, it
can help to avoid excessive would_deadlock transaction restarts.

This tweaks the reflink path to take extents btree locks in the right
order.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/reflink.c

index 607010917421047d77415b7effeb0eacf7a363de..98255aa64e2261c504ebe0686c46b89589c36a6a 100644 (file)
@@ -486,6 +486,13 @@ s64 bch2_remap_range(struct bch_fs *c,
 
                bch2_btree_iter_set_snapshot(&dst_iter, dst_snapshot);
 
+               if (dst_inum.inum < src_inum.inum) {
+                       /* Avoid some lock cycle transaction restarts */
+                       ret = bch2_btree_iter_traverse(&dst_iter);
+                       if (ret)
+                               continue;
+               }
+
                dst_done = dst_iter.pos.offset - dst_start.offset;
                src_want = POS(src_start.inode, src_start.offset + dst_done);
                bch2_btree_iter_set_pos(&src_iter, src_want);