Skip to content

Commit 3471c14

Browse files
zhangyi089gregkh
authored andcommitted
ext4: replace ext4_writepage_trans_blocks()
commit 57661f2 upstream. After ext4 supports large folios, the semantics of reserving credits in pages is no longer applicable. In most scenarios, reserving credits in extents is sufficient. Therefore, introduce ext4_chunk_trans_extent() to replace ext4_writepage_trans_blocks(). move_extent_per_page() is the only remaining location where we are still processing extents in pages. Suggested-by: Jan Kara <[email protected]> Signed-off-by: Zhang Yi <[email protected]> Reviewed-by: Jan Kara <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Theodore Ts'o <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 2e8216e commit 3471c14

6 files changed

Lines changed: 25 additions & 27 deletions

File tree

fs/ext4/ext4.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3064,9 +3064,9 @@ extern int ext4_punch_hole(struct file *file, loff_t offset, loff_t length);
30643064
extern void ext4_set_inode_flags(struct inode *, bool init);
30653065
extern int ext4_alloc_da_blocks(struct inode *inode);
30663066
extern void ext4_set_aops(struct inode *inode);
3067-
extern int ext4_writepage_trans_blocks(struct inode *);
30683067
extern int ext4_normal_submit_inode_data_buffers(struct jbd2_inode *jinode);
30693068
extern int ext4_chunk_trans_blocks(struct inode *, int nrblocks);
3069+
extern int ext4_chunk_trans_extent(struct inode *inode, int nrblocks);
30703070
extern int ext4_meta_trans_blocks(struct inode *inode, int lblocks,
30713071
int pextents);
30723072
extern int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode,

fs/ext4/extents.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5171,7 +5171,7 @@ ext4_ext_shift_path_extents(struct ext4_ext_path *path, ext4_lblk_t shift,
51715171
credits = depth + 2;
51725172
}
51735173

5174-
restart_credits = ext4_writepage_trans_blocks(inode);
5174+
restart_credits = ext4_chunk_trans_extent(inode, 0);
51755175
err = ext4_datasem_ensure_credits(handle, inode, credits,
51765176
restart_credits, 0);
51775177
if (err) {
@@ -5431,7 +5431,7 @@ static int ext4_collapse_range(struct file *file, loff_t offset, loff_t len)
54315431

54325432
truncate_pagecache(inode, start);
54335433

5434-
credits = ext4_writepage_trans_blocks(inode);
5434+
credits = ext4_chunk_trans_extent(inode, 0);
54355435
handle = ext4_journal_start(inode, EXT4_HT_TRUNCATE, credits);
54365436
if (IS_ERR(handle))
54375437
return PTR_ERR(handle);
@@ -5527,7 +5527,7 @@ static int ext4_insert_range(struct file *file, loff_t offset, loff_t len)
55275527

55285528
truncate_pagecache(inode, start);
55295529

5530-
credits = ext4_writepage_trans_blocks(inode);
5530+
credits = ext4_chunk_trans_extent(inode, 0);
55315531
handle = ext4_journal_start(inode, EXT4_HT_TRUNCATE, credits);
55325532
if (IS_ERR(handle))
55335533
return PTR_ERR(handle);

fs/ext4/inline.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping,
570570
return 0;
571571
}
572572

573-
needed_blocks = ext4_writepage_trans_blocks(inode);
573+
needed_blocks = ext4_chunk_trans_extent(inode, 1);
574574

575575
ret = ext4_get_inode_loc(inode, &iloc);
576576
if (ret)
@@ -1874,7 +1874,7 @@ int ext4_inline_data_truncate(struct inode *inode, int *has_inline)
18741874
};
18751875

18761876

1877-
needed_blocks = ext4_writepage_trans_blocks(inode);
1877+
needed_blocks = ext4_chunk_trans_extent(inode, 1);
18781878
handle = ext4_journal_start(inode, EXT4_HT_INODE, needed_blocks);
18791879
if (IS_ERR(handle))
18801880
return PTR_ERR(handle);
@@ -1994,7 +1994,7 @@ int ext4_convert_inline_data(struct inode *inode)
19941994
return 0;
19951995
}
19961996

1997-
needed_blocks = ext4_writepage_trans_blocks(inode);
1997+
needed_blocks = ext4_chunk_trans_extent(inode, 1);
19981998

19991999
iloc.bh = NULL;
20002000
error = ext4_get_inode_loc(inode, &iloc);

fs/ext4/inode.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,8 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping,
12961296
* Reserve one block more for addition to orphan list in case
12971297
* we allocate blocks but write fails for some reason
12981298
*/
1299-
needed_blocks = ext4_writepage_trans_blocks(inode) + 1;
1299+
needed_blocks = ext4_chunk_trans_extent(inode,
1300+
ext4_journal_blocks_per_folio(inode)) + 1;
13001301
index = pos >> PAGE_SHIFT;
13011302

13021303
if (ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA)) {
@@ -4464,7 +4465,7 @@ int ext4_punch_hole(struct file *file, loff_t offset, loff_t length)
44644465
return ret;
44654466

44664467
if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
4467-
credits = ext4_writepage_trans_blocks(inode);
4468+
credits = ext4_chunk_trans_extent(inode, 2);
44684469
else
44694470
credits = ext4_blocks_for_truncate(inode);
44704471
handle = ext4_journal_start(inode, EXT4_HT_TRUNCATE, credits);
@@ -4613,7 +4614,7 @@ int ext4_truncate(struct inode *inode)
46134614
}
46144615

46154616
if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
4616-
credits = ext4_writepage_trans_blocks(inode);
4617+
credits = ext4_chunk_trans_extent(inode, 1);
46174618
else
46184619
credits = ext4_blocks_for_truncate(inode);
46194620

@@ -6256,25 +6257,19 @@ int ext4_meta_trans_blocks(struct inode *inode, int lblocks, int pextents)
62566257
}
62576258

62586259
/*
6259-
* Calculate the total number of credits to reserve to fit
6260-
* the modification of a single pages into a single transaction,
6261-
* which may include multiple chunks of block allocations.
6262-
*
6263-
* This could be called via ext4_write_begin()
6264-
*
6265-
* We need to consider the worse case, when
6266-
* one new block per extent.
6260+
* Calculate the journal credits for modifying the number of blocks
6261+
* in a single extent within one transaction. 'nrblocks' is used only
6262+
* for non-extent inodes. For extent type inodes, 'nrblocks' can be
6263+
* zero if the exact number of blocks is unknown.
62676264
*/
6268-
int ext4_writepage_trans_blocks(struct inode *inode)
6265+
int ext4_chunk_trans_extent(struct inode *inode, int nrblocks)
62696266
{
6270-
int bpp = ext4_journal_blocks_per_folio(inode);
62716267
int ret;
62726268

6273-
ret = ext4_meta_trans_blocks(inode, bpp, bpp);
6274-
6269+
ret = ext4_meta_trans_blocks(inode, nrblocks, 1);
62756270
/* Account for data blocks for journalled mode */
62766271
if (ext4_should_journal_data(inode))
6277-
ret += bpp;
6272+
ret += nrblocks;
62786273
return ret;
62796274
}
62806275

@@ -6652,10 +6647,12 @@ static int ext4_block_page_mkwrite(struct inode *inode, struct folio *folio,
66526647
handle_t *handle;
66536648
loff_t size;
66546649
unsigned long len;
6650+
int credits;
66556651
int ret;
66566652

6657-
handle = ext4_journal_start(inode, EXT4_HT_WRITE_PAGE,
6658-
ext4_writepage_trans_blocks(inode));
6653+
credits = ext4_chunk_trans_extent(inode,
6654+
ext4_journal_blocks_per_folio(inode));
6655+
handle = ext4_journal_start(inode, EXT4_HT_WRITE_PAGE, credits);
66596656
if (IS_ERR(handle))
66606657
return PTR_ERR(handle);
66616658

fs/ext4/move_extent.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,8 @@ move_extent_per_page(struct file *o_filp, struct inode *donor_inode,
280280
*/
281281
again:
282282
*err = 0;
283-
jblocks = ext4_writepage_trans_blocks(orig_inode) * 2;
283+
jblocks = ext4_meta_trans_blocks(orig_inode, block_len_in_page,
284+
block_len_in_page) * 2;
284285
handle = ext4_journal_start(orig_inode, EXT4_HT_MOVE_EXTENTS, jblocks);
285286
if (IS_ERR(handle)) {
286287
*err = PTR_ERR(handle);

fs/ext4/xattr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ int __ext4_xattr_set_credits(struct super_block *sb, struct inode *inode,
962962
* so we need to reserve credits for this eventuality
963963
*/
964964
if (inode && ext4_has_inline_data(inode))
965-
credits += ext4_writepage_trans_blocks(inode) + 1;
965+
credits += ext4_chunk_trans_extent(inode, 1) + 1;
966966

967967
/* We are done if ea_inode feature is not enabled. */
968968
if (!ext4_has_feature_ea_inode(sb))

0 commit comments

Comments
 (0)