All small code style adjustments, no logic changes:

 - z_erofs_decompress_frontend => z_erofs_frontend;
 - z_erofs_decompress_backend => z_erofs_backend;
 - Use Z_EROFS_DEFINE_FRONTEND() to replace DECOMPRESS_FRONTEND_INIT();
 - `nr_folios` should be `nrpages` in z_erofs_readahead();
 - Refine in-line comments.

Signed-off-by: Gao Xiang <hsiang...@linux.alibaba.com>
---
 fs/erofs/zdata.c | 111 ++++++++++++++++++-----------------------------
 1 file changed, 43 insertions(+), 68 deletions(-)

diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c
index 8bafc4d9edbe..dcbb692ac058 100644
--- a/fs/erofs/zdata.c
+++ b/fs/erofs/zdata.c
@@ -455,31 +455,25 @@ int __init z_erofs_init_subsystem(void)
 }
 
 enum z_erofs_pclustermode {
+       /* It has previously been linked into another processing chain */
        Z_EROFS_PCLUSTER_INFLIGHT,
        /*
-        * a weak form of Z_EROFS_PCLUSTER_FOLLOWED, the difference is that it
-        * could be dispatched into bypass queue later due to uptodated managed
-        * pages. All related online pages cannot be reused for inplace I/O (or
-        * bvpage) since it can be directly decoded without I/O submission.
+        * A weaker form of Z_EROFS_PCLUSTER_FOLLOWED; the difference is that it
+        * may be dispatched to the bypass queue later due to uptodated managed
+        * folios.  All file-backed folios related to this pcluster cannot be
+        * reused for in-place I/O (or bvpage) since the pcluster may be decoded
+        * in a separate queue (and thus out of order).
         */
        Z_EROFS_PCLUSTER_FOLLOWED_NOINPLACE,
        /*
-        * The pcluster was just linked to a decompression chain by us.  It can
-        * also be linked with the remaining pclusters, which means if the
-        * processing page is the tail page of a pcluster, this pcluster can
-        * safely use the whole page (since the previous pcluster is within the
-        * same chain) for in-place I/O, as illustrated below:
-        *  ___________________________________________________
-        * |  tail (partial) page  |    head (partial) page    |
-        * |  (of the current pcl) |   (of the previous pcl)   |
-        * |___PCLUSTER_FOLLOWED___|_____PCLUSTER_FOLLOWED_____|
-        *
-        * [  (*) the page above can be used as inplace I/O.   ]
+        * The pcluster has just been linked to our processing chain.
+        * File-backed folios (except for the head page) related to it can be
+        * used for in-place I/O (or bvpage).
         */
        Z_EROFS_PCLUSTER_FOLLOWED,
 };
 
-struct z_erofs_decompress_frontend {
+struct z_erofs_frontend {
        struct inode *const inode;
        struct erofs_map_blocks map;
        struct z_erofs_bvec_iter biter;
@@ -495,11 +489,11 @@ struct z_erofs_decompress_frontend {
        unsigned int icur;
 };
 
-#define DECOMPRESS_FRONTEND_INIT(__i) { \
-       .inode = __i, .head = Z_EROFS_PCLUSTER_TAIL, \
-       .mode = Z_EROFS_PCLUSTER_FOLLOWED }
+#define Z_EROFS_DEFINE_FRONTEND(fe, i, ho) struct z_erofs_frontend fe = { \
+       .inode = i, .head = Z_EROFS_PCLUSTER_TAIL, \
+       .mode = Z_EROFS_PCLUSTER_FOLLOWED, .headoffset = ho }
 
-static bool z_erofs_should_alloc_cache(struct z_erofs_decompress_frontend *fe)
+static bool z_erofs_should_alloc_cache(struct z_erofs_frontend *fe)
 {
        unsigned int cachestrategy = EROFS_I_SB(fe->inode)->opt.cache_strategy;
 
@@ -516,7 +510,7 @@ static bool z_erofs_should_alloc_cache(struct 
z_erofs_decompress_frontend *fe)
        return false;
 }
 
-static void z_erofs_bind_cache(struct z_erofs_decompress_frontend *fe)
+static void z_erofs_bind_cache(struct z_erofs_frontend *fe)
 {
        struct address_space *mc = MNGD_MAPPING(EROFS_I_SB(fe->inode));
        struct z_erofs_pcluster *pcl = fe->pcl;
@@ -673,7 +667,7 @@ int erofs_init_managed_cache(struct super_block *sb)
 }
 
 /* callers must be with pcluster lock held */
-static int z_erofs_attach_page(struct z_erofs_decompress_frontend *fe,
+static int z_erofs_attach_page(struct z_erofs_frontend *fe,
                               struct z_erofs_bvec *bvec, bool exclusive)
 {
        struct z_erofs_pcluster *pcl = fe->pcl;
@@ -719,7 +713,7 @@ static bool z_erofs_get_pcluster(struct z_erofs_pcluster 
*pcl)
        return true;
 }
 
-static int z_erofs_register_pcluster(struct z_erofs_decompress_frontend *fe)
+static int z_erofs_register_pcluster(struct z_erofs_frontend *fe)
 {
        struct erofs_map_blocks *map = &fe->map;
        struct super_block *sb = fe->inode->i_sb;
@@ -789,7 +783,7 @@ static int z_erofs_register_pcluster(struct 
z_erofs_decompress_frontend *fe)
        return err;
 }
 
-static int z_erofs_pcluster_begin(struct z_erofs_decompress_frontend *fe)
+static int z_erofs_pcluster_begin(struct z_erofs_frontend *fe)
 {
        struct erofs_map_blocks *map = &fe->map;
        struct super_block *sb = fe->inode->i_sb;
@@ -862,14 +856,9 @@ static int z_erofs_pcluster_begin(struct 
z_erofs_decompress_frontend *fe)
        return 0;
 }
 
-/*
- * keep in mind that no referenced pclusters will be freed
- * only after a RCU grace period.
- */
 static void z_erofs_rcu_callback(struct rcu_head *head)
 {
-       z_erofs_free_pcluster(container_of(head,
-                       struct z_erofs_pcluster, rcu));
+       z_erofs_free_pcluster(container_of(head, struct z_erofs_pcluster, rcu));
 }
 
 static bool __erofs_try_to_release_pcluster(struct erofs_sb_info *sbi,
@@ -911,8 +900,7 @@ static bool erofs_try_to_release_pcluster(struct 
erofs_sb_info *sbi,
        return free;
 }
 
-unsigned long z_erofs_shrink_scan(struct erofs_sb_info *sbi,
-                                 unsigned long nr_shrink)
+unsigned long z_erofs_shrink_scan(struct erofs_sb_info *sbi, unsigned long nr)
 {
        struct z_erofs_pcluster *pcl;
        unsigned int freed = 0;
@@ -926,7 +914,7 @@ unsigned long z_erofs_shrink_scan(struct erofs_sb_info *sbi,
                xa_unlock(&sbi->managed_pslots);
 
                ++freed;
-               if (!--nr_shrink)
+               if (!--nr)
                        return freed;
                xa_lock(&sbi->managed_pslots);
        }
@@ -955,7 +943,7 @@ static void z_erofs_put_pcluster(struct erofs_sb_info *sbi,
                call_rcu(&pcl->rcu, z_erofs_rcu_callback);
 }
 
-static void z_erofs_pcluster_end(struct z_erofs_decompress_frontend *fe)
+static void z_erofs_pcluster_end(struct z_erofs_frontend *fe)
 {
        struct z_erofs_pcluster *pcl = fe->pcl;
 
@@ -968,13 +956,9 @@ static void z_erofs_pcluster_end(struct 
z_erofs_decompress_frontend *fe)
        if (fe->candidate_bvpage)
                fe->candidate_bvpage = NULL;
 
-       /*
-        * if all pending pages are added, don't hold its reference
-        * any longer if the pcluster isn't hosted by ourselves.
-        */
+       /* Drop refcount if it doesn't belong to our processing chain */
        if (fe->mode < Z_EROFS_PCLUSTER_FOLLOWED_NOINPLACE)
                z_erofs_put_pcluster(EROFS_I_SB(fe->inode), pcl, false);
-
        fe->pcl = NULL;
 }
 
@@ -1003,7 +987,7 @@ static int z_erofs_read_fragment(struct super_block *sb, 
struct folio *folio,
        return 0;
 }
 
-static int z_erofs_scan_folio(struct z_erofs_decompress_frontend *f,
+static int z_erofs_scan_folio(struct z_erofs_frontend *f,
                              struct folio *folio, bool ra)
 {
        struct inode *const inode = f->inode;
@@ -1118,7 +1102,7 @@ static bool z_erofs_page_is_invalidated(struct page *page)
        return !page_folio(page)->mapping && !z_erofs_is_shortlived_page(page);
 }
 
-struct z_erofs_decompress_backend {
+struct z_erofs_backend {
        struct page *onstack_pages[Z_EROFS_ONSTACK_PAGES];
        struct super_block *sb;
        struct z_erofs_pcluster *pcl;
@@ -1138,7 +1122,7 @@ struct z_erofs_bvec_item {
        struct list_head list;
 };
 
-static void z_erofs_do_decompressed_bvec(struct z_erofs_decompress_backend *be,
+static void z_erofs_do_decompressed_bvec(struct z_erofs_backend *be,
                                         struct z_erofs_bvec *bvec)
 {
        struct z_erofs_bvec_item *item;
@@ -1161,8 +1145,7 @@ static void z_erofs_do_decompressed_bvec(struct 
z_erofs_decompress_backend *be,
        list_add(&item->list, &be->decompressed_secondary_bvecs);
 }
 
-static void z_erofs_fill_other_copies(struct z_erofs_decompress_backend *be,
-                                     int err)
+static void z_erofs_fill_other_copies(struct z_erofs_backend *be, int err)
 {
        unsigned int off0 = be->pcl->pageofs_out;
        struct list_head *p, *n;
@@ -1203,7 +1186,7 @@ static void z_erofs_fill_other_copies(struct 
z_erofs_decompress_backend *be,
        }
 }
 
-static void z_erofs_parse_out_bvecs(struct z_erofs_decompress_backend *be)
+static void z_erofs_parse_out_bvecs(struct z_erofs_backend *be)
 {
        struct z_erofs_pcluster *pcl = be->pcl;
        struct z_erofs_bvec_iter biter;
@@ -1228,8 +1211,7 @@ static void z_erofs_parse_out_bvecs(struct 
z_erofs_decompress_backend *be)
                z_erofs_put_shortlivedpage(be->pagepool, old_bvpage);
 }
 
-static int z_erofs_parse_in_bvecs(struct z_erofs_decompress_backend *be,
-                                 bool *overlapped)
+static int z_erofs_parse_in_bvecs(struct z_erofs_backend *be, bool *overlapped)
 {
        struct z_erofs_pcluster *pcl = be->pcl;
        unsigned int pclusterpages = z_erofs_pclusterpages(pcl);
@@ -1264,8 +1246,7 @@ static int z_erofs_parse_in_bvecs(struct 
z_erofs_decompress_backend *be,
        return err;
 }
 
-static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be,
-                                      int err)
+static int z_erofs_decompress_pcluster(struct z_erofs_backend *be, int err)
 {
        struct erofs_sb_info *const sbi = EROFS_SB(be->sb);
        struct z_erofs_pcluster *pcl = be->pcl;
@@ -1395,7 +1376,7 @@ static int z_erofs_decompress_pcluster(struct 
z_erofs_decompress_backend *be,
 static int z_erofs_decompress_queue(const struct z_erofs_decompressqueue *io,
                                    struct page **pagepool)
 {
-       struct z_erofs_decompress_backend be = {
+       struct z_erofs_backend be = {
                .sb = io->sb,
                .pagepool = pagepool,
                .decompressed_secondary_bvecs =
@@ -1473,7 +1454,7 @@ static void z_erofs_decompress_kickoff(struct 
z_erofs_decompressqueue *io,
 }
 
 static void z_erofs_fill_bio_vec(struct bio_vec *bvec,
-                                struct z_erofs_decompress_frontend *f,
+                                struct z_erofs_frontend *f,
                                 struct z_erofs_pcluster *pcl,
                                 unsigned int nr,
                                 struct address_space *mc)
@@ -1652,7 +1633,7 @@ static void z_erofs_endio(struct bio *bio)
                bio_put(bio);
 }
 
-static void z_erofs_submit_queue(struct z_erofs_decompress_frontend *f,
+static void z_erofs_submit_queue(struct z_erofs_frontend *f,
                                 struct z_erofs_decompressqueue *fgq,
                                 bool *force_fg, bool readahead)
 {
@@ -1785,17 +1766,16 @@ static void z_erofs_submit_queue(struct 
z_erofs_decompress_frontend *f,
        z_erofs_decompress_kickoff(q[JQ_SUBMIT], nr_bios);
 }
 
-static int z_erofs_runqueue(struct z_erofs_decompress_frontend *f,
-                           unsigned int ra_folios)
+static int z_erofs_runqueue(struct z_erofs_frontend *f, unsigned int rapages)
 {
        struct z_erofs_decompressqueue io[NR_JOBQUEUES];
        struct erofs_sb_info *sbi = EROFS_I_SB(f->inode);
-       bool force_fg = z_erofs_is_sync_decompress(sbi, ra_folios);
+       bool force_fg = z_erofs_is_sync_decompress(sbi, rapages);
        int err;
 
        if (f->head == Z_EROFS_PCLUSTER_TAIL)
                return 0;
-       z_erofs_submit_queue(f, io, &force_fg, !!ra_folios);
+       z_erofs_submit_queue(f, io, &force_fg, !!rapages);
 
        /* handle bypass queue (no i/o pclusters) immediately */
        err = z_erofs_decompress_queue(&io[JQ_BYPASS], &f->pagepool);
@@ -1813,7 +1793,7 @@ static int z_erofs_runqueue(struct 
z_erofs_decompress_frontend *f,
  * Since partial uptodate is still unimplemented for now, we have to use
  * approximate readmore strategies as a start.
  */
-static void z_erofs_pcluster_readmore(struct z_erofs_decompress_frontend *f,
+static void z_erofs_pcluster_readmore(struct z_erofs_frontend *f,
                struct readahead_control *rac, bool backmost)
 {
        struct inode *inode = f->inode;
@@ -1868,12 +1848,10 @@ static void z_erofs_pcluster_readmore(struct 
z_erofs_decompress_frontend *f,
 static int z_erofs_read_folio(struct file *file, struct folio *folio)
 {
        struct inode *const inode = folio->mapping->host;
-       struct z_erofs_decompress_frontend f = DECOMPRESS_FRONTEND_INIT(inode);
+       Z_EROFS_DEFINE_FRONTEND(f, inode, folio_pos(folio));
        int err;
 
        trace_erofs_read_folio(folio, false);
-       f.headoffset = (erofs_off_t)folio->index << PAGE_SHIFT;
-
        z_erofs_pcluster_readmore(&f, NULL, true);
        err = z_erofs_scan_folio(&f, folio, false);
        z_erofs_pcluster_readmore(&f, NULL, false);
@@ -1893,17 +1871,14 @@ static int z_erofs_read_folio(struct file *file, struct 
folio *folio)
 static void z_erofs_readahead(struct readahead_control *rac)
 {
        struct inode *const inode = rac->mapping->host;
-       struct z_erofs_decompress_frontend f = DECOMPRESS_FRONTEND_INIT(inode);
+       Z_EROFS_DEFINE_FRONTEND(f, inode, readahead_pos(rac));
        struct folio *head = NULL, *folio;
-       unsigned int nr_folios;
+       unsigned int nrpages = readahead_count(rac);
        int err;
 
-       f.headoffset = readahead_pos(rac);
-
        z_erofs_pcluster_readmore(&f, rac, true);
-       nr_folios = readahead_count(rac);
-       trace_erofs_readpages(inode, readahead_index(rac), nr_folios, false);
-
+       nrpages = readahead_count(rac);
+       trace_erofs_readpages(inode, readahead_index(rac), nrpages, false);
        while ((folio = readahead_folio(rac))) {
                folio->private = head;
                head = folio;
@@ -1922,7 +1897,7 @@ static void z_erofs_readahead(struct readahead_control 
*rac)
        z_erofs_pcluster_readmore(&f, rac, false);
        z_erofs_pcluster_end(&f);
 
-       (void)z_erofs_runqueue(&f, nr_folios);
+       (void)z_erofs_runqueue(&f, nrpages);
        erofs_put_metabuf(&f.map.buf);
        erofs_release_pages(&f.pagepool);
 }
-- 
2.43.5

Reply via email to