Skip to contentSkip to conversation

f2fs: let f2fs_write_cache_pages() flush a partially written folio

PATCH New Daeho Jeong 1 participant 1 message Nov 19 F2FS file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs: let f2fs_write_cache_pages() flush a partially written folio

From: Daeho Jeong <[email protected]>

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.

---
 fs/f2fs/compress.c | 4 ++--
 fs/f2fs/data.c     | 7 ++++---
 2 files changed, 6 insertions(+), 5 deletions(-)
fs/f2fs/compress.c +2 -2
index d0e989254ffe..b8001953be15 100644
@@ -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:
fs/f2fs/data.c +4 -3
index cdc9e6e8633c..c0fc24d0b2ac 100644
@@ -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,
Signature · 1 line
2.56.1.750.gf70dc682cf-goog