erofs: adapt folios for z_erofs_readahead()

It's a straight-forward conversion except that readahead_folio()
will do folio_put() in advance but it doesn't matter since folios
are still locked.

As before, since file-backed folios (pages for now) are locked, so
we could temporarily use folio->private as an internal counter to
indicate split parts of each folio for the corresponding pclusters
to decompress.

When such counter becomes zero, the folio will be finally unlocked
(see compress.h and z_erofs_onlinepage_endio()).

Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20230817082813.81180-7-hsiangkao@linux.alibaba.com
This commit is contained in:
Gao Xiang 2023-08-17 16:28:12 +08:00
parent 06ec03660d
commit 491b1105a8

View File

@ -1853,37 +1853,35 @@ static void z_erofs_readahead(struct readahead_control *rac)
struct inode *const inode = rac->mapping->host; struct inode *const inode = rac->mapping->host;
struct erofs_sb_info *const sbi = EROFS_I_SB(inode); struct erofs_sb_info *const sbi = EROFS_I_SB(inode);
struct z_erofs_decompress_frontend f = DECOMPRESS_FRONTEND_INIT(inode); struct z_erofs_decompress_frontend f = DECOMPRESS_FRONTEND_INIT(inode);
struct page *head = NULL, *page; struct folio *head = NULL, *folio;
unsigned int nr_pages; unsigned int nr_folios;
int err;
f.headoffset = readahead_pos(rac); f.headoffset = readahead_pos(rac);
z_erofs_pcluster_readmore(&f, rac, true); z_erofs_pcluster_readmore(&f, rac, true);
nr_pages = readahead_count(rac); nr_folios = readahead_count(rac);
trace_erofs_readpages(inode, readahead_index(rac), nr_pages, false); trace_erofs_readpages(inode, readahead_index(rac), nr_folios, false);
while ((page = readahead_page(rac))) { while ((folio = readahead_folio(rac))) {
set_page_private(page, (unsigned long)head); folio->private = head;
head = page; head = folio;
} }
/* traverse in reverse order for best metadata I/O performance */
while (head) { while (head) {
struct page *page = head; folio = head;
int err; head = folio_get_private(folio);
/* traversal in reverse order */ err = z_erofs_do_read_page(&f, &folio->page);
head = (void *)page_private(page);
err = z_erofs_do_read_page(&f, page);
if (err && err != -EINTR) if (err && err != -EINTR)
erofs_err(inode->i_sb, "readahead error %d @ %lu of nid %llu", erofs_err(inode->i_sb, "readahead error at folio %lu @ nid %llu",
err, page->index, EROFS_I(inode)->nid); folio->index, EROFS_I(inode)->nid);
put_page(page);
} }
z_erofs_pcluster_readmore(&f, rac, false); z_erofs_pcluster_readmore(&f, rac, false);
z_erofs_pcluster_end(&f); z_erofs_pcluster_end(&f);
z_erofs_runqueue(&f, z_erofs_is_sync_decompress(sbi, nr_pages), true); z_erofs_runqueue(&f, z_erofs_is_sync_decompress(sbi, nr_folios), true);
erofs_put_metabuf(&f.map.buf); erofs_put_metabuf(&f.map.buf);
erofs_release_pages(&f.pagepool); erofs_release_pages(&f.pagepool);
} }