* [PATCH 1/2] btrfs: transaction: Add comment for btrfs transaction lifespan
@ 2019-08-22 7:24 Qu Wenruo
2019-08-22 7:25 ` [PATCH 2/2] btrfs: transaction: Cleanup unused TRANS_STATE_BLOCKED Qu Wenruo
2019-10-02 13:11 ` [PATCH 1/2] btrfs: transaction: Add comment for btrfs transaction lifespan David Sterba
0 siblings, 2 replies; 4+ messages in thread
From: Qu Wenruo @ 2019-08-22 7:24 UTC (permalink / raw)
To: linux-btrfs
Just a overview of the basic btrfs transaction lifespan, including the
following states:
- No transaction states
- Transaction N [[TRANS_STATE_RUNNING]]
- Transaction N [[TRANS_STATE_COMMIT_START]]
- Transaction N [[TRANS_STATE_COMMIT_DOING]]
- Transaction N [[TRANS_STATE_UNBLOCKED]]
- Transaction N [[TRANS_STATE_COMPLETED]]
For each states, the comment will include:
- Basic explaination about current state
- How to go next stage
- What will happen if we call variant start_transaction() functions
- Relationship to transaction N+1
This doesn't provide much tech details, but just a cheat sheet for
reader to get into the code a little easier.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/transaction.c | 70 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 70 insertions(+)
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index e3adb714c04b..6568eca28b43 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -22,6 +22,76 @@
#define BTRFS_ROOT_TRANS_TAG 0
+/*
+ * About btrfs transaction lifespan.
+ *
+ * No running transaction (fs tree blocks are not modified)
+ * |
+ * | To next stage:
+ * | Call start_transaction() variants. Except btrfs_join_transaction_nostart().
+ * V
+ * Transaction N [[TRANS_STATE_RUNNING]]
+ * |
+ * | New trans handles can be attached to transaction N by calling all
+ * | start_transaction() variants.
+ * |
+ * | To next stage:
+ * | Call btrfs_commit_transaction() on any trans handler attached to
+ * | transaction N
+ * V
+ * Transaction N [[TRANS_STATE_COMMIT_START]]
+ * |
+ * | Will wait previous running transaction to completely finish if we have.
+ * |
+ * | Then either:
+ * | - Wait all other trans handler holder to release.
+ * | This btrfs_commit_transaction() caller will do the commit work.
+ * | - Wait current transaction to be committed by others.
+ * | Other btrfs_commit_transaction() caller will do the commit work.
+ * |
+ * | At this stage, only btrfs_join_transaction*() variants can attach
+ * | to this running transaction.
+ * | All other variants will wait current one to finish and attach to
+ * | transaction N+1.
+ * |
+ * | To next stage:
+ * | Caller is chosen to commit transaction N, and all other trans handlers
+ * | haven been release.
+ * V
+ * Transaction N [[TRANS_STATE_COMMIT_DOING]]
+ * |
+ * | Heavy lift transaction is started.
+ * | From running delayed refs (modifying extent tree) to creating pending
+ * | snapshots, running qgroups.
+ * | In short, modify supporting trees to reflect modifications of subvolume
+ * | trees.
+ * |
+ * | At this stage, all start_transaction() calls will wait this transaction
+ * | to finish and attach to transaction N+1.
+ * |
+ * | To next stage:
+ * | Until all supporting trees are updated.
+ * V
+ * Transaction N [[TRANS_STATE_UNBLOCKED]]
+ * | Transaction N+1
+ * | All needed trees are modified, thus only [[TRANS_STATE_RUNNING]]
+ * | need to write them back to disk and update |
+ * | super blocks. |
+ * | |
+ * | At this stage, new transaction is allowed to |
+ * | start. |
+ * | All new start_transaction() calls will be |
+ * | attached to transid N+1. |
+ * | |
+ * | To next stage: |
+ * | Until all tree blocks are super blocks are |
+ * | written to block device(s) |
+ * V |
+ * Transaction N [[TRANS_STATE_COMPLETED]] V
+ * All tree blocks and super blocks are written. Transaction N+1
+ * This transaction is finished and all its [[TRANS_STATE_COMMIT_START]]
+ * data structures will be cleaned up. | Life goes on
+ */
static const unsigned int btrfs_blocked_trans_types[TRANS_STATE_MAX] = {
[TRANS_STATE_RUNNING] = 0U,
[TRANS_STATE_BLOCKED] = __TRANS_START,
--
2.23.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] btrfs: transaction: Cleanup unused TRANS_STATE_BLOCKED
2019-08-22 7:24 [PATCH 1/2] btrfs: transaction: Add comment for btrfs transaction lifespan Qu Wenruo
@ 2019-08-22 7:25 ` Qu Wenruo
2019-10-02 13:10 ` David Sterba
2019-10-02 13:11 ` [PATCH 1/2] btrfs: transaction: Add comment for btrfs transaction lifespan David Sterba
1 sibling, 1 reply; 4+ messages in thread
From: Qu Wenruo @ 2019-08-22 7:25 UTC (permalink / raw)
To: linux-btrfs
The state is introduced in commit 4a9d8bdee368 ("Btrfs: make the state
of the transaction more readable"), then in commit 302167c50b32
("btrfs: don't end the transaction for delayed refs in throttle") the
state is completely removed.
So we can just clean up the state since it's only compared but never
set.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/disk-io.c | 2 +-
fs/btrfs/transaction.c | 15 +++------------
fs/btrfs/transaction.h | 1 -
3 files changed, 4 insertions(+), 14 deletions(-)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 97beb351a10c..3866cca4ae5d 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1771,7 +1771,7 @@ static int transaction_kthread(void *arg)
}
now = ktime_get_seconds();
- if (cur->state < TRANS_STATE_BLOCKED &&
+ if (cur->state < TRANS_STATE_COMMIT_START &&
!test_bit(BTRFS_FS_NEED_ASYNC_COMMIT, &fs_info->flags) &&
(now < cur->start_time ||
now - cur->start_time < fs_info->commit_interval)) {
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 6568eca28b43..bfd946427f80 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -94,7 +94,6 @@
*/
static const unsigned int btrfs_blocked_trans_types[TRANS_STATE_MAX] = {
[TRANS_STATE_RUNNING] = 0U,
- [TRANS_STATE_BLOCKED] = __TRANS_START,
[TRANS_STATE_COMMIT_START] = (__TRANS_START | __TRANS_ATTACH),
[TRANS_STATE_COMMIT_DOING] = (__TRANS_START |
__TRANS_ATTACH |
@@ -451,7 +450,7 @@ int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans,
static inline int is_transaction_blocked(struct btrfs_transaction *trans)
{
- return (trans->state >= TRANS_STATE_BLOCKED &&
+ return (trans->state >= TRANS_STATE_COMMIT_START &&
trans->state < TRANS_STATE_UNBLOCKED &&
!trans->aborted);
}
@@ -638,7 +637,7 @@ start_transaction(struct btrfs_root *root, unsigned int num_items,
INIT_LIST_HEAD(&h->new_bgs);
smp_mb();
- if (cur_trans->state >= TRANS_STATE_BLOCKED &&
+ if (cur_trans->state >= TRANS_STATE_COMMIT_START &&
may_wait_transaction(fs_info, type)) {
current->journal_info = h;
btrfs_commit_transaction(h);
@@ -866,7 +865,7 @@ int btrfs_should_end_transaction(struct btrfs_trans_handle *trans)
struct btrfs_transaction *cur_trans = trans->transaction;
smp_mb();
- if (cur_trans->state >= TRANS_STATE_BLOCKED ||
+ if (cur_trans->state >= TRANS_STATE_COMMIT_START ||
cur_trans->delayed_refs.flushing)
return 1;
@@ -899,7 +898,6 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
{
struct btrfs_fs_info *info = trans->fs_info;
struct btrfs_transaction *cur_trans = trans->transaction;
- int lock = (trans->type != TRANS_JOIN_NOLOCK);
int err = 0;
if (refcount_read(&trans->use_count) > 1) {
@@ -915,13 +913,6 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
btrfs_trans_release_chunk_metadata(trans);
- if (lock && READ_ONCE(cur_trans->state) == TRANS_STATE_BLOCKED) {
- if (throttle)
- return btrfs_commit_transaction(trans);
- else
- wake_up_process(info->transaction_kthread);
- }
-
if (trans->type & __TRANS_FREEZABLE)
sb_end_intwrite(info->sb);
diff --git a/fs/btrfs/transaction.h b/fs/btrfs/transaction.h
index 2c5a6f6e5bb0..78b339fbc44f 100644
--- a/fs/btrfs/transaction.h
+++ b/fs/btrfs/transaction.h
@@ -13,7 +13,6 @@
enum btrfs_trans_state {
TRANS_STATE_RUNNING,
- TRANS_STATE_BLOCKED,
TRANS_STATE_COMMIT_START,
TRANS_STATE_COMMIT_DOING,
TRANS_STATE_UNBLOCKED,
--
2.23.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] btrfs: transaction: Cleanup unused TRANS_STATE_BLOCKED
2019-08-22 7:25 ` [PATCH 2/2] btrfs: transaction: Cleanup unused TRANS_STATE_BLOCKED Qu Wenruo
@ 2019-10-02 13:10 ` David Sterba
0 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2019-10-02 13:10 UTC (permalink / raw)
To: Qu Wenruo; +Cc: linux-btrfs
On Thu, Aug 22, 2019 at 03:25:00PM +0800, Qu Wenruo wrote:
> The state is introduced in commit 4a9d8bdee368 ("Btrfs: make the state
> of the transaction more readable"), then in commit 302167c50b32
> ("btrfs: don't end the transaction for delayed refs in throttle") the
> state is completely removed.
>
> So we can just clean up the state since it's only compared but never
> set.
>
> Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] btrfs: transaction: Add comment for btrfs transaction lifespan
2019-08-22 7:24 [PATCH 1/2] btrfs: transaction: Add comment for btrfs transaction lifespan Qu Wenruo
2019-08-22 7:25 ` [PATCH 2/2] btrfs: transaction: Cleanup unused TRANS_STATE_BLOCKED Qu Wenruo
@ 2019-10-02 13:11 ` David Sterba
1 sibling, 0 replies; 4+ messages in thread
From: David Sterba @ 2019-10-02 13:11 UTC (permalink / raw)
To: Qu Wenruo; +Cc: linux-btrfs
On Thu, Aug 22, 2019 at 03:24:59PM +0800, Qu Wenruo wrote:
> Just a overview of the basic btrfs transaction lifespan, including the
> following states:
> - No transaction states
> - Transaction N [[TRANS_STATE_RUNNING]]
> - Transaction N [[TRANS_STATE_COMMIT_START]]
> - Transaction N [[TRANS_STATE_COMMIT_DOING]]
> - Transaction N [[TRANS_STATE_UNBLOCKED]]
> - Transaction N [[TRANS_STATE_COMPLETED]]
>
> For each states, the comment will include:
> - Basic explaination about current state
> - How to go next stage
> - What will happen if we call variant start_transaction() functions
> - Relationship to transaction N+1
>
> This doesn't provide much tech details, but just a cheat sheet for
> reader to get into the code a little easier.
>
> Signed-off-by: Qu Wenruo <wqu@suse.com>
Great, thanks.
Reviewed-by: David Sterba <dsterba@suse.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-10-02 13:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-22 7:24 [PATCH 1/2] btrfs: transaction: Add comment for btrfs transaction lifespan Qu Wenruo
2019-08-22 7:25 ` [PATCH 2/2] btrfs: transaction: Cleanup unused TRANS_STATE_BLOCKED Qu Wenruo
2019-10-02 13:10 ` David Sterba
2019-10-02 13:11 ` [PATCH 1/2] btrfs: transaction: Add comment for btrfs transaction lifespan David Sterba
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).