erofs: adapt folios for z_erofs_readahead()
authorGao Xiang <hsiangkao@linux.alibaba.com>
Thu, 17 Aug 2023 08:28:12 +0000 (16:28 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Wed, 23 Aug 2023 15:47:18 +0000 (23:47 +0800)
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
fs/erofs/zdata.c

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