public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Chao Yu <chao@kernel.org>
To: Yeongjin Gil <youngjin.gil@samsung.com>,
	jaegeuk@kernel.org, jyh429@gmail.com,
	linux-f2fs-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org
Cc: chao@kernel.org, Sungjong Seo <sj1557.seo@samsung.com>,
	Sunmin Jeong <s_min.jeong@samsung.com>
Subject: Re: [PATCH v2] f2fs: optimize f2fs_overwrite_io() for f2fs_iomap_begin
Date: Fri, 23 Jan 2026 12:07:04 +0800	[thread overview]
Message-ID: <02ef4102-f143-4939-b3db-71dbaf74b5b7@kernel.org> (raw)
In-Reply-To: <20260122104527.416871-1-youngjin.gil@samsung.com>

On 1/22/2026 6:45 PM, Yeongjin Gil wrote:
> When overwriting already allocated blocks, f2fs_iomap_begin() calls
> f2fs_overwrite_io() to check block mappings. However,
> f2fs_overwrite_io() iterates through all mapped blocks in the range,
> which can be inefficient for fragmented files with large I/O requests.
> 
> This patch optimizes f2fs_overwrite_io() by adding a 'check_first'
> parameter and introducing __f2fs_overwrite_io() helper. When called from
> f2fs_iomap_begin(), we only check the first mapping to determine if the
> range is already allocated, which is sufficient for setting
> map.m_may_create.
> 
> This optimization significantly reduces the number of f2fs_map_blocks()
> calls in f2fs_overwrite_io() when called from f2fs_iomap_begin(),
> especially for fragmented files with large I/O requests.
> 

Cc: stable@kernel.org

> Fixes: 351bc761338d ("f2fs: optimize f2fs DIO overwrites")
> Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>
> Reviewed-by: Sunmin Jeong <s_min.jeong@samsung.com>
> Signed-off-by: Yeongjin Gil <youngjin.gil@samsung.com>

Otherwise, it looks good to me.

Reviewed-by: Chao Yu <chao@kernel.org>

Thanks,

> ---
>   fs/f2fs/data.c | 12 ++++++++++--
>   1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> index 2e133a723b99..11c262afad65 100644
> --- a/fs/f2fs/data.c
> +++ b/fs/f2fs/data.c
> @@ -1851,7 +1851,8 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag)
>   	return err;
>   }
>   
> -bool f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len)
> +static bool __f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len,
> +				bool check_first)
>   {
>   	struct f2fs_map_blocks map;
>   	block_t last_lblk;
> @@ -1873,10 +1874,17 @@ bool f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len)
>   		if (err || map.m_len == 0)
>   			return false;
>   		map.m_lblk += map.m_len;
> +		if (check_first)
> +			break;
>   	}
>   	return true;
>   }
>   
> +bool f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len)
> +{
> +	return __f2fs_overwrite_io(inode, pos, len, false);
> +}
> +
>   static int f2fs_xattr_fiemap(struct inode *inode,
>   				struct fiemap_extent_info *fieinfo)
>   {
> @@ -4443,7 +4451,7 @@ static int f2fs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
>   	 * f2fs_map_lock and f2fs_balance_fs are not necessary.
>   	 */
>   	if ((flags & IOMAP_WRITE) &&
> -		!f2fs_overwrite_io(inode, offset, length))
> +		!__f2fs_overwrite_io(inode, offset, length, true))
>   		map.m_may_create = true;
>   
>   	err = f2fs_map_blocks(inode, &map, F2FS_GET_BLOCK_DIO);


  reply	other threads:[~2026-01-23  4:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20260122104529epcas1p4ea35d60de87ef7ed53c5a02b0ce921b2@epcas1p4.samsung.com>
2026-01-22 10:45 ` [PATCH v2] f2fs: optimize f2fs_overwrite_io() for f2fs_iomap_begin Yeongjin Gil
2026-01-23  4:07   ` Chao Yu [this message]
2026-02-10 21:28   ` [f2fs-dev] " patchwork-bot+f2fs

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=02ef4102-f143-4939-b3db-71dbaf74b5b7@kernel.org \
    --to=chao@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=jyh429@gmail.com \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=s_min.jeong@samsung.com \
    --cc=sj1557.seo@samsung.com \
    --cc=youngjin.gil@samsung.com \
    /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