Skip to content

Commit bbbf150

Browse files
zhangyi089tytso
authored andcommitted
ext4: reserved credits for one extent during the folio writeback
After ext4 supports large folios, reserving journal credits for one maximum-ordered folio based on the worst case cenario during the writeback process can easily exceed the maximum transaction credits. Additionally, reserving journal credits for one page is also no longer appropriate. Currently, the folio writeback process can either extend the journal credits or initiate a new transaction if the currently reserved journal credits are insufficient. Therefore, it can be modified to reserve credits for only one extent at the outset. In most cases involving continuous mapping, these credits are generally adequate, and we may only need to perform some basic credit expansion. However, in extreme cases where the block size and folio size differ significantly, or when the folios are sufficiently discontinuous, it may be necessary to restart a new transaction and resubmit the folios. Suggested-by: Jan Kara <jack@suse.cz> Signed-off-by: Zhang Yi <yi.zhang@huawei.com> Reviewed-by: Jan Kara <jack@suse.cz> Link: https://patch.msgid.link/20250707140814.542883-9-yi.zhang@huaweicloud.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 95ad8ee commit bbbf150

1 file changed

Lines changed: 8 additions & 17 deletions

File tree

fs/ext4/inode.c

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,21 +2545,6 @@ static int mpage_map_and_submit_extent(handle_t *handle,
25452545
return err;
25462546
}
25472547

2548-
/*
2549-
* Calculate the total number of credits to reserve for one writepages
2550-
* iteration. This is called from ext4_writepages(). We map an extent of
2551-
* up to MAX_WRITEPAGES_EXTENT_LEN blocks and then we go on and finish mapping
2552-
* the last partial page. So in total we can map MAX_WRITEPAGES_EXTENT_LEN +
2553-
* bpp - 1 blocks in bpp different extents.
2554-
*/
2555-
static int ext4_da_writepages_trans_blocks(struct inode *inode)
2556-
{
2557-
int bpp = ext4_journal_blocks_per_folio(inode);
2558-
2559-
return ext4_meta_trans_blocks(inode,
2560-
MAX_WRITEPAGES_EXTENT_LEN + bpp - 1, bpp);
2561-
}
2562-
25632548
static int ext4_journal_folio_buffers(handle_t *handle, struct folio *folio,
25642549
size_t len)
25652550
{
@@ -2916,8 +2901,14 @@ static int ext4_do_writepages(struct mpage_da_data *mpd)
29162901
* not supported by delalloc.
29172902
*/
29182903
BUG_ON(ext4_should_journal_data(inode));
2919-
needed_blocks = ext4_da_writepages_trans_blocks(inode);
2920-
2904+
/*
2905+
* Calculate the number of credits needed to reserve for one
2906+
* extent of up to MAX_WRITEPAGES_EXTENT_LEN blocks. It will
2907+
* attempt to extend the transaction or start a new iteration
2908+
* if the reserved credits are insufficient.
2909+
*/
2910+
needed_blocks = ext4_chunk_trans_blocks(inode,
2911+
MAX_WRITEPAGES_EXTENT_LEN);
29212912
/* start a new transaction */
29222913
handle = ext4_journal_start_with_reserve(inode,
29232914
EXT4_HT_WRITE_PAGE, needed_blocks, rsv_blocks);

0 commit comments

Comments
 (0)