Skip to contentSkip to conversation

f2fs: avoid unnecessary reads in f2fs_update_meta_block()

PATCH Applied Seongjae Jeong 4 participants 5 messages Oct 2 – Oct 14 F2FS file system

lore
Share & tools
lore
#0 lore raw

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
index 794e0d99fc7c..51858f64e43e 100644
@@ -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
maintainer
#1 lore raw
Quoted 25 lines · Seongjae Jeong

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 +0 -0
index 794e0d99fc7c..51858f64e43e 100644
@@ -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 -7
  	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);

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 -0
  	memcpy(cache_address(entry), src, F2FS_BLKSIZE(sbi));
  	f2fs_mark_cache_dirty(entry);
#2 lore raw
Quoted 40 lines · Chao Yu
Quoted 25 lines · Seongjae Jeong

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 +0 -0
index 794e0d99fc7c..51858f64e43e 100644
@@ -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 -7
      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);

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 -0
      memcpy(cache_address(entry), src, F2FS_BLKSIZE(sbi));
      f2fs_mark_cache_dirty(entry);
maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Seongjae Jeong
Quoted 9 lines · Seongjae Jeong

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().

Quoted 6 lines

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.

Thanks,

#4 lore raw
In reply to Seongjae Jeong
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() 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().

[...]

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