[PATCH] ext4: do io submit when next to write page not continues

From: Jinke Han
Date: Sun Aug 21 2022 - 13:21:54 EST


From: Jinke Han <hanjinke.666@xxxxxxxxxxxxx>

In ext4_writepages, sometimes we leave the bio to next-to-write page for
physic block merge. But if next page no longer continus, we'd better
submit it immediately,

For extent inode, the chance of physic continue while logic block not
continus is very small. If next to write page not coninus and unmapped,
we may gather enough pages for extent and then do block allocation and
mapping for it's extent. Then we try to merge to prev bio and get failed.
For the prev bio, the waiting time is unnecessary.

In that case, we have to flush the prev bio with holding all page locks
of the extent. The submit_bio may be blocked by wbt or getting request
which may take a while. Users also may be waiting for these page locks.

In fast do_map=0 mode, we also end this not much hope waiting soon and
submit it without any page lock.

Signed-off-by: Jinke Han <hanjinke.666@xxxxxxxxxxxxx>
---
fs/ext4/inode.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 601214453c3a..2f7786c459c9 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -2608,6 +2608,12 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd)
if (mpd->map.m_len > 0 && mpd->next_page != page->index)
goto out;

+ /* Submit bio when page no longer continus and
+ * do it before taking other page's lock
+ */
+ if (mpd->next_page != page->index && mpd->io_submit.io_bio)
+ ext4_io_submit(&mpd->io_submit);
+
lock_page(page);
/*
* If the page is no longer dirty, or its mapping no
--
2.20.1