Skip to content

Commit 8f7d89f

Browse files
jankaratytso
authored andcommitted
jbd2: transaction reservation support
In some cases we cannot start a transaction because of locking constraints and passing started transaction into those places is not handy either because we could block transaction commit for too long. Transaction reservation is designed to solve these issues. It reserves a handle with given number of credits in the journal and the handle can be later attached to the running transaction without blocking on commit or checkpointing. Reserved handles do not block transaction commit in any way, they only reduce maximum size of the running transaction (because we have to always be prepared to accomodate request for attaching reserved handle). Signed-off-by: Jan Kara <[email protected]> Signed-off-by: "Theodore Ts'o" <[email protected]>
1 parent f29fad7 commit 8f7d89f

File tree

5 files changed

+273
-93
lines changed

5 files changed

+273
-93
lines changed

fs/ext4/ext4_jbd2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ handle_t *__ext4_journal_start_sb(struct super_block *sb, unsigned int line,
6262
ext4_abort(sb, "Detected aborted journal");
6363
return ERR_PTR(-EROFS);
6464
}
65-
return jbd2__journal_start(journal, nblocks, GFP_NOFS, type, line);
65+
return jbd2__journal_start(journal, nblocks, 0, GFP_NOFS, type, line);
6666
}
6767

6868
int __ext4_journal_stop(const char *where, unsigned int line, handle_t *handle)

fs/jbd2/commit.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,12 @@ void jbd2_journal_commit_transaction(journal_t *journal)
523523
*/
524524
jbd2_journal_switch_revoke_table(journal);
525525

526+
/*
527+
* Reserved credits cannot be claimed anymore, free them
528+
*/
529+
atomic_sub(atomic_read(&journal->j_reserved_credits),
530+
&commit_transaction->t_outstanding_credits);
531+
526532
trace_jbd2_commit_flushing(journal, commit_transaction);
527533
stats.run.rs_flushing = jiffies;
528534
stats.run.rs_locked = jbd2_time_diff(stats.run.rs_locked,

fs/jbd2/journal.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,7 @@ static journal_t * journal_init_common (void)
10301030
init_waitqueue_head(&journal->j_wait_done_commit);
10311031
init_waitqueue_head(&journal->j_wait_commit);
10321032
init_waitqueue_head(&journal->j_wait_updates);
1033+
init_waitqueue_head(&journal->j_wait_reserved);
10331034
mutex_init(&journal->j_barrier);
10341035
mutex_init(&journal->j_checkpoint_mutex);
10351036
spin_lock_init(&journal->j_revoke_lock);
@@ -1039,6 +1040,7 @@ static journal_t * journal_init_common (void)
10391040
journal->j_commit_interval = (HZ * JBD2_DEFAULT_MAX_COMMIT_AGE);
10401041
journal->j_min_batch_time = 0;
10411042
journal->j_max_batch_time = 15000; /* 15ms */
1043+
atomic_set(&journal->j_reserved_credits, 0);
10421044

10431045
/* The journal is marked for error until we succeed with recovery! */
10441046
journal->j_flags = JBD2_ABORT;

0 commit comments

Comments
 (0)