[PATCH v4 02/18] f2fs: remove mappedtodisk flag usage in mmap write path

From: Nanzhe Zhao

Date: Tue Oct 13 2026 - 08:23:42 EST


From: Nanzhe Zhao <zhaonanzhe@xxxxxxxxxx>

PG_mappedtodisk was inherited from the nobh/buffer-head era. However,
f2fs has no buffer heads and the flag is no longer meaningful. The only
user of the flag is the "no holes" shortcut in f2fs_vm_page_mkwrite(),
which makes mmap write faults skip marking the folio dirty. Moreover,
it causes the following race condition with filesystem freezing:

CPU0 (write fault) CPU1 (freeze_super)
---- ----
f2fs_vm_page_mkwrite()
sb_start_pagefault()
/* shortcut: no dirty */
sb_end_pagefault()

sb_wait_write(SB_FREEZE_PAGEFAULT)
/* no waiter, passes */
sync_filesystem()
/* folio not dirty, skipped */

finish_fault()
/* PTE writable */
fault_dirty_shared_page()
folio_mark_dirty()
/* dirty folio on a frozen fs */

It will also skip APP_MAPPED_IO iostat/REQ_TIME updates and post-EOF
folio zeroing.

Remove this shortcut in f2fs_vm_page_mkwrite() and stop setting it in
f2fs_read_single_page().

Reported-by: Chao Yu <chao@xxxxxxxxxx>
Link: https://lore.kernel.org/linux-f2fs-devel/496b913c-eb81-4fa8-be72-c6a06a10aba2@xxxxxxxxxx/
Reviewed-by: Chao Yu <chao@xxxxxxxxxx>
Reviewed-by: Barry Song <baohua@xxxxxxxxxx>
Fixes: fbfa2cc58d53 ("f2fs: add file operations")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Nanzhe Zhao <zhaonanzhe@xxxxxxxxxx>
---
fs/f2fs/data.c | 1 -
fs/f2fs/file.c | 6 ------
2 files changed, 7 deletions(-)

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 29c4a81eb..f2d2f0106 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -2481,7 +2481,6 @@ static int f2fs_read_single_page(struct inode *inode, struct fsverity_info *vi,
got_it:
if ((map->m_flags & F2FS_MAP_MAPPED)) {
block_nr = map->m_pblk + block_in_file - map->m_lblk;
- folio_set_mappedtodisk(folio);

if (!f2fs_is_valid_blkaddr(F2FS_I_SB(inode), block_nr,
DATA_GENERIC_ENHANCE_READ)) {
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index fc959cdb9..d680f6f8a 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -225,12 +225,6 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf)
/* wait for GCed page writeback via generic cache */
f2fs_wait_on_block_writeback(inode, dn.data_blkaddr);

- /*
- * check to see if the page is mapped already (no holes)
- */
- if (folio_test_mappedtodisk(folio))
- goto out_sem;
-
/* page is wholly or partially inside EOF */
if (((loff_t)(folio->index + 1) << PAGE_SHIFT) > isize) {
loff_t offset;
--
2.43.0