* [f2fs-dev] [PATCH v2 0/2] f2fs: fix large folio read corner cases for immutable files
@ 2026-01-11 10:09 Nanzhe Zhao
2026-01-11 10:09 ` [f2fs-dev] [PATCH v2 1/2] f2fs: add 'folio_in_bio' to handle readahead folios with no BIO submission Nanzhe Zhao
2026-01-11 10:09 ` [f2fs-dev] [PATCH v2 2/2] f2fs: advance index and offset after zeroing in large folio read Nanzhe Zhao
0 siblings, 2 replies; 12+ messages in thread
From: Nanzhe Zhao @ 2026-01-11 10:09 UTC (permalink / raw)
To: Jaegeuk Kim, linux-f2fs-devel, linux-fsdevel; +Cc: Chao Yu, Nanzhe Zhao
This is v2 of the bug fixes for corner cases in immutable file
large folio read. The first two fixes from v1 have already been
picked up, so this reroll only carries the remaining two fixes
from v1 (fixing the case where a folio had no BIO submission and
could be left locked, and advance the index and offset after zeroing).
Nanzhe Zhao (2):
f2fs: add 'folio_in_bio' to handle readahead folios with no BIO
submission
f2fs: advance index and offset after zeroing in large folio read
fs/f2fs/data.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
base-commit: 2ff2a9420a8221dd4fb45d7e5f60e33f17914a30
--
2.34.1
^ permalink raw reply [flat|nested] 12+ messages in thread
* [f2fs-dev] [PATCH v2 1/2] f2fs: add 'folio_in_bio' to handle readahead folios with no BIO submission
2026-01-11 10:09 [f2fs-dev] [PATCH v2 0/2] f2fs: fix large folio read corner cases for immutable files Nanzhe Zhao
@ 2026-01-11 10:09 ` Nanzhe Zhao
2026-01-12 1:02 ` Chao Yu
2026-01-13 18:32 ` Matthew Wilcox
2026-01-11 10:09 ` [f2fs-dev] [PATCH v2 2/2] f2fs: advance index and offset after zeroing in large folio read Nanzhe Zhao
1 sibling, 2 replies; 12+ messages in thread
From: Nanzhe Zhao @ 2026-01-11 10:09 UTC (permalink / raw)
To: Jaegeuk Kim, linux-f2fs-devel, linux-fsdevel; +Cc: Chao Yu, Nanzhe Zhao
f2fs_read_data_large_folio() can build a single read BIO across multiple
folios during readahead. If a folio ends up having none of its subpages
added to the BIO (e.g. all subpages are zeroed / treated as holes), it
will never be seen by f2fs_finish_read_bio(), so folio_end_read() is
never called. This leaves the folio locked and not marked uptodate.
Track whether the current folio has been added to a BIO via a local
'folio_in_bio' bool flag, and when iterating readahead folios, explicitly
mark the folio uptodate (on success) and unlock it when nothing was added.
Signed-off-by: Nanzhe Zhao <nzzhao@126.com>
---
fs/f2fs/data.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index f32eb51ccee4..ddabcb1b9882 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -2436,6 +2436,7 @@ static int f2fs_read_data_large_folio(struct inode *inode,
unsigned nrpages;
struct f2fs_folio_state *ffs;
int ret = 0;
+ bool folio_in_bio;
if (!IS_IMMUTABLE(inode))
return -EOPNOTSUPP;
@@ -2451,6 +2452,7 @@ static int f2fs_read_data_large_folio(struct inode *inode,
if (!folio)
goto out;
+ folio_in_bio = false;
index = folio->index;
offset = 0;
ffs = NULL;
@@ -2536,6 +2538,7 @@ static int f2fs_read_data_large_folio(struct inode *inode,
offset << PAGE_SHIFT))
goto submit_and_realloc;
+ folio_in_bio = true;
inc_page_count(F2FS_I_SB(inode), F2FS_RD_DATA);
f2fs_update_iostat(F2FS_I_SB(inode), NULL, FS_DATA_READ_IO,
F2FS_BLKSIZE);
@@ -2545,6 +2548,11 @@ static int f2fs_read_data_large_folio(struct inode *inode,
}
trace_f2fs_read_folio(folio, DATA);
if (rac) {
+ if (!folio_in_bio) {
+ if (!ret)
+ folio_mark_uptodate(folio);
+ folio_unlock(folio);
+ }
folio = readahead_folio(rac);
goto next_folio;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [f2fs-dev] [PATCH v2 2/2] f2fs: advance index and offset after zeroing in large folio read
2026-01-11 10:09 [f2fs-dev] [PATCH v2 0/2] f2fs: fix large folio read corner cases for immutable files Nanzhe Zhao
2026-01-11 10:09 ` [f2fs-dev] [PATCH v2 1/2] f2fs: add 'folio_in_bio' to handle readahead folios with no BIO submission Nanzhe Zhao
@ 2026-01-11 10:09 ` Nanzhe Zhao
2026-01-12 1:03 ` Chao Yu
1 sibling, 1 reply; 12+ messages in thread
From: Nanzhe Zhao @ 2026-01-11 10:09 UTC (permalink / raw)
To: Jaegeuk Kim, linux-f2fs-devel, linux-fsdevel; +Cc: Chao Yu, Nanzhe Zhao
In f2fs_read_data_large_folio(), the block zeroing path calls
folio_zero_range() and then continues the loop. However, it fails to
advance index and offset before continuing.
This can cause the loop to repeatedly process the same subpage of the
folio, leading to stalls/hangs and incorrect progress when reading large
folios with holes/zeroed blocks.
Fix it by advancing index and offset unconditionally in the loop
iteration, so they are updated even when the zeroing path continues.
Signed-off-by: Nanzhe Zhao <nzzhao@126.com>
---
fs/f2fs/data.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index ddabcb1b9882..18952daa8d8b 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -2458,7 +2458,7 @@ static int f2fs_read_data_large_folio(struct inode *inode,
ffs = NULL;
nrpages = folio_nr_pages(folio);
- for (; nrpages; nrpages--) {
+ for (; nrpages; nrpages--, index++, offset++) {
sector_t block_nr;
/*
* Map blocks using the previous result first.
@@ -2543,8 +2543,6 @@ static int f2fs_read_data_large_folio(struct inode *inode,
f2fs_update_iostat(F2FS_I_SB(inode), NULL, FS_DATA_READ_IO,
F2FS_BLKSIZE);
last_block_in_bio = block_nr;
- index++;
- offset++;
}
trace_f2fs_read_folio(folio, DATA);
if (rac) {
--
2.34.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [f2fs-dev] [PATCH v2 1/2] f2fs: add 'folio_in_bio' to handle readahead folios with no BIO submission
2026-01-11 10:09 ` [f2fs-dev] [PATCH v2 1/2] f2fs: add 'folio_in_bio' to handle readahead folios with no BIO submission Nanzhe Zhao
@ 2026-01-12 1:02 ` Chao Yu
2026-01-12 8:52 ` Nanzhe Zhao
2026-01-13 18:32 ` Matthew Wilcox
1 sibling, 1 reply; 12+ messages in thread
From: Chao Yu @ 2026-01-12 1:02 UTC (permalink / raw)
To: Nanzhe Zhao, Jaegeuk Kim, linux-f2fs-devel, linux-fsdevel; +Cc: chao
On 1/11/2026 6:09 PM, Nanzhe Zhao wrote:
> f2fs_read_data_large_folio() can build a single read BIO across multiple
> folios during readahead. If a folio ends up having none of its subpages
> added to the BIO (e.g. all subpages are zeroed / treated as holes), it
> will never be seen by f2fs_finish_read_bio(), so folio_end_read() is
> never called. This leaves the folio locked and not marked uptodate.
>
> Track whether the current folio has been added to a BIO via a local
> 'folio_in_bio' bool flag, and when iterating readahead folios, explicitly
> mark the folio uptodate (on success) and unlock it when nothing was added.
>
> Signed-off-by: Nanzhe Zhao <nzzhao@126.com>
> ---
> fs/f2fs/data.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> index f32eb51ccee4..ddabcb1b9882 100644
> --- a/fs/f2fs/data.c
> +++ b/fs/f2fs/data.c
> @@ -2436,6 +2436,7 @@ static int f2fs_read_data_large_folio(struct inode *inode,
> unsigned nrpages;
> struct f2fs_folio_state *ffs;
> int ret = 0;
> + bool folio_in_bio;
>
> if (!IS_IMMUTABLE(inode))
> return -EOPNOTSUPP;
> @@ -2451,6 +2452,7 @@ static int f2fs_read_data_large_folio(struct inode *inode,
> if (!folio)
> goto out;
>
> + folio_in_bio = false;
> index = folio->index;
> offset = 0;
> ffs = NULL;
> @@ -2536,6 +2538,7 @@ static int f2fs_read_data_large_folio(struct inode *inode,
> offset << PAGE_SHIFT))
> goto submit_and_realloc;
>
> + folio_in_bio = true;
> inc_page_count(F2FS_I_SB(inode), F2FS_RD_DATA);
> f2fs_update_iostat(F2FS_I_SB(inode), NULL, FS_DATA_READ_IO,
> F2FS_BLKSIZE);
> @@ -2545,6 +2548,11 @@ static int f2fs_read_data_large_folio(struct inode *inode,
> }
> trace_f2fs_read_folio(folio, DATA);
> if (rac) {
> + if (!folio_in_bio) {
> + if (!ret)
ret should never be true here?
Thanks,
> + folio_mark_uptodate(folio);
> + folio_unlock(folio);
> + }
> folio = readahead_folio(rac);
> goto next_folio;
> }
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [f2fs-dev] [PATCH v2 2/2] f2fs: advance index and offset after zeroing in large folio read
2026-01-11 10:09 ` [f2fs-dev] [PATCH v2 2/2] f2fs: advance index and offset after zeroing in large folio read Nanzhe Zhao
@ 2026-01-12 1:03 ` Chao Yu
0 siblings, 0 replies; 12+ messages in thread
From: Chao Yu @ 2026-01-12 1:03 UTC (permalink / raw)
To: Nanzhe Zhao, Jaegeuk Kim, linux-f2fs-devel, linux-fsdevel; +Cc: chao
On 1/11/2026 6:09 PM, Nanzhe Zhao wrote:
> In f2fs_read_data_large_folio(), the block zeroing path calls
> folio_zero_range() and then continues the loop. However, it fails to
> advance index and offset before continuing.
>
> This can cause the loop to repeatedly process the same subpage of the
> folio, leading to stalls/hangs and incorrect progress when reading large
> folios with holes/zeroed blocks.
>
> Fix it by advancing index and offset unconditionally in the loop
> iteration, so they are updated even when the zeroing path continues.
>
> Signed-off-by: Nanzhe Zhao <nzzhao@126.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Thanks,
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re:Re: [f2fs-dev] [PATCH v2 1/2] f2fs: add 'folio_in_bio' to handle readahead folios with no BIO submission
2026-01-12 1:02 ` Chao Yu
@ 2026-01-12 8:52 ` Nanzhe Zhao
2026-01-12 9:24 ` Chao Yu
0 siblings, 1 reply; 12+ messages in thread
From: Nanzhe Zhao @ 2026-01-12 8:52 UTC (permalink / raw)
To: Chao Yu; +Cc: Jaegeuk Kim, linux-f2fs-devel, linux-fsdevel
At 2026-01-12 09:02:48, "Chao Yu" <chao@kernel.org> wrote:
>> @@ -2545,6 +2548,11 @@ static int f2fs_read_data_large_folio(struct inode *inode,
>> }
>> trace_f2fs_read_folio(folio, DATA);
>> if (rac) {
>> + if (!folio_in_bio) {
>> + if (!ret)
>
>ret should never be true here?
>
>Thanks,
Yes.Need I send a v3 patch to remove the redundant check?
Thanks,
Nanzhe Zhao
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [f2fs-dev] [PATCH v2 1/2] f2fs: add 'folio_in_bio' to handle readahead folios with no BIO submission
2026-01-12 8:52 ` Nanzhe Zhao
@ 2026-01-12 9:24 ` Chao Yu
2026-01-13 17:05 ` Jaegeuk Kim
0 siblings, 1 reply; 12+ messages in thread
From: Chao Yu @ 2026-01-12 9:24 UTC (permalink / raw)
To: Nanzhe Zhao; +Cc: chao, Jaegeuk Kim, linux-f2fs-devel, linux-fsdevel
On 1/12/2026 4:52 PM, Nanzhe Zhao wrote:
>
> At 2026-01-12 09:02:48, "Chao Yu" <chao@kernel.org> wrote:
>>> @@ -2545,6 +2548,11 @@ static int f2fs_read_data_large_folio(struct inode *inode,
>>> }
>>> trace_f2fs_read_folio(folio, DATA);
>>> if (rac) {
>>> + if (!folio_in_bio) {
>>> + if (!ret)
>>
>> ret should never be true here?
>>
>> Thanks,
> Yes.Need I send a v3 patch to remove the redundant check?
Yes, I think so.
Thanks,
>
> Thanks,
> Nanzhe Zhao
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [f2fs-dev] [PATCH v2 1/2] f2fs: add 'folio_in_bio' to handle readahead folios with no BIO submission
2026-01-12 9:24 ` Chao Yu
@ 2026-01-13 17:05 ` Jaegeuk Kim
2026-01-16 3:31 ` Nanzhe Zhao
2026-01-16 8:53 ` Chao Yu
0 siblings, 2 replies; 12+ messages in thread
From: Jaegeuk Kim @ 2026-01-13 17:05 UTC (permalink / raw)
To: Chao Yu; +Cc: Nanzhe Zhao, linux-f2fs-devel, linux-fsdevel
On 01/12, Chao Yu wrote:
> On 1/12/2026 4:52 PM, Nanzhe Zhao wrote:
> >
> > At 2026-01-12 09:02:48, "Chao Yu" <chao@kernel.org> wrote:
> > > > @@ -2545,6 +2548,11 @@ static int f2fs_read_data_large_folio(struct inode *inode,
> > > > }
> > > > trace_f2fs_read_folio(folio, DATA);
> > > > if (rac) {
> > > > + if (!folio_in_bio) {
> > > > + if (!ret)
> > >
> > > ret should never be true here?
> > >
> > > Thanks,
> > Yes.Need I send a v3 patch to remove the redundant check?
>
> Yes, I think so.
Applied in dev-test with it.
>
> Thanks,
>
> >
> > Thanks,
> > Nanzhe Zhao
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [f2fs-dev] [PATCH v2 1/2] f2fs: add 'folio_in_bio' to handle readahead folios with no BIO submission
2026-01-11 10:09 ` [f2fs-dev] [PATCH v2 1/2] f2fs: add 'folio_in_bio' to handle readahead folios with no BIO submission Nanzhe Zhao
2026-01-12 1:02 ` Chao Yu
@ 2026-01-13 18:32 ` Matthew Wilcox
2026-01-16 4:33 ` Jaegeuk Kim
1 sibling, 1 reply; 12+ messages in thread
From: Matthew Wilcox @ 2026-01-13 18:32 UTC (permalink / raw)
To: Nanzhe Zhao; +Cc: Jaegeuk Kim, linux-f2fs-devel, linux-fsdevel, Chao Yu
On Sun, Jan 11, 2026 at 06:09:40PM +0800, Nanzhe Zhao wrote:
> @@ -2545,6 +2548,11 @@ static int f2fs_read_data_large_folio(struct inode *inode,
> }
> trace_f2fs_read_folio(folio, DATA);
> if (rac) {
> + if (!folio_in_bio) {
> + if (!ret)
> + folio_mark_uptodate(folio);
> + folio_unlock(folio);
folio_end_read(folio, ret == 0);
surely?
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re:Re: [f2fs-dev] [PATCH v2 1/2] f2fs: add 'folio_in_bio' to handle readahead folios with no BIO submission
2026-01-13 17:05 ` Jaegeuk Kim
@ 2026-01-16 3:31 ` Nanzhe Zhao
2026-01-16 8:53 ` Chao Yu
1 sibling, 0 replies; 12+ messages in thread
From: Nanzhe Zhao @ 2026-01-16 3:31 UTC (permalink / raw)
To: Jaegeuk Kim; +Cc: Chao Yu, linux-f2fs-devel, linux-fsdevel
Hi Kim:
At 2026-01-14 01:05:35, "Jaegeuk Kim" <jaegeuk@kernel.org> wrote:
>On 01/12, Chao Yu wrote:
>> On 1/12/2026 4:52 PM, Nanzhe Zhao wrote:
>> >
>> > At 2026-01-12 09:02:48, "Chao Yu" <chao@kernel.org> wrote:
>> > > > @@ -2545,6 +2548,11 @@ static int f2fs_read_data_large_folio(struct inode *inode,
>> > > > }
>> > > > trace_f2fs_read_folio(folio, DATA);
>> > > > if (rac) {
>> > > > + if (!folio_in_bio) {
>> > > > + if (!ret)
>> > >
>> > > ret should never be true here?
>> > >
>> > > Thanks,
>> > Yes.Need I send a v3 patch to remove the redundant check?
>>
>> Yes, I think so.
>
>Applied in dev-test with it.
>
Thanks for apply!
As an aside, I noticed that f2fs_folio_state removed the uptodate bitmap. Do we need to
consider the case where a bio ends up with bi_status set to error (which could potentially
cause a large folio to be only partially read successfully)?
Also, is bio submission and the submit_and_realloc loop never fails ?
Thanks,
Nanzhe Zhao
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [f2fs-dev] [PATCH v2 1/2] f2fs: add 'folio_in_bio' to handle readahead folios with no BIO submission
2026-01-13 18:32 ` Matthew Wilcox
@ 2026-01-16 4:33 ` Jaegeuk Kim
0 siblings, 0 replies; 12+ messages in thread
From: Jaegeuk Kim @ 2026-01-16 4:33 UTC (permalink / raw)
To: Matthew Wilcox; +Cc: Nanzhe Zhao, linux-f2fs-devel, linux-fsdevel, Chao Yu
On 01/13, Matthew Wilcox wrote:
> On Sun, Jan 11, 2026 at 06:09:40PM +0800, Nanzhe Zhao wrote:
> > @@ -2545,6 +2548,11 @@ static int f2fs_read_data_large_folio(struct inode *inode,
> > }
> > trace_f2fs_read_folio(folio, DATA);
> > if (rac) {
> > + if (!folio_in_bio) {
> > + if (!ret)
> > + folio_mark_uptodate(folio);
> > + folio_unlock(folio);
>
> folio_end_read(folio, ret == 0);
Thanks.
https://lore.kernel.org/linux-f2fs-devel/20260116043203.2313943-1-jaegeuk@kernel.org/T/#u
>
> surely?
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [f2fs-dev] [PATCH v2 1/2] f2fs: add 'folio_in_bio' to handle readahead folios with no BIO submission
2026-01-13 17:05 ` Jaegeuk Kim
2026-01-16 3:31 ` Nanzhe Zhao
@ 2026-01-16 8:53 ` Chao Yu
1 sibling, 0 replies; 12+ messages in thread
From: Chao Yu @ 2026-01-16 8:53 UTC (permalink / raw)
To: Jaegeuk Kim; +Cc: chao, Nanzhe Zhao, linux-f2fs-devel, linux-fsdevel
On 1/14/2026 1:05 AM, Jaegeuk Kim wrote:
> On 01/12, Chao Yu wrote:
>> On 1/12/2026 4:52 PM, Nanzhe Zhao wrote:
>>>
>>> At 2026-01-12 09:02:48, "Chao Yu" <chao@kernel.org> wrote:
>>>>> @@ -2545,6 +2548,11 @@ static int f2fs_read_data_large_folio(struct inode *inode,
>>>>> }
>>>>> trace_f2fs_read_folio(folio, DATA);
>>>>> if (rac) {
>>>>> + if (!folio_in_bio) {
>>>>> + if (!ret)
>>>>
>>>> ret should never be true here?
>>>>
>>>> Thanks,
>>> Yes.Need I send a v3 patch to remove the redundant check?
>>
>> Yes, I think so.
>
> Applied in dev-test with it.
For upstreamed version,
Reviewed-by: Chao Yu <chao@kernel.org>
Thanks,
>
>>
>> Thanks,
>>
>>>
>>> Thanks,
>>> Nanzhe Zhao
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2026-01-16 8:53 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-11 10:09 [f2fs-dev] [PATCH v2 0/2] f2fs: fix large folio read corner cases for immutable files Nanzhe Zhao
2026-01-11 10:09 ` [f2fs-dev] [PATCH v2 1/2] f2fs: add 'folio_in_bio' to handle readahead folios with no BIO submission Nanzhe Zhao
2026-01-12 1:02 ` Chao Yu
2026-01-12 8:52 ` Nanzhe Zhao
2026-01-12 9:24 ` Chao Yu
2026-01-13 17:05 ` Jaegeuk Kim
2026-01-16 3:31 ` Nanzhe Zhao
2026-01-16 8:53 ` Chao Yu
2026-01-13 18:32 ` Matthew Wilcox
2026-01-16 4:33 ` Jaegeuk Kim
2026-01-11 10:09 ` [f2fs-dev] [PATCH v2 2/2] f2fs: advance index and offset after zeroing in large folio read Nanzhe Zhao
2026-01-12 1:03 ` Chao Yu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox