Skip to content

Commit

Permalink
jbd2: rename j_maxlen to j_total_len and add jbd2_journal_max_txn_bufs
Browse files Browse the repository at this point in the history
The on-disk superblock field sb->s_maxlen represents the total size of
the journal including the fast commit area and is no more the max
number of blocks available for a transaction. The maximum number of
blocks available to a transaction is reduced by the number of fast
commit blocks. So, this patch renames j_maxlen to j_total_len to
better represent its intent. Also, it adds a function to calculate max
number of bufs available for a transaction.

Suggested-by: Jan Kara <[email protected]>
Signed-off-by: Harshad Shirwadkar <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Theodore Ts'o <[email protected]>
  • Loading branch information
harshadjs authored and tytso committed Nov 7, 2020
1 parent a80f7fc commit ede7dc7
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion fs/ext4/fsmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ static int ext4_getfsmap_logdev(struct super_block *sb, struct ext4_fsmap *keys,

/* Fabricate an rmap entry for the external log device. */
irec.fmr_physical = journal->j_blk_offset;
irec.fmr_length = journal->j_maxlen;
irec.fmr_length = journal->j_total_len;
irec.fmr_owner = EXT4_FMR_OWN_LOG;
irec.fmr_flags = 0;

Expand Down
2 changes: 1 addition & 1 deletion fs/ext4/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -3976,7 +3976,7 @@ int ext4_calculate_overhead(struct super_block *sb)
* loaded or not
*/
if (sbi->s_journal && !sbi->s_journal_bdev)
overhead += EXT4_NUM_B2C(sbi, sbi->s_journal->j_maxlen);
overhead += EXT4_NUM_B2C(sbi, sbi->s_journal->j_total_len);
else if (ext4_has_feature_journal(sb) && !sbi->s_journal && j_inum) {
/* j_inum for internal journal is non-zero */
j_inode = ext4_get_journal_inode(sb, j_inum);
Expand Down
2 changes: 1 addition & 1 deletion fs/jbd2/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)
if (first_block < journal->j_tail)
freed += journal->j_last - journal->j_first;
/* Update tail only if we free significant amount of space */
if (freed < journal->j_maxlen / 4)
if (freed < jbd2_journal_get_max_txn_bufs(journal))
update_tail = 0;
}
J_ASSERT(commit_transaction->t_state == T_COMMIT);
Expand Down
12 changes: 6 additions & 6 deletions fs/jbd2/journal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,7 @@ static journal_t *journal_init_common(struct block_device *bdev,
journal->j_dev = bdev;
journal->j_fs_dev = fs_dev;
journal->j_blk_offset = start;
journal->j_maxlen = len;
journal->j_total_len = len;
/* We need enough buffers to write out full descriptor block. */
n = journal->j_blocksize / jbd2_min_tag_size();
journal->j_wbufsize = n;
Expand Down Expand Up @@ -1531,7 +1531,7 @@ static int journal_reset(journal_t *journal)
journal->j_commit_sequence = journal->j_transaction_sequence - 1;
journal->j_commit_request = journal->j_commit_sequence;

journal->j_max_transaction_buffers = journal->j_maxlen / 4;
journal->j_max_transaction_buffers = jbd2_journal_get_max_txn_bufs(journal);

/*
* As a special case, if the on-disk copy is already marked as needing
Expand Down Expand Up @@ -1792,15 +1792,15 @@ static int journal_get_superblock(journal_t *journal)
goto out;
}

if (be32_to_cpu(sb->s_maxlen) < journal->j_maxlen)
journal->j_maxlen = be32_to_cpu(sb->s_maxlen);
else if (be32_to_cpu(sb->s_maxlen) > journal->j_maxlen) {
if (be32_to_cpu(sb->s_maxlen) < journal->j_total_len)
journal->j_total_len = be32_to_cpu(sb->s_maxlen);
else if (be32_to_cpu(sb->s_maxlen) > journal->j_total_len) {
printk(KERN_WARNING "JBD2: journal file too short\n");
goto out;
}

if (be32_to_cpu(sb->s_first) == 0 ||
be32_to_cpu(sb->s_first) >= journal->j_maxlen) {
be32_to_cpu(sb->s_first) >= journal->j_total_len) {
printk(KERN_WARNING
"JBD2: Invalid start block of journal: %u\n",
be32_to_cpu(sb->s_first));
Expand Down
6 changes: 3 additions & 3 deletions fs/jbd2/recovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ static int do_readahead(journal_t *journal, unsigned int start)

/* Do up to 128K of readahead */
max = start + (128 * 1024 / journal->j_blocksize);
if (max > journal->j_maxlen)
max = journal->j_maxlen;
if (max > journal->j_total_len)
max = journal->j_total_len;

/* Do the readahead itself. We'll submit MAXBUF buffer_heads at
* a time to the block device IO layer. */
Expand Down Expand Up @@ -134,7 +134,7 @@ static int jread(struct buffer_head **bhp, journal_t *journal,

*bhp = NULL;

if (offset >= journal->j_maxlen) {
if (offset >= journal->j_total_len) {
printk(KERN_ERR "JBD2: corrupted journal superblock\n");
return -EFSCORRUPTED;
}
Expand Down
2 changes: 1 addition & 1 deletion fs/ocfs2/journal.c
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ int ocfs2_journal_init(struct ocfs2_journal *journal, int *dirty)
goto done;
}

trace_ocfs2_journal_init_maxlen(j_journal->j_maxlen);
trace_ocfs2_journal_init_maxlen(j_journal->j_total_len);

*dirty = (le32_to_cpu(di->id1.journal1.ij_flags) &
OCFS2_JOURNAL_DIRTY_FL);
Expand Down
9 changes: 7 additions & 2 deletions include/linux/jbd2.h
Original file line number Diff line number Diff line change
Expand Up @@ -988,9 +988,9 @@ struct journal_s
struct block_device *j_fs_dev;

/**
* @j_maxlen: Total maximum capacity of the journal region on disk.
* @j_total_len: Total maximum capacity of the journal region on disk.
*/
unsigned int j_maxlen;
unsigned int j_total_len;

/**
* @j_reserved_credits:
Expand Down Expand Up @@ -1624,6 +1624,11 @@ int jbd2_wait_inode_data(journal_t *journal, struct jbd2_inode *jinode);
int jbd2_fc_wait_bufs(journal_t *journal, int num_blks);
int jbd2_fc_release_bufs(journal_t *journal);

static inline int jbd2_journal_get_max_txn_bufs(journal_t *journal)
{
return (journal->j_total_len - journal->j_fc_wbufsize) / 4;
}

/*
* is_journal_abort
*
Expand Down

0 comments on commit ede7dc7

Please sign in to comment.