[PATCH] f2fs: let f2fs_write_cache_pages() flush a partially written folio

From: Daeho Jeong

Date: Thu Nov 19 2026 - 15:42:39 EST


From: Daeho Jeong <daehojeong@xxxxxxxxxx>

f2fs_write_single_data_page() writes a multi-block folio block by block,
so it can fail after it put some of the blocks into the merged bio. It
does not report them on an error, and f2fs_write_raw_pages() does not
count a folio that failed, so f2fs_write_cache_pages() may not flush the
bio at the end and the folio stays under writeback. For that reason
f2fs_write_single_data_page() flushes the bio by itself on an error.

Report the submitted blocks on an error as well, and count them in
f2fs_write_raw_pages() before its error handling. Then
f2fs_write_cache_pages() flushes the bio as it does after a successful
write, which is also what f2fs_write_cache_folios() does, and the flush
in f2fs_write_single_data_page() can go.

Suggested-by: Chao Yu <chao@xxxxxxxxxx>
Signed-off-by: Daeho Jeong <daehojeong@xxxxxxxxxx>
---
fs/f2fs/compress.c | 4 ++--
fs/f2fs/data.c | 7 ++++---
2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c
index d0e989254ffe..b8001953be15 100644
--- a/fs/f2fs/compress.c
+++ b/fs/f2fs/compress.c
@@ -1743,6 +1743,8 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc,
ret = f2fs_write_single_data_page(folio, &submitted,
NULL, NULL, wbc, io_type,
compr_blocks, false);
+ /* Some blocks can be submitted before an error. */
+ *submitted_p += submitted;
if (ret) {
if (ret == 1) {
ret = 0;
@@ -1760,8 +1762,6 @@ static int f2fs_write_raw_pages(struct compress_ctx *cc,
}
goto out;
}
-
- *submitted_p += submitted;
}

out:
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index cdc9e6e8633c..c0fc24d0b2ac 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -4381,9 +4381,10 @@ int f2fs_write_single_data_page(struct folio *folio, int *submitted,
if (!compr_blocks)
f2fs_unlock_op(sbi, &lc);

- /* The callers drop the submitted count on error. */
- if (err && local_submitted)
- f2fs_submit_merged_write_cond(sbi, NULL, folio);
+ /* Let the caller flush the blocks submitted before an error. */
+ if (err && submitted)
+ *submitted = DIV_ROUND_UP(local_submitted,
+ F2FS_BLKS_PER_PAGE(sbi));

if (!err)
f2fs_ffs_clear_subrange_dirty_and_test(folio, 0,
--
2.56.1.750.gf70dc682cf-goog