[RFCv2 1/3] iomap: Move creation of iomap_page early in __iomap_write_begin

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Before this commit[1], we used to call iomap_page_create() before
checking folio_test_uptodate() in __iomap_write_begin().

The problem is that commit[1] moved iop creation later i.e. after checking for
whether the folio is uptodate. And if the folio is uptodate, it simply
returns and doesn't allocate a iop.
Now what can happen is that during __iomap_write_begin() for bs < ps,
there can be a folio which is marked uptodate but does not have a iomap_page
structure allocated.
(I think one of the reason it can happen is due to memory pressure, we
can end up freeing folio->private resource).

Thus the iop structure will only gets allocated at the time of writeback
in iomap_writepage_map(). This I think, was a not problem till now since
we anyway only track uptodate status in iop (no support of tracking
dirty bitmap status which later patches will add), and we also end up
setting all the bits in iomap_page_create(), if the page is uptodate.

[1]: https://lore.kernel.org/all/20220623175157.1715274-5-shr@xxxxxx/
Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@xxxxxxxxx>
---
 fs/iomap/buffered-io.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 356193e44cf0..e9c85fcf7a1f 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -527,7 +527,8 @@ static int __iomap_write_begin(const struct iomap_iter *iter, loff_t pos,
 		size_t len, struct folio *folio)
 {
 	const struct iomap *srcmap = iomap_iter_srcmap(iter);
-	struct iomap_page *iop;
+	struct iomap_page *iop = iomap_page_create(iter->inode, folio,
+						   iter->flags);
 	loff_t block_size = i_blocksize(iter->inode);
 	loff_t block_start = round_down(pos, block_size);
 	loff_t block_end = round_up(pos + len, block_size);
@@ -539,7 +540,6 @@ static int __iomap_write_begin(const struct iomap_iter *iter, loff_t pos,
 		return 0;
 	folio_clear_error(folio);
 
-	iop = iomap_page_create(iter->inode, folio, iter->flags);
 	if ((iter->flags & IOMAP_NOWAIT) && !iop && nr_blocks > 1)
 		return -EAGAIN;
 
-- 
2.39.1




[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux