Commit 368a83ce authored by Matthew Wilcox (Oracle)'s avatar Matthew Wilcox (Oracle) Committed by Theodore Ts'o

ext4: pipeline buffer reads in mext_page_mkuptodate()

Instead of synchronously reading one buffer at a time, submit reads
as we walk the buffers in the first loop, then wait for them in the
second loop.  This should be significantly more efficient, particularly
on HDDs, but I have not measured.
Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Link: https://patch.msgid.link/20240718223005.568869-2-willy@infradead.orgSigned-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent e37c9e17
...@@ -174,7 +174,9 @@ mext_page_mkuptodate(struct folio *folio, unsigned from, unsigned to) ...@@ -174,7 +174,9 @@ mext_page_mkuptodate(struct folio *folio, unsigned from, unsigned to)
sector_t block; sector_t block;
struct buffer_head *bh, *head, *arr[MAX_BUF_PER_PAGE]; struct buffer_head *bh, *head, *arr[MAX_BUF_PER_PAGE];
unsigned int blocksize, block_start, block_end; unsigned int blocksize, block_start, block_end;
int i, err, nr = 0, partial = 0; int i, nr = 0;
bool partial = false;
BUG_ON(!folio_test_locked(folio)); BUG_ON(!folio_test_locked(folio));
BUG_ON(folio_test_writeback(folio)); BUG_ON(folio_test_writeback(folio));
...@@ -192,13 +194,13 @@ mext_page_mkuptodate(struct folio *folio, unsigned from, unsigned to) ...@@ -192,13 +194,13 @@ mext_page_mkuptodate(struct folio *folio, unsigned from, unsigned to)
block_end = block_start + blocksize; block_end = block_start + blocksize;
if (block_end <= from || block_start >= to) { if (block_end <= from || block_start >= to) {
if (!buffer_uptodate(bh)) if (!buffer_uptodate(bh))
partial = 1; partial = true;
continue; continue;
} }
if (buffer_uptodate(bh)) if (buffer_uptodate(bh))
continue; continue;
if (!buffer_mapped(bh)) { if (!buffer_mapped(bh)) {
err = ext4_get_block(inode, block, bh, 0); int err = ext4_get_block(inode, block, bh, 0);
if (err) if (err)
return err; return err;
if (!buffer_mapped(bh)) { if (!buffer_mapped(bh)) {
...@@ -207,6 +209,12 @@ mext_page_mkuptodate(struct folio *folio, unsigned from, unsigned to) ...@@ -207,6 +209,12 @@ mext_page_mkuptodate(struct folio *folio, unsigned from, unsigned to)
continue; continue;
} }
} }
lock_buffer(bh);
if (buffer_uptodate(bh)) {
unlock_buffer(bh);
continue;
}
ext4_read_bh_nowait(bh, 0, NULL);
BUG_ON(nr >= MAX_BUF_PER_PAGE); BUG_ON(nr >= MAX_BUF_PER_PAGE);
arr[nr++] = bh; arr[nr++] = bh;
} }
...@@ -216,11 +224,10 @@ mext_page_mkuptodate(struct folio *folio, unsigned from, unsigned to) ...@@ -216,11 +224,10 @@ mext_page_mkuptodate(struct folio *folio, unsigned from, unsigned to)
for (i = 0; i < nr; i++) { for (i = 0; i < nr; i++) {
bh = arr[i]; bh = arr[i];
if (!bh_uptodate_or_lock(bh)) { wait_on_buffer(bh);
err = ext4_read_bh(bh, 0, NULL); if (buffer_uptodate(bh))
if (err) continue;
return err; return -EIO;
}
} }
out: out:
if (!partial) if (!partial)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment