From 084d42bbd67c5b2de607f56a94c7295459b16b61 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Tue, 23 Nov 2021 19:00:23 -0500 Subject: [PATCH] bcachefs: Apply workaround for too many btree iters to read path Reading from cached data, which calls bch2_bucket_io_time_reset(), is leading to transaction iterator overflows - this standardizes the workaround. Signed-off-by: Kent Overstreet --- fs/bcachefs/btree_iter.h | 8 +++++++- fs/bcachefs/dirent.c | 5 ++--- fs/bcachefs/fs-io.c | 4 ++++ fs/bcachefs/io.c | 4 ++++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/fs/bcachefs/btree_iter.h b/fs/bcachefs/btree_iter.h index 72b9605cf3e7..af1922c448ed 100644 --- a/fs/bcachefs/btree_iter.h +++ b/fs/bcachefs/btree_iter.h @@ -328,13 +328,19 @@ static inline struct bkey_s_c __bch2_btree_iter_peek(struct btree_iter *iter, : bch2_btree_iter_peek(iter); } +static inline int btree_trans_too_many_iters(struct btree_trans *trans) +{ + return hweight64(trans->paths_allocated) > BTREE_ITER_MAX / 2 + ? -EINTR : 0; +} + static inline struct bkey_s_c __bch2_btree_iter_peek_and_restart(struct btree_trans *trans, struct btree_iter *iter, unsigned flags) { struct bkey_s_c k; - while ((hweight64(trans->paths_allocated) > BTREE_ITER_MAX / 2) || + while (btree_trans_too_many_iters(trans) || (k = __bch2_btree_iter_peek(iter, flags), bkey_err(k) == -EINTR)) bch2_trans_begin(trans); diff --git a/fs/bcachefs/dirent.c b/fs/bcachefs/dirent.c index 4dfcc955675b..fe4a85a6a8cb 100644 --- a/fs/bcachefs/dirent.c +++ b/fs/bcachefs/dirent.c @@ -531,10 +531,9 @@ retry: * read_target looks up subvolumes, we can overflow paths if the * directory has many subvolumes in it */ - if (hweight64(trans.paths_allocated) > BTREE_ITER_MAX / 2) { - ret = -EINTR; + ret = btree_trans_too_many_iters(&trans); + if (ret) break; - } } bch2_trans_iter_exit(&trans, &iter); err: diff --git a/fs/bcachefs/fs-io.c b/fs/bcachefs/fs-io.c index c014f10885dc..b36685ebba69 100644 --- a/fs/bcachefs/fs-io.c +++ b/fs/bcachefs/fs-io.c @@ -881,6 +881,10 @@ retry: swap(rbio->bio.bi_iter.bi_size, bytes); bio_advance(&rbio->bio, bytes); + + ret = btree_trans_too_many_iters(trans); + if (ret) + break; } err: bch2_trans_iter_exit(trans, &iter); diff --git a/fs/bcachefs/io.c b/fs/bcachefs/io.c index c5bd17f913f2..03bea2ddfb39 100644 --- a/fs/bcachefs/io.c +++ b/fs/bcachefs/io.c @@ -2395,6 +2395,10 @@ retry: swap(bvec_iter.bi_size, bytes); bio_advance_iter(&rbio->bio, &bvec_iter, bytes); + + ret = btree_trans_too_many_iters(&trans); + if (ret) + break; } err: bch2_trans_iter_exit(&trans, &iter);