f2fs: force out-place update for all writes on compressed file
Subsystems (2)
PATCH 1/1 f2fs: force out-place update for all writes on compressed file
For compressed file, compressed write may fail and fall back to raw write.
-Thread A - Thread B
- f2fs_write_multi_pages - f2fs_down_write(&sbi->cp_rwsem);
- f2fs_write_compressed_pages - ...
- f2fs_trylock_op - ...
- f2fs_down_read_trylock(&sbi->cp_rwsem); - ...
- f2fs_write_raw_pages - ...Thread B acquires the lock first, which causes Thread A to fail lock acquisition and fall back to raw-data write.IPU_FORCE is enabled on small-capacity storage devices (< 16GB), so f2fs_write_raw_pages() overwrites the original compressed data in-place.
The in-memory node has been updated with raw-data addresses, while the node metadata stored on eMMC still remains in compressed state. If a power-cut occurs before the node is flushed to disk, on-disk inconsistency arises: disk data is raw, yet metadata treats it as a compressed cluster, leading to decompression failure.
To eliminate this risk completely, force out-place update for all write operations on compressed file.
---
- Link to v1: https://lore.kernel.org/r/[email protected]
--- fs/f2fs/data.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
fs/f2fs/data.c +6 -4
@@ -2973,10 +2973,12 @@ bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio)return true;if (f2fs_used_in_atomic_write (inode))return true; -/* rewrite low ratio compress data w/ OPU mode to avoid fragmentation */ -if (f2fs_compressed_file (inode) && -F2FS_OPTION (sbi).compress_mode ==COMPR_MODE_USER && -is_inode_flag_set (inode,FI_ENABLE_COMPRESS )) +/* +* rewrite low ratio compress data w/ OPU mode to avoid fragmentation. +* If IO comes from compressed write path and fallback to raw write, +* force out‑place to prevent metadata‑data inconsistency. +*/ +if (f2fs_compressed_file (inode))return true;/* swap file is migrating in aligned write mode */
---
base-commit: 0a1703eba23707e3b2edfa2a2329352e7abc0ffa
change-id: 20260818-origin-dev-0e8c63e2145a
Best regards,
Signature · 1 line
Jiucheng Xu <[email protected]>
Quoted 18 lines · On 9/7/26 19:35, Jiucheng Xu via B4 Relay wrote:
From: Jiucheng Xu <[email protected]>
For compressed file, compressed write may fail and fall back to raw write.
-Thread A - Thread B
- f2fs_write_multi_pages - f2fs_down_write(&sbi->cp_rwsem); - f2fs_write_compressed_pages - ... - f2fs_trylock_op - ... - f2fs_down_read_trylock(&sbi->cp_rwsem); - ... - f2fs_write_raw_pages - ...Thread B acquires the lock first, which causes Thread A to fail lock acquisition and fall back to raw-data write.
IPU_FORCEis enabled on small-capacity storage devices (< 16GB), sof2fs_write_raw_pages()overwrites the original compressed data in-place.
Quoted 9 lines
The in-memory node has been updated with raw-data addresses, while the node metadata stored on eMMC still remains in compressed state. If a power-cut occurs before the node is flushed to disk, on-disk inconsistency arises: disk data is raw, yet metadata treats it as a compressed cluster, leading to decompression failure.
To eliminate this risk completely, force out-place update for all write operations on compressed file.
Quoted 1 line
Signed-off-by Jiucheng Xu <[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 5 lines · On Mon, 07 Sep 2026 19:35:42 +0800 you wrote:
From: Jiucheng Xu <[email protected]>
For compressed file, compressed write may fail and fall back to raw write.
Quoted 8 lines
-Thread A - Thread B
- f2fs_write_multi_pages - f2fs_down_write(&sbi->cp_rwsem); - f2fs_write_compressed_pages - ... - f2fs_trylock_op - ... - f2fs_down_read_trylock(&sbi->cp_rwsem); - ... - f2fs_write_raw_pages - ...[...]
Here is the summary with links:
- [f2fs-dev] f2fs: force out-place update for all writes on compressed file
https://git.kernel.org/jaegeuk/f2fs/c/a64a3fec11e7
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html