Skip to contentSkip to conversation

f2fs: fix large folio read corner cases for immutable files

PATCH In review Nanzhe Zhao 4 participants 12 messages Jan 11 – Jan 16

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover f2fs: fix large folio read corner cases for immutable files

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

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

#1 lore raw

PATCH v2 1/2 f2fs: add 'folio_in_bio' to handle readahead folios with no BIO submission

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.

---
 fs/f2fs/data.c | 8 ++++++++
 1 file changed, 8 insertions(+)
fs/f2fs/data.c +8 -0
index f32eb51ccee4..ddabcb1b9882 100644
@@ -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

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

maintainer
#2 lore raw

Re: [f2fs-dev] [PATCH v2 1/2] f2fs: add 'folio_in_bio' to handle readahead folios with no BIO submission

Quoted 44 lines · 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.

---
  fs/f2fs/data.c | 8 ++++++++
  1 file changed, 8 insertions(+)
fs/f2fs/data.c +3 -0
index f32eb51ccee4..ddabcb1b9882 100644
@@ -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);

fs/f2fs/data.c static int f2fs_read_data_large_folio(struct inode *inode, · line 2552

Quoted 5 lines
fs/f2fs/data.c +2 -0
@@ -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,

Quoted 9 lines
fs/f2fs/data.c +3 -1
+				folio_mark_uptodate(folio);
+			folio_unlock(folio);
+		}
  		folio = readahead_folio(rac);
  		goto next_folio;
  	}
--

2.34.1

#3 lore raw

Re:Re: [f2fs-dev] [PATCH v2 1/2] f2fs: add 'folio_in_bio' to handle readahead folios with no BIO submission

Quoted 10 lines · Chao Yu

fs/f2fs/data.c static int f2fs_read_data_large_folio(struct inode *inode, · line 2552

Quoted 6 lines
fs/f2fs/data.c +2 -0
@@ -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

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

maintainer
#4 lore raw

Re: [f2fs-dev] [PATCH v2 1/2] f2fs: add 'folio_in_bio' to handle readahead folios with no BIO submission

Quoted 11 lines · Nanzhe Zhao
Quoted 9 lines · Chao Yu

fs/f2fs/data.c static int f2fs_read_data_large_folio(struct inode *inode, · line 2552

Quoted 6 lines
fs/f2fs/data.c +2 -0
@@ -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?

Quoted 2 lines
Quoted 1 line

Thanks,

Yes.Need I send a v3 patch to remove the redundant check?

Yes, I think so.

Thanks,

Quoted 3 lines

Thanks,
Nanzhe Zhao

maintainer
#5 lore raw

Re: [f2fs-dev] [PATCH v2 1/2] f2fs: add 'folio_in_bio' to handle readahead folios with no BIO submission

Quoted 12 lines · Chao Yu
Quoted 11 lines · Nanzhe Zhao
Quoted 9 lines · Chao Yu

fs/f2fs/data.c static int f2fs_read_data_large_folio(struct inode *inode, · line 2552

Quoted 6 lines
fs/f2fs/data.c +2 -0
@@ -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?

Quoted 4 lines
Quoted 2 lines
Quoted 1 line

Thanks,

Yes.Need I send a v3 patch to remove the redundant check?

Yes, I think so.

Applied in dev-test with it.

Quoted 6 lines

Thanks,

Quoted 3 lines

Thanks,
Nanzhe Zhao

#6 lore raw

Re:Re: [f2fs-dev] [PATCH v2 1/2] f2fs: add 'folio_in_bio' to handle readahead folios with no BIO submission

Hi Kim:

Quoted 13 lines · Jaegeuk Kim
Quoted 12 lines · Chao Yu
Quoted 11 lines · Nanzhe Zhao
Quoted 9 lines · Chao Yu

fs/f2fs/data.c static int f2fs_read_data_large_folio(struct inode *inode, · line 2552

Quoted 6 lines
fs/f2fs/data.c +2 -0
@@ -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?

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Quoted 1 line

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
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

maintainer Reviewed-by
#7 lore raw

Re: [f2fs-dev] [PATCH v2 1/2] f2fs: add 'folio_in_bio' to handle readahead folios with no BIO submission

In reply to Jaegeuk Kim
Quoted 13 lines · Jaegeuk Kim
Quoted 12 lines · Chao Yu
Quoted 11 lines · Nanzhe Zhao
Quoted 9 lines · Chao Yu

fs/f2fs/data.c static int f2fs_read_data_large_folio(struct inode *inode, · line 2552

Quoted 6 lines
fs/f2fs/data.c +2 -0
@@ -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?

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Quoted 1 line

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,

Thanks,

Quoted 7 lines
Quoted 7 lines

Thanks,

Quoted 3 lines

Thanks,
Nanzhe Zhao

#8 lore raw

Re: [f2fs-dev] [PATCH v2 1/2] f2fs: add 'folio_in_bio' to handle readahead folios with no BIO submission

In reply to Nanzhe Zhao

fs/f2fs/data.c static int f2fs_read_data_large_folio(struct inode *inode, · line 2554

Quoted 8 lines · Nanzhe Zhao
fs/f2fs/data.c +4 -0
@@ -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?

maintainer
#9 lore raw

Re: [f2fs-dev] [PATCH v2 1/2] f2fs: add 'folio_in_bio' to handle readahead folios with no BIO submission

Quoted 11 lines · Matthew Wilcox

fs/f2fs/data.c static int f2fs_read_data_large_folio(struct inode *inode, · line 2554

Quoted 8 lines · Nanzhe Zhao
fs/f2fs/data.c +4 -0
@@ -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/[email protected]/T/#u

Quoted 2 lines

surely?

#10 lore raw

PATCH v2 2/2 f2fs: advance index and offset after zeroing in large folio read

In reply to 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.

---
 fs/f2fs/data.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
fs/f2fs/data.c +1 -3
index ddabcb1b9882..18952daa8d8b 100644
@@ -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

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

maintainer Reviewed-by on v2 2/2
#11 lore raw

Re: [f2fs-dev] [PATCH v2 2/2] f2fs: advance index and offset after zeroing in large folio read

Quoted 4 lines · 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.

Quoted 8 lines

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.

Thanks,