f2fs_read_data_large_folio() relies on f2fs_map_blocks() to decide whether
a subpage should be zero-filled or queued to a read bio.

However, f2fs_map_blocks() can set F2FS_MAP_MAPPED for NULL_ADDR and
NEW_ADDR in the non-DIO, no-create path. The large folio read code then
treats such hole blocks as mapped blocks, and may account them
in read_pages_pending and attempt to build bios for them, which can
leave tasks stuck in readahead for heavily fragmented files.

Add a helper, f2fs_block_needs_zeroing(), which detects NULL_ADDR and
NEW_ADDR from struct f2fs_map_blocks. Use it to prioritize the zeroing
path by checking f2fs_block_needs_zeroing() before
(map.m_flags & F2FS_MAP_MAPPED) under got_it: label.

Signed-off-by: Nanzhe Zhao <[email protected]>
---
 fs/f2fs/data.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 4bef04560924..66ab7a43a56f 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -2413,6 +2413,11 @@ static void ffs_detach_free(struct folio *folio)
        kmem_cache_free(ffs_entry_slab, ffs);
 }

+static inline bool f2fs_block_needs_zeroing(const struct f2fs_map_blocks *map)
+{
+       return map->m_pblk == NULL_ADDR || map->m_pblk == NEW_ADDR;
+}
+
 static int f2fs_read_data_large_folio(struct inode *inode,
                struct readahead_control *rac, struct folio *folio)
 {
@@ -2468,14 +2473,7 @@ static int f2fs_read_data_large_folio(struct inode 
*inode,
                if (ret)
                        goto err_out;
 got_it:
-               if ((map.m_flags & F2FS_MAP_MAPPED)) {
-                       block_nr = map.m_pblk + index - map.m_lblk;
-                       if (!f2fs_is_valid_blkaddr(F2FS_I_SB(inode), block_nr,
-                                               DATA_GENERIC_ENHANCE_READ)) {
-                               ret = -EFSCORRUPTED;
-                               goto err_out;
-                       }
-               } else {
+               if ((f2fs_block_needs_zeroing(&map))) {
                        folio_zero_range(folio, offset << PAGE_SHIFT, 
PAGE_SIZE);
                        if (f2fs_need_verity(inode, index) &&
                            !fsverity_verify_page(folio_file_page(folio,
@@ -2484,6 +2482,13 @@ static int f2fs_read_data_large_folio(struct inode 
*inode,
                                goto err_out;
                        }
                        continue;
+               } else if((map.m_flags & F2FS_MAP_MAPPED)) {
+                       block_nr = map.m_pblk + index - map.m_lblk;
+                       if (!f2fs_is_valid_blkaddr(F2FS_I_SB(inode), block_nr,
+                                               DATA_GENERIC_ENHANCE_READ)) {
+                               ret = -EFSCORRUPTED;
+                               goto err_out;
+                       }
                }

                /* We must increment read_pages_pending before possible BIOs 
submitting
--
2.34.1



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reply via email to