f2fs: avoid unnecessary reads in f2fs_update_meta_block()
PATCH 1/1 f2fs: avoid unnecessary reads in f2fs_update_meta_block()
When the packed SSA feature is enabled, f2fs_update_meta_block() uses f2fs_get_meta_cache_retry(), which reads the target block from disk if the cache entry is not uptodate.
However, f2fs_update_meta_block() overwrites the entire filesystem block with memcpy(), so the existing contents are not needed. Partial updates to packed SSA blocks are handled separately in write_sum_block().
Use f2fs_grab_meta_cache() unconditionally to avoid reading blocks that will be fully overwritten. Also remove the error check, since f2fs_grab_meta_cache() retries allocation failures internally and does not return an error pointer.
--- fs/f2fs/segment.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
fs/f2fs/segment.c +1 -7
@@ -2844,13 +2844,7 @@ void f2fs_update_meta_block(struct f2fs_sb_info *sbi, {struct f2fs_cached_block *entry; -if (!f2fs_sb_has_packed_ssa (sbi)) - entry =f2fs_grab_meta_cache (sbi, blk_addr); -else - entry =f2fs_get_meta_cache_retry (sbi, blk_addr); - -if (IS_ERR (entry)) -return ; + entry =f2fs_grab_meta_cache (sbi, blk_addr);memcpy (cache_address (entry), src,F2FS_BLKSIZE (sbi));f2fs_mark_cache_dirty (entry);
Signature · 1 line
2.53.0
Chao Yu
maintainerQuoted 25 lines · Seongjae Jeong
When the packed SSA feature is enabled,
f2fs_update_meta_block()usesf2fs_get_meta_cache_retry(), which reads the target block from disk if the cache entry is not uptodate.However,
f2fs_update_meta_block()overwrites the entire filesystem block withmemcpy(), so the existing contents are not needed. Partial updates to packed SSA blocks are handled separately inwrite_sum_block().Use
f2fs_grab_meta_cache()unconditionally to avoid reading blocks that will be fully overwritten. Also remove the error check, sincef2fs_grab_meta_cache()retries allocation failures internally and does not return an error pointer.Signed-off-by Seongjae Jeong <[email protected]>--- fs/f2fs/segment.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)fs/f2fs/segment.c +0
-0@@ -2844,13 +2844,7 @@ void f2fs_update_meta_block(struct f2fs_sb_info *sbi, {
fs/f2fs/segment.c void f2fs_update_meta_block(struct f2fs_sb_info *sbi, · line 2847
Quoted 10 lines
fs/f2fs/segment.c +1
-7struct f2fs_cached_block *entry; -if (!f2fs_sb_has_packed_ssa (sbi)) - entry =f2fs_grab_meta_cache (sbi, blk_addr); -else - entry =f2fs_get_meta_cache_retry (sbi, blk_addr); - -if (IS_ERR (entry)) -return ; + entry =f2fs_grab_meta_cache (sbi, blk_addr);
Daeho,
From code side, I feel this is clean.
But, could you double check this cleanup? in case if we handle this intentionally in original patch for something.
Thanks,
Quoted 3 lines
fs/f2fs/segment.c +0
-0memcpy (cache_address (entry), src,F2FS_BLKSIZE (sbi));f2fs_mark_cache_dirty (entry);
Quoted 40 lines · Chao Yu
Quoted 25 lines · Seongjae Jeong
When the packed SSA feature is enabled,
f2fs_update_meta_block()usesf2fs_get_meta_cache_retry(), which reads the target block from disk if the cache entry is not uptodate.However,
f2fs_update_meta_block()overwrites the entire filesystem block withmemcpy(), so the existing contents are not needed. Partial updates to packed SSA blocks are handled separately inwrite_sum_block().Use
f2fs_grab_meta_cache()unconditionally to avoid reading blocks that will be fully overwritten. Also remove the error check, sincef2fs_grab_meta_cache()retries allocation failures internally and does not return an error pointer.Signed-off-by Seongjae Jeong <[email protected]>--- fs/f2fs/segment.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)fs/f2fs/segment.c +0
-0@@ -2844,13 +2844,7 @@ void f2fs_update_meta_block(struct f2fs_sb_info *sbi, {fs/f2fs/segment.c void f2fs_update_meta_block(struct f2fs_sb_info *sbi, · line 2847
Quoted 10 lines
fs/f2fs/segment.c +1
-7struct f2fs_cached_block *entry; -if (!f2fs_sb_has_packed_ssa (sbi)) - entry =f2fs_grab_meta_cache (sbi, blk_addr); -else - entry =f2fs_get_meta_cache_retry (sbi, blk_addr); - -if (IS_ERR (entry)) -return ; + entry =f2fs_grab_meta_cache (sbi, blk_addr);Daeho,
Quoted 6 lines
From code side, I feel this is clean.
But, could you double check this cleanup? in case if we handle this intentionally in original patch for something.
Thanks,
Looks good to me. Thanks~
Quoted 5 lines
Quoted 4 lines
fs/f2fs/segment.c +0
-0memcpy (cache_address (entry), src,F2FS_BLKSIZE (sbi));f2fs_mark_cache_dirty (entry);
Quoted 9 lines · Seongjae Jeong
When the packed SSA feature is enabled,
f2fs_update_meta_block()usesf2fs_get_meta_cache_retry(), which reads the target block from disk if the cache entry is not uptodate.However,
f2fs_update_meta_block()overwrites the entire filesystem block withmemcpy(), so the existing contents are not needed. Partial updates to packed SSA blocks are handled separately inwrite_sum_block().
Quoted 6 lines
Use
f2fs_grab_meta_cache()unconditionally to avoid reading blocks that will be fully overwritten. Also remove the error check, sincef2fs_grab_meta_cache()retries allocation failures internally and does not return an error pointer.Signed-off-by Seongjae Jeong <[email protected]>
Thanks,
This patch was applied to jaegeuk/f2fs.git (dev) by Jaegeuk Kim <[email protected]>:
Hello:
This patch was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <[email protected]>:
Quoted 10 lines · On Fri, 2 Oct 2026 06:48:53 +0000 you wrote:
When the packed SSA feature is enabled,
f2fs_update_meta_block()usesf2fs_get_meta_cache_retry(), which reads the target block from disk if the cache entry is not uptodate.However,
f2fs_update_meta_block()overwrites the entire filesystem block withmemcpy(), so the existing contents are not needed. Partial updates to packed SSA blocks are handled separately inwrite_sum_block().[...]
Here is the summary with links:
- [f2fs-dev] f2fs: avoid unnecessary reads in f2fs_update_meta_block()
https://git.kernel.org/jaegeuk/f2fs/c/e8bc653c0d50
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html