Skip to content

Commit 0415ae5

Browse files
YeongjinGilgregkh
authored andcommitted
f2fs: optimize f2fs_overwrite_io() for f2fs_iomap_begin
commit d860974 upstream. 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: 351bc76 ("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> Reviewed-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent fee27b6 commit 0415ae5

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

fs/f2fs/data.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,7 +1799,8 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag)
17991799
return err;
18001800
}
18011801

1802-
bool f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len)
1802+
static bool __f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len,
1803+
bool check_first)
18031804
{
18041805
struct f2fs_map_blocks map;
18051806
block_t last_lblk;
@@ -1821,10 +1822,17 @@ bool f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len)
18211822
if (err || map.m_len == 0)
18221823
return false;
18231824
map.m_lblk += map.m_len;
1825+
if (check_first)
1826+
break;
18241827
}
18251828
return true;
18261829
}
18271830

1831+
bool f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len)
1832+
{
1833+
return __f2fs_overwrite_io(inode, pos, len, false);
1834+
}
1835+
18281836
static int f2fs_xattr_fiemap(struct inode *inode,
18291837
struct fiemap_extent_info *fieinfo)
18301838
{
@@ -4191,7 +4199,7 @@ static int f2fs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
41914199
* f2fs_map_lock and f2fs_balance_fs are not necessary.
41924200
*/
41934201
if ((flags & IOMAP_WRITE) &&
4194-
!f2fs_overwrite_io(inode, offset, length))
4202+
!__f2fs_overwrite_io(inode, offset, length, true))
41954203
map.m_may_create = true;
41964204

41974205
err = f2fs_map_blocks(inode, &map, F2FS_GET_BLOCK_DIO);

0 commit comments

Comments
 (0)