From: Baokun Li Date: Fri, 21 Nov 2025 09:06:34 +0000 (+0800) Subject: ext4: make ext4_punch_hole() support large block size X-Git-Tag: v6.19-rc1~161^2~21 X-Git-Url: https://gentwo.org/gitweb/?a=commitdiff_plain;h=d37a7ddd3a384bd34f985273d6e776d3d50b0edd;p=linux%2F.git ext4: make ext4_punch_hole() support large block size When preparing for bs > ps support, clean up unnecessary PAGE_SIZE references in ext4_punch_hole(). Previously, when a hole extended beyond i_size, we aligned the hole end upwards to PAGE_SIZE to handle partial folio invalidation. Now that truncate_inode_pages_range() already handles partial folio invalidation correctly, this alignment is no longer required. However, to save pointless tail block zeroing, we still keep rounding up to the block size here. In addition, as Honza pointed out, when the hole end equals i_size, it should also be rounded up to the block size. This patch fixes that as well. Suggested-by: Jan Kara Signed-off-by: Baokun Li Reviewed-by: Zhang Yi Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo Message-ID: <20251121090654.631996-5-libaokun@huaweicloud.com> Signed-off-by: Theodore Ts'o --- diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index d232154cc14d..5cf392142c8c 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -4408,10 +4408,10 @@ int ext4_punch_hole(struct file *file, loff_t offset, loff_t length) /* * If the hole extends beyond i_size, set the hole to end after - * the page that contains i_size. + * the block that contains i_size to save pointless tail block zeroing. */ - if (end > inode->i_size) - end = round_up(inode->i_size, PAGE_SIZE); + if (end >= inode->i_size) + end = round_up(inode->i_size, sb->s_blocksize); if (end > max_end) end = max_end; length = end - offset;