Skip to content

Commit

Permalink
jbd2: optimize jbd2_journal_force_commit
Browse files Browse the repository at this point in the history
Current implementation of jbd2_journal_force_commit() is suboptimal because
result in empty and useless commits. But callers just want to force and wait
any unfinished commits. We already have jbd2_journal_force_commit_nested()
which does exactly what we want, except we are guaranteed that we do not hold
journal transaction open.

Signed-off-by: Dmitry Monakhov <[email protected]>
Signed-off-by: "Theodore Ts'o" <[email protected]>
Signed-off-by: franciscofranco <[email protected]>
Signed-off-by: flar2 <[email protected]>
  • Loading branch information
mrg666 authored and SuperHanss committed Mar 5, 2015
1 parent 3839aec commit 742f11d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 38 deletions.
62 changes: 48 additions & 14 deletions fs/jbd2/journal.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,20 +518,17 @@ int jbd2_log_start_commit(journal_t *journal, tid_t tid)
}

/*
* Force and wait upon a commit if the calling process is not within
* transaction. This is used for forcing out undo-protected data which contains
* bitmaps, when the fs is running out of space.
*
* We can only force the running transaction if we don't have an active handle;
* otherwise, we will deadlock.
*
* Returns true if a transaction was started.
* Force and wait any uncommitted transactions. We can only force the running
* transaction if we don't have an active handle, otherwise, we will deadlock.
* Returns: <0 in case of error,
* 0 if nothing to commit,
* 1 if transaction was successfully committed.
*/
int jbd2_journal_force_commit_nested(journal_t *journal)
static int __jbd2_journal_force_commit(journal_t *journal)
{
transaction_t *transaction = NULL;
tid_t tid;
int need_to_start = 0;
int need_to_start = 0, ret = 0;

read_lock(&journal->j_state_lock);
if (journal->j_running_transaction && !current->journal_info) {
Expand All @@ -542,16 +539,53 @@ int jbd2_journal_force_commit_nested(journal_t *journal)
transaction = journal->j_committing_transaction;

if (!transaction) {
/* Nothing to commit */
read_unlock(&journal->j_state_lock);
return 0; /* Nothing to retry */
return 0;
}

tid = transaction->t_tid;
read_unlock(&journal->j_state_lock);
if (need_to_start)
jbd2_log_start_commit(journal, tid);
jbd2_log_wait_commit(journal, tid);
return 1;
ret = jbd2_log_wait_commit(journal, tid);
if (!ret)
ret = 1;

return ret;
}

/**
* Force and wait upon a commit if the calling process is not within
* transaction. This is used for forcing out undo-protected data which contains
* bitmaps, when the fs is running out of space.
*
* @journal: journal to force
* Returns true if progress was made.
*/
int jbd2_journal_force_commit_nested(journal_t *journal)
{
int ret;

ret = __jbd2_journal_force_commit(journal);
return ret > 0;
}

/**
* int journal_force_commit() - force any uncommitted transactions
* @journal: journal to force
*
* Caller want unconditional commit. We can only force the running transaction
* if we don't have an active handle, otherwise, we will deadlock.
*/
int jbd2_journal_force_commit(journal_t *journal)
{
int ret;

J_ASSERT(!current->journal_info);
ret = __jbd2_journal_force_commit(journal);
if (ret > 0)
ret = 0;
return ret;
}

/*
Expand Down
23 changes: 0 additions & 23 deletions fs/jbd2/transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -1496,29 +1496,6 @@ int jbd2_journal_stop(handle_t *handle)
return err;
}

/**
* int jbd2_journal_force_commit() - force any uncommitted transactions
* @journal: journal to force
*
* For synchronous operations: force any uncommitted transactions
* to disk. May seem kludgy, but it reuses all the handle batching
* code in a very simple manner.
*/
int jbd2_journal_force_commit(journal_t *journal)
{
handle_t *handle;
int ret;

handle = jbd2_journal_start(journal, 1);
if (IS_ERR(handle)) {
ret = PTR_ERR(handle);
} else {
handle->h_sync = 1;
ret = jbd2_journal_stop(handle);
}
return ret;
}

/*
*
* List management code snippets: various functions for manipulating the
Expand Down
2 changes: 1 addition & 1 deletion include/linux/jbd2.h
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,7 @@ extern void jbd2_journal_ack_err (journal_t *);
extern int jbd2_journal_clear_err (journal_t *);
extern int jbd2_journal_bmap(journal_t *, unsigned long, unsigned long long *);
extern int jbd2_journal_force_commit(journal_t *);
extern int jbd2_journal_force_commit_nested(journal_t *);
extern int jbd2_journal_file_inode(handle_t *handle, struct jbd2_inode *inode);
extern int jbd2_journal_begin_ordered_truncate(journal_t *journal,
struct jbd2_inode *inode, loff_t new_size);
Expand Down Expand Up @@ -1174,7 +1175,6 @@ int __jbd2_log_space_left(journal_t *); /* Called with journal locked */
int jbd2_log_start_commit(journal_t *journal, tid_t tid);
int __jbd2_log_start_commit(journal_t *journal, tid_t tid);
int jbd2_journal_start_commit(journal_t *journal, tid_t *tid);
int jbd2_journal_force_commit_nested(journal_t *journal);
int jbd2_log_wait_commit(journal_t *journal, tid_t tid);
int jbd2_log_do_checkpoint(journal_t *journal);
int jbd2_trans_will_send_data_barrier(journal_t *journal, tid_t tid);
Expand Down

0 comments on commit 742f11d

Please sign in to comment.