* [PATCH] f2fs: force out-place update for all writes on compressed file
@ 2026-09-07 11:35 Jiucheng Xu via B4 Relay
2026-09-08 0:15 ` Chao Yu
0 siblings, 1 reply; 3+ messages in thread
From: Jiucheng Xu via B4 Relay @ 2026-09-07 11:35 UTC (permalink / raw)
To: Jaegeuk Kim, Chao Yu
Cc: linux-f2fs-devel, linux-kernel, stable, jianxin.pan, tao.zeng,
tuan.zhang, Jiucheng Xu
From: Jiucheng Xu <jiucheng.xu@amlogic.com>
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.
Signed-off-by: Jiucheng Xu <jiucheng.xu@amlogic.com>
---
- Link to v1: https://lore.kernel.org/r/20260826-origin-dev-v1-1-c21271a82100@amlogic.com
---
fs/f2fs/data.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 6ae0eb37d20f96ed51a8124f59ba90dabf632fb5..aaeea561dcd30681b9b37f2f6f0493ed58ec2fe0 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -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,
--
Jiucheng Xu <jiucheng.xu@amlogic.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] f2fs: force out-place update for all writes on compressed file
2026-09-07 11:35 [PATCH] f2fs: force out-place update for all writes on compressed file Jiucheng Xu via B4 Relay
@ 2026-09-08 0:15 ` Chao Yu
0 siblings, 0 replies; 3+ messages in thread
From: Chao Yu @ 2026-09-08 0:15 UTC (permalink / raw)
To: jiucheng.xu, Jaegeuk Kim
Cc: chao, linux-f2fs-devel, linux-kernel, stable, jianxin.pan,
tao.zeng, tuan.zhang
On 9/7/26 19:35, Jiucheng Xu via B4 Relay wrote:
> From: Jiucheng Xu <jiucheng.xu@amlogic.com>
>
> 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.
>
Cc: stable@kernel.org
Fixes: 4c8ff7095bef ("f2fs: support data compression")
> Signed-off-by: Jiucheng Xu <jiucheng.xu@amlogic.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Thanks,
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] f2fs: force out-place update for all writes on compressed file
@ 2026-08-26 8:48 Jiucheng Xu via B4 Relay
0 siblings, 0 replies; 3+ messages in thread
From: Jiucheng Xu via B4 Relay @ 2026-08-26 8:48 UTC (permalink / raw)
To: Jaegeuk Kim, Chao Yu
Cc: linux-f2fs-devel, linux-kernel, jianxin.pan, tao.zeng,
tuan.zhang, Jiucheng Xu
From: Jiucheng Xu <jiucheng.xu@amlogic.com>
For compressed file, compressed write may fail and fall back to raw
write.
If in-place update(IPU) is allowed, raw data could be written into disk
before cluster metadata is updated from compressed state to raw state.
Sudden power-cut during this window will result in inconsistency:
raw data on disk but metadata still expects compressed content,
which causes decompression failure when reading the file later.
To eliminate this risk completely, force out-place update for all
write operations on compressed file, so IPU will never be used.
Signed-off-by: Jiucheng Xu <jiucheng.xu@amlogic.com>
---
fs/f2fs/data.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 6ae0eb37d20f96ed51a8124f59ba90dabf632fb5..aaeea561dcd30681b9b37f2f6f0493ed58ec2fe0 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -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,
--
Jiucheng Xu <jiucheng.xu@amlogic.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-09-08 0:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-07 11:35 [PATCH] f2fs: force out-place update for all writes on compressed file Jiucheng Xu via B4 Relay
2026-09-08 0:15 ` Chao Yu
-- strict thread matches above, loose matches on Subject: below --
2026-08-26 8:48 Jiucheng Xu via B4 Relay
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®