Linux EXT4 FS development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ding Feng" <dingf3ng@gmail.com>
Cc: linux-ext4@vger.kernel.org, tytso@mit.edu
Subject: Re: [PATCH v2 2/2] ext4: punch hole beyond i_size
Date: Thu, 03 Dec 2026 12:22:40 +0000	[thread overview]
Message-ID: <sashiko-outbox-247711@kernel.org> (raw)
In-Reply-To: <20261203115201.48810-3-dingf3ng@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] ext4: ext4_punch_hole() drops EOF block round-up when end
  reaches i_size
--

commit fa94f38a0bf415aa375c8cc034c22fb0d79dfa23
Author: Ding Feng <dingf3ng@gmail.com>

ext4: punch hole beyond i_size

This commit updates ext4_punch_hole() to remove extents allocated beyond
i_size instead of returning early or stopping at the block containing
i_size, while restricting partial block zeroing to holes starting below
i_size.

> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 26cf00ff8630a..7f491a7237357 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
[ ... ]
> @@ -5371,19 +5372,16 @@ int ext4_punch_hole(struct file *file, loff_t offset, loff_t length)
>  	if (!ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
>  		max_end = EXT4_SB(sb)->s_bitmap_maxbytes - sb->s_blocksize;
>  
> -	/* No need to punch hole beyond i_size */
> -	if (offset >= inode->i_size || offset >= max_end)
> +	if (offset >= max_end)
>  		return 0;
> -
> -	/*
> -	 * If the hole extends beyond i_size, set the hole to end after
> -	 * the block that contains i_size to save pointless tail block zeroing.
> -	 */
> -	if (end >= inode->i_size)
> -		end = round_up(inode->i_size, sb->s_blocksize);
>  	if (end > max_end)
>  		end = max_end;
>  	length = end - offset;
> +	/*
> +	 * Blocks past i_size (from FALLOC_FL_KEEP_SIZE) are removed too, but
> +	 * nothing after the block that contains i_size needs zeroing.
> +	 */
> +	zero_end = min_t(loff_t, end, round_up(inode->i_size, sb->s_blocksize));
>  
>  	ret = ext4_update_disksize_before_punch(inode, offset, length);
>  	if (ret)
> @@ -5394,9 +5392,12 @@ int ext4_punch_hole(struct file *file, loff_t offset, loff_t length)
>  	if (ret)
>  		return ret;
>  
> -	ret = ext4_zero_partial_blocks(inode, offset, length, &partial_zeroed);
> -	if (ret)
> -		return ret;
> +	if (offset < inode->i_size) {
> +		ret = ext4_zero_partial_blocks(inode, offset, zero_end - offset,
> +					       &partial_zeroed);
> +		if (ret)
> +			return ret;
> +	}

[Severity: Medium]
Does removing the upward round-up of end regress EOF block reclamation and
reintroduce tail-block zeroing when end falls in
[i_size, round_up(i_size, sb->s_blocksize))?

The deleted check both clamped end downward and rounded it upward to the
end of the EOF block, which commit d37a7ddd3a38 ("ext4: make
ext4_punch_hole() support large block size") kept to free the EOF block
and avoid pointless tail-block zeroing.

With this change, punching [0, 5000) on a 5000-byte file with 4096-byte
blocks leaves both end and zero_end at 5000.  ext4_zero_partial_blocks()
then reads, zeros, and dirties the EOF block, and end_lblk excludes that
block so it stays allocated on disk instead of being freed.

If the same file is punched over [0, 6000), zero_end stays at 6000 and
ext4_zero_partial_blocks() also writes zeroes over [5000, 6000) past
i_size while leaving the EOF block allocated.

Preserving the upward round-up when end >= inode->i_size with
end = max_t(loff_t, end, round_up(inode->i_size, sb->s_blocksize)) before
clamping against max_end would still punch blocks past i_size without
regressing EOF block reclamation or tail-block zeroing.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203115201.48810-1-dingf3ng@gmail.com?part=2

  reply	other threads:[~2026-12-03 12:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 11:51 [PATCH v2 0/2] ext4: punch hole beyond i_size Ding Feng
2026-12-03 11:52 ` [PATCH v2 1/2] ext4: fix the fast commit range of a punched hole Ding Feng
2026-12-03 11:52 ` [PATCH v2 2/2] ext4: punch hole beyond i_size Ding Feng
2026-12-03 12:22   ` sashiko-bot [this message]
2026-12-03 12:22 ` [PATCH v2 0/2] " sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-247711@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dingf3ng@gmail.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox