add patch fix-fsync-error-handling-after-filesystem-abort
[ext4-patch-queue.git] / commit-as-soon-as-possible-after-log_start_commit
blob0e0cf638734fb0ba6728680e2a8485de7f6bd4ba
1 jbd2: commit as soon as possible after log_start_commit
3 Once a transaction has been requested to be committed, don't let any
4 other handles start under that transaction, and don't allow any
5 pending transactions to be extended (i.e., in the case of
6 unlink/ftruncate).
8 The idea is once the transaction has had log_start_commit() called on
9 it, at least one thread is blocked waiting for that transaction to
10 commit, and over time, more and more threads will end up getting
11 blocked.  In order to avoid high variability in file system operations
12 getting blocked behind the a blocked start_this_handle(), we should
13 try to get the commit started as soon as possible.
15 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
16 ---
17  fs/jbd2/transaction.c | 6 ++++--
18  1 file changed, 4 insertions(+), 2 deletions(-)
20 diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
21 index 735609e..434d525 100644
22 --- a/fs/jbd2/transaction.c
23 +++ b/fs/jbd2/transaction.c
24 @@ -225,7 +225,8 @@ repeat:
25          * If the current transaction is locked down for commit, wait for the
26          * lock to be released.
27          */
28 -       if (transaction->t_state == T_LOCKED) {
29 +       if (transaction->t_state == T_LOCKED ||
30 +           transaction->t_requested) {
31                 DEFINE_WAIT(wait);
33                 prepare_to_wait(&journal->j_wait_transaction_locked,
34 @@ -427,7 +428,8 @@ int jbd2_journal_extend(handle_t *handle, int nblocks)
35         read_lock(&journal->j_state_lock);
37         /* Don't extend a locked-down transaction! */
38 -       if (handle->h_transaction->t_state != T_RUNNING) {
39 +       if (handle->h_transaction->t_state != T_RUNNING ||
40 +           handle->h_transaction->t_requested) {
41                 jbd_debug(3, "denied handle %p %d blocks: "
42                           "transaction not running\n", handle, nblocks);
43                 goto error_out;