From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 499432857C7 for ; Thu, 22 Jan 2026 09:14:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769073298; cv=none; b=BrEaWEE/qb6nGTsIH0I6yEZ/aUw+xIPKNAtRzBRh4ZFXv5YViFOMOpotTEoU9MV02cYLw0+DmHVU9Wq/3qej2MnmzVpaJ1pb1HyFlc6TQ2L2KNXWCg2mZYNk7crW8Cd4WUDKXEis9FWfYwMs0O8OWZcZPseEPStLFDAc3vSpgKw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769073298; c=relaxed/simple; bh=T8TOFgL9MIZVQG0T6OPEUQBPv/7tT5KWjY+sBkrwtHg=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=W8RltYvnig9Ee8AgU0v883mGxJ7CLGlxA2UoQL4si5hRlOx48ElJFnLXs7NiW5qClpzxP/nv9VcupbNzJHmf0s+4MtyWiCZ+lKroA8ONqUe/efVj+RFWRHrcwvmKv2WmQwMA5Z00BS6ESfwlYWLGwOZL2FDN3uxwk+Oaijd8kgQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iq0J8pKZ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iq0J8pKZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F291C116C6; Thu, 22 Jan 2026 09:14:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1769073297; bh=T8TOFgL9MIZVQG0T6OPEUQBPv/7tT5KWjY+sBkrwtHg=; h=Date:Cc:Subject:To:References:From:In-Reply-To:From; b=iq0J8pKZEIaHMJwc0I/0ugsJdup+WNFxKYPUyG8mUcYopDQW3Gjo8V6kJx0ecInpv VZM0cnHKbj490qC6VgncdeHnRATSzJGrU6HizEUsmaBiGyV5NivEg9KVFHRv5PJ4VE NMJ3sXgzAGCXU5I2mEKX9KQd6hDyoH5bklAeZ96lW/bCSShlCFlTbLaMB34uTJjrMN uoj5jYlUNTQk1Kua13qhCPDVJGl/p9N2FGYxT+SlZY0cFfMhJBkqxqaYyqm/8zisQo I4Ph+F7u4bvIZpn0FtYbKO58ffZanIKU0fns/2xA1y5me36XT1PylJYtLw2oC1NDwE juRv/tSEWEFhw== Message-ID: <8a00c027-d14d-44c8-9105-b385fabb37f2@kernel.org> Date: Thu, 22 Jan 2026 17:15:00 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: chao@kernel.org, Sungjong Seo , Sunmin Jeong Subject: Re: [PATCH RESEND] f2fs: optimize f2fs_overwrite_io() for f2fs_iomap_begin To: Yeongjin Gil , jaegeuk@kernel.org, jyh429@gmail.com, linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org References: <20260116102346.992546-1-youngjin.gil@samsung.com> Content-Language: en-US From: Chao Yu In-Reply-To: <20260116102346.992546-1-youngjin.gil@samsung.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 1/16/2026 6:23 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. > > Fixes: 351bc761338d ("f2fs: optimize f2fs DIO overwrites") > Reviewed-by: Sungjong Seo > Reviewed-by: Sunmin Jeong > Signed-off-by: Yeongjin Gil > --- > fs/f2fs/data.c | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) > > diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c > index 2e133a723b99..bfbd717e628a 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) Yeongjin, You may missed to add logic related to check_first parameter? Thanks, > { > struct f2fs_map_blocks map; > block_t last_lblk; > @@ -1877,6 +1878,11 @@ bool f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len) > 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 +4449,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);