Skip to content

Commit 19014d6

Browse files
jankaratytso
authored andcommitted
jbd2: Fine tune estimate of necessary descriptor blocks
Currently we reserve j_max_transaction_buffers / 32 for transaction descriptor blocks. Now that revoke descriptors are accounted for separately this estimate is unnecessarily high and we can actually compute much tighter estimate. In the common case of 32k journal blocks and 4k blocksize this actually reduces the amount of reserved descriptor blocks from 256 to ~25 which allows us to fit more real data into a transaction. Signed-off-by: Jan Kara <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 0094f98 commit 19014d6

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

fs/jbd2/transaction.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,25 @@ void jbd2_journal_free_transaction(transaction_t *transaction)
6363
}
6464

6565
/*
66-
* We reserve t_outstanding_credits >> JBD2_CONTROL_BLOCKS_SHIFT for
67-
* transaction descriptor blocks.
66+
* Base amount of descriptor blocks we reserve for each transaction.
6867
*/
69-
#define JBD2_CONTROL_BLOCKS_SHIFT 5
70-
7168
static int jbd2_descriptor_blocks_per_trans(journal_t *journal)
7269
{
73-
return journal->j_max_transaction_buffers >> JBD2_CONTROL_BLOCKS_SHIFT;
70+
int tag_space = journal->j_blocksize - sizeof(journal_header_t);
71+
int tags_per_block;
72+
73+
/* Subtract UUID */
74+
tag_space -= 16;
75+
if (jbd2_journal_has_csum_v2or3(journal))
76+
tag_space -= sizeof(struct jbd2_journal_block_tail);
77+
/* Commit code leaves a slack space of 16 bytes at the end of block */
78+
tags_per_block = (tag_space - 16) / journal_tag_bytes(journal);
79+
/*
80+
* Revoke descriptors are accounted separately so we need to reserve
81+
* space for commit block and normal transaction descriptor blocks.
82+
*/
83+
return 1 + DIV_ROUND_UP(journal->j_max_transaction_buffers,
84+
tags_per_block);
7485
}
7586

7687
/*

0 commit comments

Comments
 (0)