Commit a0cb8d78 authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

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: default avatarKent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 549d173c
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "subvolume.h" #include "subvolume.h"
#include "trace.h" #include "trace.h"
#include <linux/random.h>
#include <linux/prefetch.h> #include <linux/prefetch.h>
static inline void btree_path_list_remove(struct btree_trans *, struct btree_path *); static inline void btree_path_list_remove(struct btree_trans *, struct btree_path *);
...@@ -1660,6 +1661,16 @@ static int btree_path_traverse_one(struct btree_trans *trans, ...@@ -1660,6 +1661,16 @@ static int btree_path_traverse_one(struct btree_trans *trans,
int __must_check bch2_btree_path_traverse(struct btree_trans *trans, int __must_check bch2_btree_path_traverse(struct btree_trans *trans,
struct btree_path *path, unsigned flags) 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) if (path->uptodate < BTREE_ITER_NEED_RELOCK)
return 0; return 0;
......
...@@ -707,6 +707,12 @@ DEFINE_EVENT(transaction_event, transaction_restart_ip, ...@@ -707,6 +707,12 @@ DEFINE_EVENT(transaction_event, transaction_restart_ip,
TP_ARGS(trans_fn, caller_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, DEFINE_EVENT(transaction_event, trans_blocked_journal_reclaim,
TP_PROTO(const char *trans_fn, TP_PROTO(const char *trans_fn,
unsigned long caller_ip), unsigned long caller_ip),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment