Skip to content

Commit

Permalink
jbd2: fix the way the b_modified flag is cleared
Browse files Browse the repository at this point in the history
Currently at the start of a journal commit we loop through all of the buffers
on the committing transaction and clear the b_modified flag (the flag that is
set when a transaction modifies the buffer) under the j_list_lock.

The problem is that everywhere else this flag is modified only under the jbd2
lock buffer flag, so it will race with a running transaction who could
potentially set it, and have it unset by the committing transaction.

This is also a big waste, you can have several thousands of buffers that you
are clearing the modified flag on when you may not need to.  This patch
removes this code and instead clears the b_modified flag upon entering
do_get_write_access/journal_get_create_access, so if that transaction does
indeed use the buffer then it will be accounted for properly, and if it does
not then we know we didn't use it.

That will be important for the next patch in this series.  Tested thoroughly
by myself using postmark/iozone/bonnie++.

Cc: <linux-ext4@vger.kernel.org>
Cc: Jan Kara <jack@ucw.cz>
Signed-off-by: Josef Bacik <jbacik@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
  • Loading branch information
Josef Bacik authored and Theodore Ts'o committed Apr 17, 2008
1 parent 33ae0cd commit 9fc7c63
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
16 changes: 0 additions & 16 deletions fs/jbd2/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,22 +519,6 @@ void jbd2_journal_commit_transaction(journal_t *journal)

jbd_debug (3, "JBD: commit phase 2\n");

/*
* First, drop modified flag: all accesses to the buffers
* will be tracked for a new trasaction only -bzzz
*/
spin_lock(&journal->j_list_lock);
if (commit_transaction->t_buffers) {
new_jh = jh = commit_transaction->t_buffers->b_tnext;
do {
J_ASSERT_JH(new_jh, new_jh->b_modified == 1 ||
new_jh->b_modified == 0);
new_jh->b_modified = 0;
new_jh = new_jh->b_tnext;
} while (new_jh != jh);
}
spin_unlock(&journal->j_list_lock);

/*
* Now start flushing things to disk, in the order they appear
* on the transaction lists. Data blocks go first.
Expand Down
13 changes: 13 additions & 0 deletions fs/jbd2/transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,12 @@ do_get_write_access(handle_t *handle, struct journal_head *jh,
jh->b_next_transaction == transaction)
goto done;

/*
* this is the first time this transaction is touching this buffer,
* reset the modified flag
*/
jh->b_modified = 0;

/*
* If there is already a copy-out version of this buffer, then we don't
* need to make another one
Expand Down Expand Up @@ -829,9 +835,16 @@ int jbd2_journal_get_create_access(handle_t *handle, struct buffer_head *bh)

if (jh->b_transaction == NULL) {
jh->b_transaction = transaction;

/* first access by this transaction */
jh->b_modified = 0;

JBUFFER_TRACE(jh, "file as BJ_Reserved");
__jbd2_journal_file_buffer(jh, transaction, BJ_Reserved);
} else if (jh->b_transaction == journal->j_committing_transaction) {
/* first access by this transaction */
jh->b_modified = 0;

JBUFFER_TRACE(jh, "set next transaction");
jh->b_next_transaction = transaction;
}
Expand Down

0 comments on commit 9fc7c63

Please sign in to comment.