Skip to contentSkip to conversation

iomap: small block problems

PATCH In review Andreas Gruenbacher 4 participants 15 messages Jul 7, 2021 – Jul 9, 2021

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

v3 cover iomap: small block problems

Here's another update of this patch queue. Changes from v2:

* Reverse the order of the first two patches to make the queue bisect clean. Adjust the patch descriptions accordingly.

* With the second patch, iomap_readpage_actor currently still creates iops. Christoph has indicated that this should now be unnecessary as well, but testing has proven that we're not quite at that point, yet.

* Don't create iomap_page objects in iomap_page_mkwrite_actor anymore; this clearly has become obsolete with the first patch.

Thanks,
Andreas

Andreas Gruenbacher (3):
iomap: Permit pages without an iop to enter writeback
iomap: Don't create iomap_page objects for inline files
iomap: Don't create iomap_page objects in iomap_page_mkwrite_actor

 fs/iomap/buffered-io.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Signature · 1 line
2.26.3
#1 lore raw

PATCH v3 1/3 iomap: Permit pages without an iop to enter writeback

Create an iop in the writeback path if one doesn't exist. This allows us to avoid creating the iop in some cases. We'll initially do that for pages with inline data, but it can be extended to pages which are entirely within an extent. It also allows for an iop to be removed from pages in the future (eg page split).

---
 fs/iomap/buffered-io.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/iomap/buffered-io.c +1 -2
index 9023717c5188..598fcfabc337 100644
@@ -1334,14 +1334,13 @@ iomap_writepage_map(struct iomap_writepage_ctx *wpc,
 		struct writeback_control *wbc, struct inode *inode,
 		struct page *page, u64 end_offset)
 {
-	struct iomap_page *iop = to_iomap_page(page);
+	struct iomap_page *iop = iomap_page_create(inode, page);
 	struct iomap_ioend *ioend, *next;
 	unsigned len = i_blocksize(inode);
 	u64 file_offset; /* file offset of page */
 	int error = 0, count = 0, i;
 	LIST_HEAD(submit_list);
 
-	WARN_ON_ONCE(i_blocks_per_page(inode, page) > 1 && !iop);
 	WARN_ON_ONCE(iop && atomic_read(&iop->write_bytes_pending) != 0);
 
 	/*
Signature · 1 line
2.26.3
Reviewed-by on v3 1/3
#2 lore raw

Re: [PATCH v3 1/3] iomap: Permit pages without an iop to enter writeback

Quoted 10 lines · Andreas Gruenbacher

Create an iop in the writeback path if one doesn't exist. This allows us to avoid creating the iop in some cases. We'll initially do that for pages with inline data, but it can be extended to pages which are entirely within an extent. It also allows for an iop to be removed from pages in the future (eg page split).

Seems simple enough...

--D

Quoted 27 lines
---
 fs/iomap/buffered-io.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/iomap/buffered-io.c +1 -2
index 9023717c5188..598fcfabc337 100644
@@ -1334,14 +1334,13 @@ iomap_writepage_map(struct iomap_writepage_ctx *wpc,
 		struct writeback_control *wbc, struct inode *inode,
 		struct page *page, u64 end_offset)
 {
-	struct iomap_page *iop = to_iomap_page(page);
+	struct iomap_page *iop = iomap_page_create(inode, page);
 	struct iomap_ioend *ioend, *next;
 	unsigned len = i_blocksize(inode);
 	u64 file_offset; /* file offset of page */
 	int error = 0, count = 0, i;
 	LIST_HEAD(submit_list);
 
-	WARN_ON_ONCE(i_blocks_per_page(inode, page) > 1 && !iop);
 	WARN_ON_ONCE(iop && atomic_read(&iop->write_bytes_pending) != 0);
 
 	/*
Signature · 1 line
2.26.3
#3 lore raw

PATCH v3 2/3 iomap: Don't create iomap_page objects for inline files

In reply to Andreas Gruenbacher

In iomap_readpage_actor, don't create iop objects for inline inodes. Otherwise, iomap_read_inline_data will set PageUptodate without setting iop->uptodate, and iomap_page_release will eventually complain.

To prevent this kind of bug from occurring in the future, make sure the page doesn't have private data attached in iomap_read_inline_data.

---
 fs/iomap/buffered-io.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/iomap/buffered-io.c +3 -1
index 598fcfabc337..6330dabc451e 100644
@@ -215,6 +215,7 @@ iomap_read_inline_data(struct inode *inode, struct page *page,
 	if (PageUptodate(page))
 		return;
 
+	BUG_ON(page_has_private(page));
 	BUG_ON(page->index);
 	BUG_ON(size > PAGE_SIZE - offset_in_page(iomap->inline_data));
 
@@ -239,7 +240,7 @@ iomap_readpage_actor(struct inode *inode, loff_t pos, loff_t length, void *data,
 {
 	struct iomap_readpage_ctx *ctx = data;
 	struct page *page = ctx->cur_page;
-	struct iomap_page *iop = iomap_page_create(inode, page);
+	struct iomap_page *iop;
 	bool same_page = false, is_contig = false;
 	loff_t orig_pos = pos;
 	unsigned poff, plen;
@@ -252,6 +253,7 @@ iomap_readpage_actor(struct inode *inode, loff_t pos, loff_t length, void *data,
 	}
 
 	/* zero post-eof blocks as the page may be mapped */
+	iop = iomap_page_create(inode, page);
 	iomap_adjust_read_range(inode, iop, &pos, length, &poff, &plen);
 	if (plen == 0)
 		goto done;
Signature · 1 line
2.26.3
#4 lore raw

Re: [PATCH v3 2/3] iomap: Don't create iomap_page objects for inline files

fs/iomap/buffered-io.c iomap_readpage_actor(struct inode *inode, loff_t pos, loff_t length, void *data, · line 259

Quoted 8 lines · Andreas Gruenbacher
fs/iomap/buffered-io.c +1 -0
@@ -252,6 +253,7 @@ iomap_readpage_actor(struct inode *inode, loff_t pos, loff_t length, void *data,
 	}
 
 	/* zero post-eof blocks as the page may be mapped */
+	iop = iomap_page_create(inode, page);
 	iomap_adjust_read_range(inode, iop, &pos, length, &poff, &plen);
 	if (plen == 0)
 		goto done;

I /think/ a subsequent patch would look like this:

+ /* No need to create an iop if the page is within an extent */
+ loff_t page_pos = page_offset(page);
+ if (pos > page_pos || pos + length < page_pos + page_size(page))
+ iop = iomap_page_create(inode, page);

but that might miss some other reasons to create an iop.

#5 lore raw

Re: [PATCH v3 2/3] iomap: Don't create iomap_page objects for inline files

Quoted 17 lines · Matthew Wilcox

fs/iomap/buffered-io.c iomap_readpage_actor(struct inode *inode, loff_t pos, loff_t length, void *data, · line 259

Quoted 8 lines · Andreas Gruenbacher
fs/iomap/buffered-io.c +1 -0
@@ -252,6 +253,7 @@ iomap_readpage_actor(struct inode *inode, loff_t pos, loff_t length, void *data,
 	}
 
 	/* zero post-eof blocks as the page may be mapped */
+	iop = iomap_page_create(inode, page);
 	iomap_adjust_read_range(inode, iop, &pos, length, &poff, &plen);
 	if (plen == 0)
 		goto done;

I /think/ a subsequent patch would look like this:

(quoted diff) +4 -0
+	/* No need to create an iop if the page is within an extent */
+	loff_t page_pos = page_offset(page);
+	if (pos > page_pos || pos + length < page_pos + page_size(page))
+		iop = iomap_page_create(inode, page);
Quoted 1 line

but that might miss some other reasons to create an iop.

I was under the impression that for blksize<pagesize filesystems, the page always had to have an iop attached. In principle I think you're right that we don't need one if all i_blocks_per_page blocks have the same uptodate state, but someone would have to perform a close reading of buffered-io.c to make it drop them when unnecessary and re-add them if it becomes necessary. That might be more cycling through kmem_alloc than we like, but as I said, I have never studied this idea.

--D

#6 lore raw

Re: [PATCH v3 2/3] iomap: Don't create iomap_page objects for inline files

Quoted 2 lines · Darrick J. Wong

I was under the impression that for blksize<pagesize filesystems, the page always had to have an iop attached.

Currently it does. But I've talked since day one of the !bufferhead iomap code that we should eventually lift that.

#7 lore raw

Re: [PATCH v3 2/3] iomap: Don't create iomap_page objects for inline files

In reply to Darrick J. Wong
Quoted 18 lines · Darrick J. Wong
Quoted 17 lines · Matthew Wilcox

fs/iomap/buffered-io.c iomap_readpage_actor(struct inode *inode, loff_t pos, loff_t length, void *data, · line 259

Quoted 8 lines · Andreas Gruenbacher
fs/iomap/buffered-io.c +1 -0
@@ -252,6 +253,7 @@ iomap_readpage_actor(struct inode *inode, loff_t pos, loff_t length, void *data,
 	}
 
 	/* zero post-eof blocks as the page may be mapped */
+	iop = iomap_page_create(inode, page);
 	iomap_adjust_read_range(inode, iop, &pos, length, &poff, &plen);
 	if (plen == 0)
 		goto done;

I /think/ a subsequent patch would look like this:

(quoted diff) +4 -0
+	/* No need to create an iop if the page is within an extent */
+	loff_t page_pos = page_offset(page);
+	if (pos > page_pos || pos + length < page_pos + page_size(page))
+		iop = iomap_page_create(inode, page);
Quoted 9 lines
Quoted 1 line

but that might miss some other reasons to create an iop.

I was under the impression that for blksize<pagesize filesystems, the page always had to have an iop attached. In principle I think you're right that we don't need one if all i_blocks_per_page blocks have the same uptodate state, but someone would have to perform a close reading of buffered-io.c to make it drop them when unnecessary and re-add them if it becomes necessary. That might be more cycling through kmem_alloc than we like, but as I said, I have never studied this idea.

I wouldn't free them unnecessarily; that is, once we've determined that we need an iop, we should just keep it, even once the entire page is Uptodate (because we'll need it for write-out eventually anyway).

I haven't noticed any ill-effects from discarding iops while running xfstests on the THP/multipage folio patches. That will discard iops when splitting a page (the page must be entirely uptodate at that point).

Reviewed-by on v3 2/3
#8 lore raw

Re: [PATCH v3 2/3] iomap: Don't create iomap_page objects for inline files

In reply to Andreas Gruenbacher
Quoted 8 lines · Andreas Gruenbacher

In iomap_readpage_actor, don't create iop objects for inline inodes. Otherwise, iomap_read_inline_data will set PageUptodate without setting iop->uptodate, and iomap_page_release will eventually complain.

To prevent this kind of bug from occurring in the future, make sure the page doesn't have private data attached in iomap_read_inline_data.

Looks good to me,

--D

Quoted 36 lines
---
 fs/iomap/buffered-io.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/iomap/buffered-io.c +3 -1
index 598fcfabc337..6330dabc451e 100644
@@ -215,6 +215,7 @@ iomap_read_inline_data(struct inode *inode, struct page *page,
 	if (PageUptodate(page))
 		return;
 
+	BUG_ON(page_has_private(page));
 	BUG_ON(page->index);
 	BUG_ON(size > PAGE_SIZE - offset_in_page(iomap->inline_data));
 
@@ -239,7 +240,7 @@ iomap_readpage_actor(struct inode *inode, loff_t pos, loff_t length, void *data,
 {
 	struct iomap_readpage_ctx *ctx = data;
 	struct page *page = ctx->cur_page;
-	struct iomap_page *iop = iomap_page_create(inode, page);
+	struct iomap_page *iop;
 	bool same_page = false, is_contig = false;
 	loff_t orig_pos = pos;
 	unsigned poff, plen;
@@ -252,6 +253,7 @@ iomap_readpage_actor(struct inode *inode, loff_t pos, loff_t length, void *data,
 	}
 
 	/* zero post-eof blocks as the page may be mapped */
+	iop = iomap_page_create(inode, page);
 	iomap_adjust_read_range(inode, iop, &pos, length, &poff, &plen);
 	if (plen == 0)
 		goto done;
Signature · 1 line
2.26.3
Reviewed-by on v3 2/3
#9 lore raw

Re: [PATCH v3 2/3] iomap: Don't create iomap_page objects for inline files

In reply to Andreas Gruenbacher
Quoted 8 lines · Andreas Gruenbacher

In iomap_readpage_actor, don't create iop objects for inline inodes. Otherwise, iomap_read_inline_data will set PageUptodate without setting iop->uptodate, and iomap_page_release will eventually complain.

To prevent this kind of bug from occurring in the future, make sure the page doesn't have private data attached in iomap_read_inline_data.

Ok, given that you want a quick fix this looks good for now:

#10 lore raw

PATCH v3 3/3 iomap: Don't create iomap_page objects in iomap_page_mkwrite_actor

In reply to Andreas Gruenbacher

Now that we create those objects in iomap_writepage_map when needed, there's no need to pre-create them in iomap_page_mkwrite_actor anymore.

---
 fs/iomap/buffered-io.c | 1 -
 1 file changed, 1 deletion(-)
fs/iomap/buffered-io.c +0 -1
index 6330dabc451e..9f45050b61dd 100644
@@ -999,7 +999,6 @@ iomap_page_mkwrite_actor(struct inode *inode, loff_t pos, loff_t length,
 		block_commit_write(page, 0, length);
 	} else {
 		WARN_ON_ONCE(!PageUptodate(page));
-		iomap_page_create(inode, page);
 		set_page_dirty(page);
 	}
 
Signature · 1 line
2.26.3
Reviewed-by on v3 3/3
#11 lore raw

Re: [PATCH v3 3/3] iomap: Don't create iomap_page objects in iomap_page_mkwrite_actor

Quoted 4 lines · Andreas Gruenbacher

Now that we create those objects in iomap_writepage_map when needed, there's no need to pre-create them in iomap_page_mkwrite_actor anymore.

Thanks for sticking with this. It looks like a nice cleanup now rather than "argh, a bug, burn it with fire".

Reviewed-by on v3 3/3
#12 lore raw

Re: [PATCH v3 3/3] iomap: Don't create iomap_page objects in iomap_page_mkwrite_actor

In reply to Andreas Gruenbacher
Quoted 4 lines · Andreas Gruenbacher

Now that we create those objects in iomap_writepage_map when needed, there's no need to pre-create them in iomap_page_mkwrite_actor anymore.

I'd like to stage this series as a bugfix branch against -rc1 next week, if there are no other objections?

--D

Quoted 19 lines
---
 fs/iomap/buffered-io.c | 1 -
 1 file changed, 1 deletion(-)
fs/iomap/buffered-io.c +0 -1
index 6330dabc451e..9f45050b61dd 100644
@@ -999,7 +999,6 @@ iomap_page_mkwrite_actor(struct inode *inode, loff_t pos, loff_t length,
 		block_commit_write(page, 0, length);
 	} else {
 		WARN_ON_ONCE(!PageUptodate(page));
-		iomap_page_create(inode, page);
 		set_page_dirty(page);
 	}
 
Signature · 1 line
2.26.3
#13 lore raw

Re: [PATCH v3 3/3] iomap: Don't create iomap_page objects in iomap_page_mkwrite_actor

Quoted 8 lines · Darrick J. Wong
Quoted 4 lines · Andreas Gruenbacher

Now that we create those objects in iomap_writepage_map when needed, there's no need to pre-create them in iomap_page_mkwrite_actor anymore.

I'd like to stage this series as a bugfix branch against -rc1 next week, if there are no other objections?

Yes, that would help a lot, thanks.

Andreas