Skip to content

Commit 9f11182

Browse files
zhangyi089tytso
authored andcommitted
ext4: add a hole extent entry in cache after punch
In order to cache hole extents in the extent status tree and keep the hole length as long as possible, re-add a hole entry to the cache just after punching a hole. Signed-off-by: Zhang Yi <[email protected]> Reviewed-by: Jan Kara <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 6430dea commit 9f11182

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

fs/ext4/inode.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4007,12 +4007,12 @@ int ext4_punch_hole(struct file *file, loff_t offset, loff_t length)
40074007

40084008
/* If there are blocks to remove, do it */
40094009
if (stop_block > first_block) {
4010+
ext4_lblk_t hole_len = stop_block - first_block;
40104011

40114012
down_write(&EXT4_I(inode)->i_data_sem);
40124013
ext4_discard_preallocations(inode);
40134014

4014-
ext4_es_remove_extent(inode, first_block,
4015-
stop_block - first_block);
4015+
ext4_es_remove_extent(inode, first_block, hole_len);
40164016

40174017
if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
40184018
ret = ext4_ext_remove_space(inode, first_block,
@@ -4021,6 +4021,8 @@ int ext4_punch_hole(struct file *file, loff_t offset, loff_t length)
40214021
ret = ext4_ind_remove_space(handle, inode, first_block,
40224022
stop_block);
40234023

4024+
ext4_es_insert_extent(inode, first_block, hole_len, ~0,
4025+
EXTENT_STATUS_HOLE);
40244026
up_write(&EXT4_I(inode)->i_data_sem);
40254027
}
40264028
ext4_fc_track_range(handle, inode, first_block, stop_block);

0 commit comments

Comments
 (0)