bcachefs: Split out CONFIG_BCACHEFS_DEBUG_TRANSACTIONS

This puts the btree_transactions sysfs/debugfs file behind a separate
config option - it's highly useful, but not cheap enough to enable
permenantly.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2021-12-16 20:36:26 -05:00 committed by Kent Overstreet
parent 51c4e406aa
commit b84d42c31f
3 changed files with 23 additions and 19 deletions

View File

@ -35,6 +35,15 @@ config BCACHEFS_POSIX_ACL
depends on BCACHEFS_FS
select FS_POSIX_ACL
config BCACHEFS_DEBUG_TRANSACTIONS
bool "bcachefs runtime info"
depends on BCACHEFS_FS
default y
help
This makes the list of running btree transactions available in debugfs.
This is a highly useful debugging feature but does add a small amount of overhead.
config BCACHEFS_DEBUG
bool "bcachefs debugging"
depends on BCACHEFS_FS

View File

@ -364,19 +364,16 @@ bool __bch2_btree_node_lock(struct btree_trans *trans,
if (six_trylock_type(&b->c.lock, type))
return true;
#ifdef CONFIG_BCACHEFS_DEBUG
trans->locking_path_idx = path->idx;
trans->locking_pos = pos;
trans->locking_btree_id = path->btree_id;
trans->locking_level = level;
trans->locking = b;
#endif
ret = six_lock_type(&b->c.lock, type, should_sleep_fn, p) == 0;
#ifdef CONFIG_BCACHEFS_DEBUG
trans->locking = NULL;
#endif
if (ret)
bch2_time_stats_update(&trans->c->times[lock_to_time_stat(type)],
start_time);
@ -2822,12 +2819,12 @@ void bch2_trans_init(struct btree_trans *trans, struct bch_fs *c,
trans->srcu_idx = srcu_read_lock(&c->btree_trans_barrier);
#ifdef CONFIG_BCACHEFS_DEBUG
trans->pid = current->pid;
mutex_lock(&c->btree_trans_lock);
list_add(&trans->list, &c->btree_trans_list);
mutex_unlock(&c->btree_trans_lock);
#endif
if (IS_ENABLED(CONFIG_BCACHEFS_DEBUG_TRANSACTIONS)) {
trans->pid = current->pid;
mutex_lock(&c->btree_trans_lock);
list_add(&trans->list, &c->btree_trans_list);
mutex_unlock(&c->btree_trans_lock);
}
}
static void check_btree_paths_leaked(struct btree_trans *trans)
@ -2866,11 +2863,11 @@ void bch2_trans_exit(struct btree_trans *trans)
check_btree_paths_leaked(trans);
#ifdef CONFIG_BCACHEFS_DEBUG
mutex_lock(&c->btree_trans_lock);
list_del(&trans->list);
mutex_unlock(&c->btree_trans_lock);
#endif
if (IS_ENABLED(CONFIG_BCACHEFS_DEBUG_TRANSACTIONS)) {
mutex_lock(&c->btree_trans_lock);
list_del(&trans->list);
mutex_unlock(&c->btree_trans_lock);
}
srcu_read_unlock(&c->btree_trans_barrier, trans->srcu_idx);
@ -2914,7 +2911,7 @@ bch2_btree_path_node_to_text(struct printbuf *out,
bch2_bpos_to_text(out, btree_node_pos(_b, cached));
}
#ifdef CONFIG_BCACHEFS_DEBUG
#ifdef CONFIG_BCACHEFS_DEBUG_TRANSACTIONS
static bool trans_has_locks(struct btree_trans *trans)
{
struct btree_path *path;
@ -2928,7 +2925,7 @@ static bool trans_has_locks(struct btree_trans *trans)
void bch2_btree_trans_to_text(struct printbuf *out, struct bch_fs *c)
{
#ifdef CONFIG_BCACHEFS_DEBUG
#ifdef CONFIG_BCACHEFS_DEBUG_TRANSACTIONS
struct btree_trans *trans;
struct btree_path *path;
struct btree *b;

View File

@ -363,7 +363,6 @@ struct btree_trans_commit_hook {
struct btree_trans {
struct bch_fs *c;
#ifdef CONFIG_BCACHEFS_DEBUG
struct list_head list;
struct btree *locking;
unsigned locking_path_idx;
@ -371,7 +370,6 @@ struct btree_trans {
u8 locking_btree_id;
u8 locking_level;
pid_t pid;
#endif
unsigned long ip;
int srcu_idx;