From a0cb8d784f309d22323974e47b103bf01d0b62c0 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Sun, 17 Jul 2022 20:22:30 -0400 Subject: [PATCH] bcachefs: Inject transaction restarts in debug mode In CONFIG_BCACHEFS_DEBUG mode, we'll now randomly issue transaction restarts - with a decaying probability based on the number of restarts we've already had, to ensure that transactions eventually make forward progress. This should help shake out some bugs. Signed-off-by: Kent Overstreet Signed-off-by: Kent Overstreet --- fs/bcachefs/btree_iter.c | 11 +++++++++++ fs/bcachefs/trace.h | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/fs/bcachefs/btree_iter.c b/fs/bcachefs/btree_iter.c index db247c96298f4..777e41a122462 100644 --- a/fs/bcachefs/btree_iter.c +++ b/fs/bcachefs/btree_iter.c @@ -17,6 +17,7 @@ #include "subvolume.h" #include "trace.h" +#include #include static inline void btree_path_list_remove(struct btree_trans *, struct btree_path *); @@ -1660,6 +1661,16 @@ out: int __must_check bch2_btree_path_traverse(struct btree_trans *trans, struct btree_path *path, unsigned flags) { + if (IS_ENABLED(CONFIG_BCACHEFS_DEBUG)) { + unsigned restart_probability_bits = 4 << min(trans->restart_count, 32U); + u64 max = ~(~0ULL << restart_probability_bits); + + if (!get_random_u32_below(max)) { + trace_transaction_restart_injected(trans->fn, _RET_IP_); + return btree_trans_restart(trans, BCH_ERR_transaction_restart_fault_inject); + } + } + if (path->uptodate < BTREE_ITER_NEED_RELOCK) return 0; diff --git a/fs/bcachefs/trace.h b/fs/bcachefs/trace.h index a52da91f279e6..1e9e93161509c 100644 --- a/fs/bcachefs/trace.h +++ b/fs/bcachefs/trace.h @@ -707,6 +707,12 @@ DEFINE_EVENT(transaction_event, transaction_restart_ip, TP_ARGS(trans_fn, caller_ip) ); +DEFINE_EVENT(transaction_event, transaction_restart_injected, + TP_PROTO(const char *trans_fn, + unsigned long caller_ip), + TP_ARGS(trans_fn, caller_ip) +); + DEFINE_EVENT(transaction_event, trans_blocked_journal_reclaim, TP_PROTO(const char *trans_fn, unsigned long caller_ip), -- 2.30.2