Skip to content

Commit 6a66a7d

Browse files
zhangyi089tytso
authored andcommitted
jbd2: move the clearing of b_modified flag to the journal_unmap_buffer()
There is no need to delay the clearing of b_modified flag to the transaction committing time when unmapping the journalled buffer, so just move it to the journal_unmap_buffer(). Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Jan Kara <[email protected]> Signed-off-by: zhangyi (F) <[email protected]> Signed-off-by: Theodore Ts'o <[email protected]> Cc: [email protected]
1 parent af133ad commit 6a66a7d

File tree

2 files changed

+21
-32
lines changed

2 files changed

+21
-32
lines changed

fs/jbd2/commit.c

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -976,34 +976,21 @@ void jbd2_journal_commit_transaction(journal_t *journal)
976976
* it. */
977977

978978
/*
979-
* A buffer which has been freed while still being journaled by
980-
* a previous transaction.
981-
*/
982-
if (buffer_freed(bh)) {
983-
/*
984-
* If the running transaction is the one containing
985-
* "add to orphan" operation (b_next_transaction !=
986-
* NULL), we have to wait for that transaction to
987-
* commit before we can really get rid of the buffer.
988-
* So just clear b_modified to not confuse transaction
989-
* credit accounting and refile the buffer to
990-
* BJ_Forget of the running transaction. If the just
991-
* committed transaction contains "add to orphan"
992-
* operation, we can completely invalidate the buffer
993-
* now. We are rather through in that since the
994-
* buffer may be still accessible when blocksize <
995-
* pagesize and it is attached to the last partial
996-
* page.
997-
*/
998-
jh->b_modified = 0;
999-
if (!jh->b_next_transaction) {
1000-
clear_buffer_freed(bh);
1001-
clear_buffer_jbddirty(bh);
1002-
clear_buffer_mapped(bh);
1003-
clear_buffer_new(bh);
1004-
clear_buffer_req(bh);
1005-
bh->b_bdev = NULL;
1006-
}
979+
* A buffer which has been freed while still being journaled
980+
* by a previous transaction, refile the buffer to BJ_Forget of
981+
* the running transaction. If the just committed transaction
982+
* contains "add to orphan" operation, we can completely
983+
* invalidate the buffer now. We are rather through in that
984+
* since the buffer may be still accessible when blocksize <
985+
* pagesize and it is attached to the last partial page.
986+
*/
987+
if (buffer_freed(bh) && !jh->b_next_transaction) {
988+
clear_buffer_freed(bh);
989+
clear_buffer_jbddirty(bh);
990+
clear_buffer_mapped(bh);
991+
clear_buffer_new(bh);
992+
clear_buffer_req(bh);
993+
bh->b_bdev = NULL;
1007994
}
1008995

1009996
if (buffer_jbddirty(bh)) {

fs/jbd2/transaction.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2329,14 +2329,16 @@ static int journal_unmap_buffer(journal_t *journal, struct buffer_head *bh,
23292329
return -EBUSY;
23302330
}
23312331
/*
2332-
* OK, buffer won't be reachable after truncate. We just set
2333-
* j_next_transaction to the running transaction (if there is
2334-
* one) and mark buffer as freed so that commit code knows it
2335-
* should clear dirty bits when it is done with the buffer.
2332+
* OK, buffer won't be reachable after truncate. We just clear
2333+
* b_modified to not confuse transaction credit accounting, and
2334+
* set j_next_transaction to the running transaction (if there
2335+
* is one) and mark buffer as freed so that commit code knows
2336+
* it should clear dirty bits when it is done with the buffer.
23362337
*/
23372338
set_buffer_freed(bh);
23382339
if (journal->j_running_transaction && buffer_jbddirty(bh))
23392340
jh->b_next_transaction = journal->j_running_transaction;
2341+
jh->b_modified = 0;
23402342
spin_unlock(&journal->j_list_lock);
23412343
spin_unlock(&jh->b_state_lock);
23422344
write_unlock(&journal->j_state_lock);

0 commit comments

Comments
 (0)