From: Zhang Yi <yi.zhang@xxxxxxxxxx> In order to cache hole extents in the extent status tree and keep the hole continuity as much as possible, add a hole entry to the cache after punching a hole. It can reduce the 'hole' in some continuous hole extent entries. Signed-off-by: Zhang Yi <yi.zhang@xxxxxxxxxx> --- fs/ext4/ext4.h | 3 +++ fs/ext4/extents.c | 5 ++--- fs/ext4/inode.c | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 9418359b1d9d..c2ca28c6ec38 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -3681,6 +3681,9 @@ extern int ext4_convert_unwritten_io_end_vec(handle_t *handle, ext4_io_end_t *io_end); extern int ext4_map_blocks(handle_t *handle, struct inode *inode, struct ext4_map_blocks *map, int flags); +extern void ext4_ext_put_gap_in_cache(struct inode *inode, + ext4_lblk_t hole_start, + ext4_lblk_t hole_len); extern int ext4_ext_calc_credits_for_single_extent(struct inode *inode, int num, struct ext4_ext_path *path); diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 202c76996b62..52bad225e3c8 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -2275,9 +2275,8 @@ static ext4_lblk_t ext4_ext_determine_hole(struct inode *inode, * calculate boundaries of the gap that the requested block fits into * and cache this gap */ -static void -ext4_ext_put_gap_in_cache(struct inode *inode, ext4_lblk_t hole_start, - ext4_lblk_t hole_len) +void ext4_ext_put_gap_in_cache(struct inode *inode, ext4_lblk_t hole_start, + ext4_lblk_t hole_len) { struct extent_status es; diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 94e7b8500878..3908ce7f6fb8 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -4034,6 +4034,8 @@ int ext4_punch_hole(struct file *file, loff_t offset, loff_t length) ret = ext4_ind_remove_space(handle, inode, first_block, stop_block); + ext4_ext_put_gap_in_cache(inode, first_block, + stop_block - first_block); up_write(&EXT4_I(inode)->i_data_sem); } ext4_fc_track_range(handle, inode, first_block, stop_block); -- 2.39.2