All of lore.kernel.org
 help / color / mirror / Atom feed
From: fdmanana@kernel.org
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 09/28] btrfs: tracepoints: trace transaction states during commit phase
Date: Fri, 15 May 2026 18:00:06 +0100	[thread overview]
Message-ID: <bfa4e4e87bf05561027d559620dd15949b280d45.1778776707.git.fdmanana@suse.com> (raw)
In-Reply-To: <cover.1778776706.git.fdmanana@suse.com>

From: Filipe Manana <fdmanana@suse.com>

Currently the trace event is fired only when a transaction is fully
complete (its state is TRANS_STATE_COMPLETED). However during a
transaction commit we go through several states and as soon as the
state reaches TRANS_STATE_UNBLOCKED, another transaction can start.
Therefore it's useful to track every transaction state changed during
the commit of a transaction, so that we can see if a new transaction
is started before the current one is completed. Add the transaction
state to the transaction commit event and call the event everytime
we change the transaction state during commit.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 fs/btrfs/transaction.c       |  8 ++++++--
 include/trace/events/btrfs.h | 17 +++++++++++++++--
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 9ff8792d7182..aef2462b25d8 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -2321,6 +2321,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
 	}
 
 	cur_trans->state = TRANS_STATE_COMMIT_PREP;
+	trace_btrfs_transaction_commit(trans);
 	wake_up(&fs_info->transaction_blocked_wait);
 	btrfs_trans_state_lockdep_release(fs_info, BTRFS_LOCKDEP_TRANS_COMMIT_PREP);
 
@@ -2359,6 +2360,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
 	}
 
 	cur_trans->state = TRANS_STATE_COMMIT_START;
+	trace_btrfs_transaction_commit(trans);
 	wake_up(&fs_info->transaction_blocked_wait);
 	spin_unlock(&fs_info->trans_lock);
 
@@ -2414,6 +2416,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
 	spin_lock(&fs_info->trans_lock);
 	add_pending_snapshot(trans);
 	cur_trans->state = TRANS_STATE_COMMIT_DOING;
+	trace_btrfs_transaction_commit(trans);
 	spin_unlock(&fs_info->trans_lock);
 
 	/*
@@ -2562,6 +2565,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
 
 	spin_lock(&fs_info->trans_lock);
 	cur_trans->state = TRANS_STATE_UNBLOCKED;
+	trace_btrfs_transaction_commit(trans);
 	fs_info->running_transaction = NULL;
 	spin_unlock(&fs_info->trans_lock);
 	mutex_unlock(&fs_info->reloc_mutex);
@@ -2604,6 +2608,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
 	 * which can change it.
 	 */
 	cur_trans->state = TRANS_STATE_SUPER_COMMITTED;
+	trace_btrfs_transaction_commit(trans);
 	wake_up(&cur_trans->commit_wait);
 	btrfs_trans_state_lockdep_release(fs_info, BTRFS_LOCKDEP_TRANS_SUPER_COMMITTED);
 
@@ -2620,6 +2625,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
 	 * which can change it.
 	 */
 	cur_trans->state = TRANS_STATE_COMPLETED;
+	trace_btrfs_transaction_commit(trans);
 	wake_up(&cur_trans->commit_wait);
 	btrfs_trans_state_lockdep_release(fs_info, BTRFS_LOCKDEP_TRANS_COMPLETED);
 
@@ -2633,8 +2639,6 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
 	if (trans->type & __TRANS_FREEZABLE)
 		sb_end_intwrite(fs_info->sb);
 
-	trace_btrfs_transaction_commit(trans);
-
 	btrfs_scrub_continue(fs_info);
 
 	if (current->journal_info == trans)
diff --git a/include/trace/events/btrfs.h b/include/trace/events/btrfs.h
index e43528003848..801f4793e002 100644
--- a/include/trace/events/btrfs.h
+++ b/include/trace/events/btrfs.h
@@ -105,6 +105,15 @@ struct btrfs_transaction;
 	EM( COMMIT_TRANS,		"COMMIT_TRANS")			\
 	EMe(RESET_ZONES,		"RESET_ZONES")
 
+#define TRANSACTION_STATES							\
+	EM( TRANS_STATE_RUNNING,		"TRANS_STATE_RUNNING")		\
+	EM( TRANS_STATE_COMMIT_PREP,		"TRANS_STATE_COMMIT_PREP")	\
+	EM( TRANS_STATE_COMMIT_START,		"TRANS_STATE_COMMIT_START")	\
+	EM( TRANS_STATE_COMMIT_DOING,		"TRANS_STATE_COMMIT_DOING")	\
+	EM( TRANS_STATE_UNBLOCKED,		"TRANS_STATE_UNBLOCKED")	\
+	EM( TRANS_STATE_SUPER_COMMITTED,	"TRANS_STATE_SUPER_COMMITTED")	\
+	EMe(TRANS_STATE_COMPLETED,		"TRANS_STATE_COMPLETED")
+
 /*
  * First define the enums in the above macros to be exported to userspace via
  * TRACE_DEFINE_ENUM().
@@ -120,6 +129,7 @@ FI_TYPES
 QGROUP_RSV_TYPES
 IO_TREE_OWNER
 FLUSH_STATES
+TRANSACTION_STATES
 
 /*
  * Now redefine the EM and EMe macros to map the enums to the strings that will
@@ -208,15 +218,18 @@ TRACE_EVENT(btrfs_transaction_commit,
 	TP_STRUCT__entry_btrfs(
 		__field(	u64,  generation		)
 		__field(	bool, in_fsync			)
+		__field(	int,  state			)
 	),
 
 	TP_fast_assign_btrfs(trans->fs_info,
 		__entry->generation	= trans->transid;
 		__entry->in_fsync	= trans->in_fsync;
+		__entry->state		= trans->transaction->state;
 	),
 
-	TP_printk_btrfs("gen=%llu in_fsync=%d", __entry->generation,
-			__entry->in_fsync)
+	TP_printk_btrfs("gen=%llu in_fsync=%d state=%d(%s)", __entry->generation,
+			__entry->in_fsync, __entry->state,
+			__print_symbolic(__entry->state, TRANSACTION_STATES))
 );
 
 TRACE_EVENT(btrfs_transaction_abort,
-- 
2.47.2


  parent reply	other threads:[~2026-05-15 17:00 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-15 16:59 [PATCH 00/28] btrfs: add trace events for fsync and inode logging fdmanana
2026-05-15 16:59 ` [PATCH 01/28] btrfs: tracepoints: remove double negation in finish ordered extent event fdmanana
2026-05-15 16:59 ` [PATCH 02/28] btrfs: tracepoints: remove pointless root field from transaction commit event fdmanana
2026-05-15 17:00 ` [PATCH 03/28] btrfs: remove call to transaction commit trace in warn_about_uncommitted_trans() fdmanana
2026-05-15 17:00 ` [PATCH 04/28] btrfs: remove call to transaction commit trace in btrfs_cleanup_transaction() fdmanana
2026-05-15 17:00 ` [PATCH 05/28] btrfs: tracepoints: pass a transaction handle to transaction commit event fdmanana
2026-05-15 17:00 ` [PATCH 06/28] btrfs: tracepoints: add in_fsync field " fdmanana
2026-05-15 17:00 ` [PATCH 07/28] btrfs: tracepoints: add trace event for transaction aborts fdmanana
2026-05-15 17:00 ` [PATCH 08/28] btrfs: tracepoints: add trace event for the start of a new transaction fdmanana
2026-05-15 17:00 ` fdmanana [this message]
2026-05-15 17:00 ` [PATCH 10/28] btrfs: stop checking for greater then zero return values in btrfs_sync_file() fdmanana
2026-05-15 17:00 ` [PATCH 11/28] btrfs: remove redundant writeback error check during fsync fdmanana
2026-05-15 17:00 ` [PATCH 12/28] btrfs: tracepoints: add trace event for when fsync finishes fdmanana
2026-05-15 17:00 ` [PATCH 13/28] btrfs: tracepoints: add trace event for btrfs_log_inode_parent() fdmanana
2026-05-15 17:00 ` [PATCH 14/28] btrfs: use a named enum for the log mode in inode log functions fdmanana
2026-05-15 17:00 ` [PATCH 15/28] btrfs: tracepoints: add trace event for btrfs_log_inode() fdmanana
2026-05-15 17:00 ` [PATCH 16/28] btrfs: tracepoints: add trace event for btrfs_log_all_parents() fdmanana
2026-05-15 17:00 ` [PATCH 17/28] btrfs: tracepoints: add trace event for log_all_new_ancestors() fdmanana
2026-05-15 17:00 ` [PATCH 18/28] btrfs: tracepoints: add trace event for log_new_dir_dentries() fdmanana
2026-05-15 17:00 ` [PATCH 19/28] btrfs: tracepoints: add trace event for add_conflicting_inode() fdmanana
2026-05-15 17:00 ` [PATCH 20/28] btrfs: tracepoints: add trace event for log_conflicting_inodes() fdmanana
2026-05-15 17:00 ` [PATCH 21/28] btrfs: use simple assertions where enough during inode logging and replay fdmanana
2026-05-15 17:00 ` [PATCH 22/28] btrfs: tracepoints: add trace event for log_new_delayed_dentries() fdmanana
2026-05-15 17:00 ` [PATCH 23/28] btrfs: tracepoints: add trace event for btrfs_record_unlink_dir() fdmanana
2026-05-15 17:00 ` [PATCH 24/28] btrfs: tracepoints: add trace event for btrfs_record_snapshot_destroy() fdmanana
2026-05-15 17:00 ` [PATCH 25/28] btrfs: tracepoints: add trace event for btrfs_record_new_subvolume() fdmanana
2026-05-15 17:00 ` [PATCH 26/28] btrfs: tracepoints: add trace event for btrfs_log_new_name() fdmanana
2026-05-15 17:00 ` [PATCH 27/28] btrfs: tracepoints: add trace event for btrfs_sync_log() fdmanana
2026-05-15 17:00 ` [PATCH 28/28] btrfs: tracepoints: show inode type in btrfs_sync_file_enter() event fdmanana

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bfa4e4e87bf05561027d559620dd15949b280d45.1778776707.git.fdmanana@suse.com \
    --to=fdmanana@kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.