diff --git a/fs/bcachefs/btree_iter.h b/fs/bcachefs/btree_iter.h index e58cad4b8fc6..16fa0fe1c5b7 100644 --- a/fs/bcachefs/btree_iter.h +++ b/fs/bcachefs/btree_iter.h @@ -329,8 +329,9 @@ __bch2_btree_iter_peek_and_restart(struct btree_trans *trans, { struct bkey_s_c k; - while (k = __bch2_btree_iter_peek(iter, flags), - bkey_err(k) == -EINTR) + while ((hweight64(trans->paths_allocated) > BTREE_ITER_MAX / 2) || + (k = __bch2_btree_iter_peek(iter, flags), + bkey_err(k) == -EINTR)) bch2_trans_begin(trans); return k;