]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
f2fs: Accounting large folio subpages before bio submission
authorNanzhe Zhao <nzzhao@126.com>
Mon, 5 Jan 2026 15:30:58 +0000 (23:30 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 7 Jan 2026 03:17:08 +0000 (03:17 +0000)
In f2fs_read_data_large_folio(), read_pages_pending is incremented only
after the subpage has been added to the BIO.  With a heavily fragmented
file, each new subpage can force submission of the previous BIO.

If the BIO completes quickly, f2fs_finish_read_bio() may decrement
read_pages_pending to zero and call folio_end_read() while the read loop
is still processing other subpages of the same large folio.

Fix the ordering by incrementing read_pages_pending before any possible
BIO submission for the current subpage, matching the iomap ordering and
preventing premature folio_end_read().

Signed-off-by: Nanzhe Zhao <nzzhao@126.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/data.c

index b5b39a788ee5762dd5498072dbfa03c132ad512d..f32eb51ccee4747956406ad4ea3d3fcf20f89fdf 100644 (file)
@@ -2497,6 +2497,18 @@ got_it:
                        continue;
                }
 
+               /* We must increment read_pages_pending before possible BIOs submitting
+                * to prevent from premature folio_end_read() call on folio
+                */
+               if (folio_test_large(folio)) {
+                       ffs = ffs_find_or_alloc(folio);
+
+                       /* set the bitmap to wait */
+                       spin_lock_irq(&ffs->state_lock);
+                       ffs->read_pages_pending++;
+                       spin_unlock_irq(&ffs->state_lock);
+               }
+
                /*
                 * This page will go to BIO.  Do we need to send this
                 * BIO off first?
@@ -2524,15 +2536,6 @@ submit_and_realloc:
                                        offset << PAGE_SHIFT))
                        goto submit_and_realloc;
 
-               if (folio_test_large(folio)) {
-                       ffs = ffs_find_or_alloc(folio);
-
-                       /* set the bitmap to wait */
-                       spin_lock_irq(&ffs->state_lock);
-                       ffs->read_pages_pending++;
-                       spin_unlock_irq(&ffs->state_lock);
-               }
-
                inc_page_count(F2FS_I_SB(inode), F2FS_RD_DATA);
                f2fs_update_iostat(F2FS_I_SB(inode), NULL, FS_DATA_READ_IO,
                                F2FS_BLKSIZE);