From b84d42c31f34094c74d6306e11e3a0bc224c7575 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Thu, 16 Dec 2021 20:36:26 -0500 Subject: [PATCH] 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 --- fs/bcachefs/Kconfig | 9 +++++++++ fs/bcachefs/btree_iter.c | 31 ++++++++++++++----------------- fs/bcachefs/btree_types.h | 2 -- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/fs/bcachefs/Kconfig b/fs/bcachefs/Kconfig index bfe7e6c9c0649..d2eb65e9032b1 100644 --- a/fs/bcachefs/Kconfig +++ b/fs/bcachefs/Kconfig @@ -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 diff --git a/fs/bcachefs/btree_iter.c b/fs/bcachefs/btree_iter.c index 1ad81cad36f18..cc1dd788cdd57 100644 --- a/fs/bcachefs/btree_iter.c +++ b/fs/bcachefs/btree_iter.c @@ -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; diff --git a/fs/bcachefs/btree_types.h b/fs/bcachefs/btree_types.h index 25b0df22366bf..e1b417df4b73a 100644 --- a/fs/bcachefs/btree_types.h +++ b/fs/bcachefs/btree_types.h @@ -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; -- 2.30.2