From nobody Sat Apr 18 10:52:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25537C43334 for ; Thu, 14 Jul 2022 13:21:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239732AbiGNNVR (ORCPT ); Thu, 14 Jul 2022 09:21:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239762AbiGNNVF (ORCPT ); Thu, 14 Jul 2022 09:21:05 -0400 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 445905E325 for ; Thu, 14 Jul 2022 06:21:02 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R561e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VJJkPD9_1657804858; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJJkPD9_1657804858) by smtp.aliyun-inc.com; Thu, 14 Jul 2022 21:20:59 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang Subject: [PATCH 01/16] erofs: get rid of unneeded `inode', `map' and `sb' Date: Thu, 14 Jul 2022 21:20:36 +0800 Message-Id: <20220714132051.46012-2-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> References: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Since commit 5c6dcc57e2e5 ("erofs: get rid of `struct z_erofs_collector'"), these arguments can be dropped as well. No logic changes. Signed-off-by: Gao Xiang Reviewed-by: Yue Hu --- fs/erofs/zdata.c | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index 724bb57075f6..1b6816dd235f 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -404,10 +404,9 @@ static void z_erofs_try_to_claim_pcluster(struct z_ero= fs_decompress_frontend *f) f->mode =3D COLLECT_PRIMARY; } =20 -static int z_erofs_lookup_pcluster(struct z_erofs_decompress_frontend *fe, - struct inode *inode, - struct erofs_map_blocks *map) +static int z_erofs_lookup_pcluster(struct z_erofs_decompress_frontend *fe) { + struct erofs_map_blocks *map =3D &fe->map; struct z_erofs_pcluster *pcl =3D fe->pcl; unsigned int length; =20 @@ -449,10 +448,9 @@ static int z_erofs_lookup_pcluster(struct z_erofs_deco= mpress_frontend *fe, return 0; } =20 -static int z_erofs_register_pcluster(struct z_erofs_decompress_frontend *f= e, - struct inode *inode, - struct erofs_map_blocks *map) +static int z_erofs_register_pcluster(struct z_erofs_decompress_frontend *f= e) { + struct erofs_map_blocks *map =3D &fe->map; bool ztailpacking =3D map->m_flags & EROFS_MAP_META; struct z_erofs_pcluster *pcl; struct erofs_workgroup *grp; @@ -494,7 +492,7 @@ static int z_erofs_register_pcluster(struct z_erofs_dec= ompress_frontend *fe, } else { pcl->obj.index =3D map->m_pa >> PAGE_SHIFT; =20 - grp =3D erofs_insert_workgroup(inode->i_sb, &pcl->obj); + grp =3D erofs_insert_workgroup(fe->inode->i_sb, &pcl->obj); if (IS_ERR(grp)) { err =3D PTR_ERR(grp); goto err_out; @@ -520,10 +518,9 @@ static int z_erofs_register_pcluster(struct z_erofs_de= compress_frontend *fe, return err; } =20 -static int z_erofs_collector_begin(struct z_erofs_decompress_frontend *fe, - struct inode *inode, - struct erofs_map_blocks *map) +static int z_erofs_collector_begin(struct z_erofs_decompress_frontend *fe) { + struct erofs_map_blocks *map =3D &fe->map; struct erofs_workgroup *grp; int ret; =20 @@ -541,19 +538,19 @@ static int z_erofs_collector_begin(struct z_erofs_dec= ompress_frontend *fe, goto tailpacking; } =20 - grp =3D erofs_find_workgroup(inode->i_sb, map->m_pa >> PAGE_SHIFT); + grp =3D erofs_find_workgroup(fe->inode->i_sb, map->m_pa >> PAGE_SHIFT); if (grp) { fe->pcl =3D container_of(grp, struct z_erofs_pcluster, obj); } else { tailpacking: - ret =3D z_erofs_register_pcluster(fe, inode, map); + ret =3D z_erofs_register_pcluster(fe); if (!ret) goto out; if (ret !=3D -EEXIST) return ret; } =20 - ret =3D z_erofs_lookup_pcluster(fe, inode, map); + ret =3D z_erofs_lookup_pcluster(fe); if (ret) { erofs_workgroup_put(&fe->pcl->obj); return ret; @@ -663,7 +660,7 @@ static int z_erofs_do_read_page(struct z_erofs_decompre= ss_frontend *fe, if (!(map->m_flags & EROFS_MAP_MAPPED)) goto hitted; =20 - err =3D z_erofs_collector_begin(fe, inode, map); + err =3D z_erofs_collector_begin(fe); if (err) goto err_out; =20 @@ -1259,13 +1256,13 @@ static void z_erofs_decompressqueue_endio(struct bi= o *bio) bio_put(bio); } =20 -static void z_erofs_submit_queue(struct super_block *sb, - struct z_erofs_decompress_frontend *f, +static void z_erofs_submit_queue(struct z_erofs_decompress_frontend *f, struct page **pagepool, struct z_erofs_decompressqueue *fgq, bool *force_fg) { - struct erofs_sb_info *const sbi =3D EROFS_SB(sb); + struct super_block *sb =3D f->inode->i_sb; + struct address_space *mc =3D MNGD_MAPPING(EROFS_SB(sb)); z_erofs_next_pcluster_t qtail[NR_JOBQUEUES]; struct z_erofs_decompressqueue *q[NR_JOBQUEUES]; void *bi_private; @@ -1317,7 +1314,7 @@ static void z_erofs_submit_queue(struct super_block *= sb, struct page *page; =20 page =3D pickup_page_for_submission(pcl, i++, pagepool, - MNGD_MAPPING(sbi)); + mc); if (!page) continue; =20 @@ -1369,15 +1366,14 @@ static void z_erofs_submit_queue(struct super_block= *sb, z_erofs_decompress_kickoff(q[JQ_SUBMIT], *force_fg, nr_bios); } =20 -static void z_erofs_runqueue(struct super_block *sb, - struct z_erofs_decompress_frontend *f, +static void z_erofs_runqueue(struct z_erofs_decompress_frontend *f, struct page **pagepool, bool force_fg) { struct z_erofs_decompressqueue io[NR_JOBQUEUES]; =20 if (f->owned_head =3D=3D Z_EROFS_PCLUSTER_TAIL) return; - z_erofs_submit_queue(sb, f, pagepool, io, &force_fg); + z_erofs_submit_queue(f, pagepool, io, &force_fg); =20 /* handle bypass queue (no i/o pclusters) immediately */ z_erofs_decompress_queue(&io[JQ_BYPASS], pagepool); @@ -1475,7 +1471,7 @@ static int z_erofs_read_folio(struct file *file, stru= ct folio *folio) (void)z_erofs_collector_end(&f); =20 /* if some compressed cluster ready, need submit them anyway */ - z_erofs_runqueue(inode->i_sb, &f, &pagepool, + z_erofs_runqueue(&f, &pagepool, z_erofs_get_sync_decompress_policy(sbi, 0)); =20 if (err) @@ -1524,7 +1520,7 @@ static void z_erofs_readahead(struct readahead_contro= l *rac) z_erofs_pcluster_readmore(&f, rac, 0, &pagepool, false); (void)z_erofs_collector_end(&f); =20 - z_erofs_runqueue(inode->i_sb, &f, &pagepool, + z_erofs_runqueue(&f, &pagepool, z_erofs_get_sync_decompress_policy(sbi, nr_pages)); erofs_put_metabuf(&f.map.buf); erofs_release_pages(&pagepool); --=20 2.24.4 From nobody Sat Apr 18 10:52:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52AB3C433EF for ; Thu, 14 Jul 2022 13:21:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239749AbiGNNVV (ORCPT ); Thu, 14 Jul 2022 09:21:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239723AbiGNNVF (ORCPT ); Thu, 14 Jul 2022 09:21:05 -0400 Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 447725D5B1 for ; Thu, 14 Jul 2022 06:21:04 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R841e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046059;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VJJkPEO_1657804860; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJJkPEO_1657804860) by smtp.aliyun-inc.com; Thu, 14 Jul 2022 21:21:01 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang Subject: [PATCH 02/16] erofs: clean up z_erofs_collector_begin() Date: Thu, 14 Jul 2022 21:20:37 +0800 Message-Id: <20220714132051.46012-3-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> References: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Rearrange the code and get rid of all gotos. Signed-off-by: Gao Xiang Reviewed-by: Yue Hu --- fs/erofs/zdata.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index 1b6816dd235f..c7be447ac64d 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -521,7 +521,7 @@ static int z_erofs_register_pcluster(struct z_erofs_dec= ompress_frontend *fe) static int z_erofs_collector_begin(struct z_erofs_decompress_frontend *fe) { struct erofs_map_blocks *map =3D &fe->map; - struct erofs_workgroup *grp; + struct erofs_workgroup *grp =3D NULL; int ret; =20 DBG_BUGON(fe->pcl); @@ -530,33 +530,31 @@ static int z_erofs_collector_begin(struct z_erofs_dec= ompress_frontend *fe) DBG_BUGON(fe->owned_head =3D=3D Z_EROFS_PCLUSTER_NIL); DBG_BUGON(fe->owned_head =3D=3D Z_EROFS_PCLUSTER_TAIL_CLOSED); =20 - if (map->m_flags & EROFS_MAP_META) { - if ((map->m_pa & ~PAGE_MASK) + map->m_plen > PAGE_SIZE) { - DBG_BUGON(1); - return -EFSCORRUPTED; - } - goto tailpacking; + if (!(map->m_flags & EROFS_MAP_META)) { + grp =3D erofs_find_workgroup(fe->inode->i_sb, + map->m_pa >> PAGE_SHIFT); + } else if ((map->m_pa & ~PAGE_MASK) + map->m_plen > PAGE_SIZE) { + DBG_BUGON(1); + return -EFSCORRUPTED; } =20 - grp =3D erofs_find_workgroup(fe->inode->i_sb, map->m_pa >> PAGE_SHIFT); if (grp) { fe->pcl =3D container_of(grp, struct z_erofs_pcluster, obj); + ret =3D -EEXIST; } else { -tailpacking: ret =3D z_erofs_register_pcluster(fe); - if (!ret) - goto out; - if (ret !=3D -EEXIST) - return ret; } =20 - ret =3D z_erofs_lookup_pcluster(fe); - if (ret) { - erofs_workgroup_put(&fe->pcl->obj); + if (ret =3D=3D -EEXIST) { + ret =3D z_erofs_lookup_pcluster(fe); + if (ret) { + erofs_workgroup_put(&fe->pcl->obj); + return ret; + } + } else if (ret) { return ret; } =20 -out: z_erofs_pagevec_ctor_init(&fe->vector, Z_EROFS_NR_INLINE_PAGEVECS, fe->pcl->pagevec, fe->pcl->vcnt); /* since file-backed online pages are traversed in reverse order */ --=20 2.24.4 From nobody Sat Apr 18 10:52:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6714AC43334 for ; Thu, 14 Jul 2022 13:21:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239764AbiGNNVY (ORCPT ); Thu, 14 Jul 2022 09:21:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239727AbiGNNVI (ORCPT ); Thu, 14 Jul 2022 09:21:08 -0400 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19A015D5A4 for ; Thu, 14 Jul 2022 06:21:06 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R331e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046050;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VJJkPG0_1657804862; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJJkPG0_1657804862) by smtp.aliyun-inc.com; Thu, 14 Jul 2022 21:21:03 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang Subject: [PATCH 03/16] erofs: introduce `z_erofs_parse_out_bvecs()' Date: Thu, 14 Jul 2022 21:20:38 +0800 Message-Id: <20220714132051.46012-4-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> References: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" `z_erofs_decompress_pcluster()' is too long therefore it'd be better to introduce another helper to parse decompressed pages (or laterly, decompressed bvecs.) BTW, since `decompressed_bvecs' is too long as a part of the function name, `out_bvecs' is used instead. Signed-off-by: Gao Xiang Reviewed-by: Yue Hu --- fs/erofs/zdata.c | 81 +++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 38 deletions(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index c7be447ac64d..c183cd0bc42b 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -778,18 +778,58 @@ static bool z_erofs_page_is_invalidated(struct page *= page) return !page->mapping && !z_erofs_is_shortlived_page(page); } =20 +static int z_erofs_parse_out_bvecs(struct z_erofs_pcluster *pcl, + struct page **pages, struct page **pagepool) +{ + struct z_erofs_pagevec_ctor ctor; + enum z_erofs_page_type page_type; + int i, err =3D 0; + + z_erofs_pagevec_ctor_init(&ctor, Z_EROFS_NR_INLINE_PAGEVECS, + pcl->pagevec, 0); + for (i =3D 0; i < pcl->vcnt; ++i) { + struct page *page =3D z_erofs_pagevec_dequeue(&ctor, &page_type); + unsigned int pagenr; + + /* all pages in pagevec ought to be valid */ + DBG_BUGON(!page); + DBG_BUGON(z_erofs_page_is_invalidated(page)); + + if (z_erofs_put_shortlivedpage(pagepool, page)) + continue; + + if (page_type =3D=3D Z_EROFS_VLE_PAGE_TYPE_HEAD) + pagenr =3D 0; + else + pagenr =3D z_erofs_onlinepage_index(page); + + DBG_BUGON(pagenr >=3D pcl->nr_pages); + /* + * currently EROFS doesn't support multiref(dedup), + * so here erroring out one multiref page. + */ + if (pages[pagenr]) { + DBG_BUGON(1); + SetPageError(pages[pagenr]); + z_erofs_onlinepage_endio(pages[pagenr]); + err =3D -EFSCORRUPTED; + } + pages[pagenr] =3D page; + } + z_erofs_pagevec_ctor_exit(&ctor, true); + return err; +} + static int z_erofs_decompress_pcluster(struct super_block *sb, struct z_erofs_pcluster *pcl, struct page **pagepool) { struct erofs_sb_info *const sbi =3D EROFS_SB(sb); unsigned int pclusterpages =3D z_erofs_pclusterpages(pcl); - struct z_erofs_pagevec_ctor ctor; unsigned int i, inputsize, outputsize, llen, nr_pages; struct page *pages_onstack[Z_EROFS_VMAP_ONSTACK_PAGES]; struct page **pages, **compressed_pages, *page; =20 - enum z_erofs_page_type page_type; bool overlapped, partial; int err; =20 @@ -823,42 +863,7 @@ static int z_erofs_decompress_pcluster(struct super_bl= ock *sb, for (i =3D 0; i < nr_pages; ++i) pages[i] =3D NULL; =20 - err =3D 0; - z_erofs_pagevec_ctor_init(&ctor, Z_EROFS_NR_INLINE_PAGEVECS, - pcl->pagevec, 0); - - for (i =3D 0; i < pcl->vcnt; ++i) { - unsigned int pagenr; - - page =3D z_erofs_pagevec_dequeue(&ctor, &page_type); - - /* all pages in pagevec ought to be valid */ - DBG_BUGON(!page); - DBG_BUGON(z_erofs_page_is_invalidated(page)); - - if (z_erofs_put_shortlivedpage(pagepool, page)) - continue; - - if (page_type =3D=3D Z_EROFS_VLE_PAGE_TYPE_HEAD) - pagenr =3D 0; - else - pagenr =3D z_erofs_onlinepage_index(page); - - DBG_BUGON(pagenr >=3D nr_pages); - - /* - * currently EROFS doesn't support multiref(dedup), - * so here erroring out one multiref page. - */ - if (pages[pagenr]) { - DBG_BUGON(1); - SetPageError(pages[pagenr]); - z_erofs_onlinepage_endio(pages[pagenr]); - err =3D -EFSCORRUPTED; - } - pages[pagenr] =3D page; - } - z_erofs_pagevec_ctor_exit(&ctor, true); + err =3D z_erofs_parse_out_bvecs(pcl, pages, pagepool); =20 overlapped =3D false; compressed_pages =3D pcl->compressed_pages; --=20 2.24.4 From nobody Sat Apr 18 10:52:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE252C433EF for ; Thu, 14 Jul 2022 13:21:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239774AbiGNNV0 (ORCPT ); Thu, 14 Jul 2022 09:21:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239731AbiGNNVJ (ORCPT ); Thu, 14 Jul 2022 09:21:09 -0400 Received: from out30-42.freemail.mail.aliyun.com (out30-42.freemail.mail.aliyun.com [115.124.30.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD8805E33F for ; Thu, 14 Jul 2022 06:21:07 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046060;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VJJkPH4_1657804863; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJJkPH4_1657804863) by smtp.aliyun-inc.com; Thu, 14 Jul 2022 21:21:04 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang Subject: [PATCH 04/16] erofs: introduce bufvec to store decompressed buffers Date: Thu, 14 Jul 2022 21:20:39 +0800 Message-Id: <20220714132051.46012-5-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> References: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" For each pcluster, the total compressed buffers are determined in advance, yet the number of decompressed buffers actually vary. Too many decompressed pages can be recorded if one pcluster is highly compressed or its pcluster size is large. That takes extra memory footprints compared to uncompressed filesystems, especially a lot of I/O in flight on low-ended devices. Therefore, similar to inplace I/O, pagevec was introduced to reuse page cache to store these pointers in the time-sharing way since these pages are actually unused before decompressing. In order to make it more flexable, a cleaner bufvec is used to replace the old pagevec stuffs so that - Decompressed offsets can be stored inline, thus it can be used for the upcoming feature like compressed data deduplication; - Towards supporting large folios for compressed inodes since our final goal is to completely avoid page->private but use folio->private only for all page cache pages. Signed-off-by: Gao Xiang --- fs/erofs/zdata.c | 177 +++++++++++++++++++++++++++++++++++------------ fs/erofs/zdata.h | 26 +++++-- 2 files changed, 153 insertions(+), 50 deletions(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index c183cd0bc42b..f52c54058f31 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -2,6 +2,7 @@ /* * Copyright (C) 2018 HUAWEI, Inc. * https://www.huawei.com/ + * Copyright (C) 2022 Alibaba Cloud */ #include "zdata.h" #include "compress.h" @@ -26,6 +27,82 @@ static struct z_erofs_pcluster_slab pcluster_pool[] __re= ad_mostly =3D { _PCLP(Z_EROFS_PCLUSTER_MAX_PAGES) }; =20 +struct z_erofs_bvec_iter { + struct page *bvpage; + struct z_erofs_bvset *bvset; + unsigned int nr, cur; +}; + +static struct page *z_erofs_bvec_iter_end(struct z_erofs_bvec_iter *iter) +{ + if (iter->bvpage) + kunmap_local(iter->bvset); + return iter->bvpage; +} + +static struct page *z_erofs_bvset_flip(struct z_erofs_bvec_iter *iter) +{ + unsigned long base =3D (unsigned long)((struct z_erofs_bvset *)0)->bvec; + /* have to access nextpage in advance, otherwise it will be unmapped */ + struct page *nextpage =3D iter->bvset->nextpage; + struct page *oldpage; + + DBG_BUGON(!nextpage); + oldpage =3D z_erofs_bvec_iter_end(iter); + iter->bvpage =3D nextpage; + iter->bvset =3D kmap_local_page(nextpage); + iter->nr =3D (PAGE_SIZE - base) / sizeof(struct z_erofs_bvec); + iter->cur =3D 0; + return oldpage; +} + +static void z_erofs_bvec_iter_begin(struct z_erofs_bvec_iter *iter, + struct z_erofs_bvset_inline *bvset, + unsigned int bootstrap_nr, + unsigned int cur) +{ + *iter =3D (struct z_erofs_bvec_iter) { + .nr =3D bootstrap_nr, + .bvset =3D (struct z_erofs_bvset *)bvset, + }; + + while (cur > iter->nr) { + cur -=3D iter->nr; + z_erofs_bvset_flip(iter); + } + iter->cur =3D cur; +} + +static int z_erofs_bvec_enqueue(struct z_erofs_bvec_iter *iter, + struct z_erofs_bvec *bvec, + struct page **candidate_bvpage) +{ + if (iter->cur =3D=3D iter->nr) { + if (!*candidate_bvpage) + return -EAGAIN; + + DBG_BUGON(iter->bvset->nextpage); + iter->bvset->nextpage =3D *candidate_bvpage; + z_erofs_bvset_flip(iter); + + iter->bvset->nextpage =3D NULL; + *candidate_bvpage =3D NULL; + } + iter->bvset->bvec[iter->cur++] =3D *bvec; + return 0; +} + +static void z_erofs_bvec_dequeue(struct z_erofs_bvec_iter *iter, + struct z_erofs_bvec *bvec, + struct page **old_bvpage) +{ + if (iter->cur =3D=3D iter->nr) + *old_bvpage =3D z_erofs_bvset_flip(iter); + else + *old_bvpage =3D NULL; + *bvec =3D iter->bvset->bvec[iter->cur++]; +} + static void z_erofs_destroy_pcluster_pool(void) { int i; @@ -195,9 +272,10 @@ enum z_erofs_collectmode { struct z_erofs_decompress_frontend { struct inode *const inode; struct erofs_map_blocks map; - + struct z_erofs_bvec_iter biter; struct z_erofs_pagevec_ctor vector; =20 + struct page *candidate_bvpage; struct z_erofs_pcluster *pcl, *tailpcl; /* a pointer used to pick up inplace I/O pages */ struct page **icpage_ptr; @@ -358,21 +436,24 @@ static bool z_erofs_try_inplace_io(struct z_erofs_dec= ompress_frontend *fe, =20 /* callers must be with pcluster lock held */ static int z_erofs_attach_page(struct z_erofs_decompress_frontend *fe, - struct page *page, enum z_erofs_page_type type, - bool pvec_safereuse) + struct z_erofs_bvec *bvec, + enum z_erofs_page_type type) { int ret; =20 - /* give priority for inplaceio */ if (fe->mode >=3D COLLECT_PRIMARY && - type =3D=3D Z_EROFS_PAGE_TYPE_EXCLUSIVE && - z_erofs_try_inplace_io(fe, page)) - return 0; - - ret =3D z_erofs_pagevec_enqueue(&fe->vector, page, type, - pvec_safereuse); - fe->pcl->vcnt +=3D (unsigned int)ret; - return ret ? 0 : -EAGAIN; + type =3D=3D Z_EROFS_PAGE_TYPE_EXCLUSIVE) { + /* give priority for inplaceio to use file pages first */ + if (z_erofs_try_inplace_io(fe, bvec->page)) + return 0; + /* otherwise, check if it can be used as a bvpage */ + if (fe->mode >=3D COLLECT_PRIMARY_FOLLOWED && + !fe->candidate_bvpage) + fe->candidate_bvpage =3D bvec->page; + } + ret =3D z_erofs_bvec_enqueue(&fe->biter, bvec, &fe->candidate_bvpage); + fe->pcl->vcnt +=3D (ret >=3D 0); + return ret; } =20 static void z_erofs_try_to_claim_pcluster(struct z_erofs_decompress_fronte= nd *f) @@ -554,9 +635,8 @@ static int z_erofs_collector_begin(struct z_erofs_decom= press_frontend *fe) } else if (ret) { return ret; } - - z_erofs_pagevec_ctor_init(&fe->vector, Z_EROFS_NR_INLINE_PAGEVECS, - fe->pcl->pagevec, fe->pcl->vcnt); + z_erofs_bvec_iter_begin(&fe->biter, &fe->pcl->bvset, + Z_EROFS_NR_INLINE_PAGEVECS, fe->pcl->vcnt); /* since file-backed online pages are traversed in reverse order */ fe->icpage_ptr =3D fe->pcl->compressed_pages + z_erofs_pclusterpages(fe->pcl); @@ -588,9 +668,14 @@ static bool z_erofs_collector_end(struct z_erofs_decom= press_frontend *fe) if (!pcl) return false; =20 - z_erofs_pagevec_ctor_exit(&fe->vector, false); + z_erofs_bvec_iter_end(&fe->biter); mutex_unlock(&pcl->lock); =20 + if (fe->candidate_bvpage) { + DBG_BUGON(z_erofs_is_shortlived_page(fe->candidate_bvpage)); + fe->candidate_bvpage =3D NULL; + } + /* * if all pending pages are added, don't hold its reference * any longer if the pcluster isn't hosted by ourselves. @@ -712,22 +797,23 @@ static int z_erofs_do_read_page(struct z_erofs_decomp= ress_frontend *fe, tight &=3D (fe->mode >=3D COLLECT_PRIMARY_FOLLOWED); =20 retry: - err =3D z_erofs_attach_page(fe, page, page_type, - fe->mode >=3D COLLECT_PRIMARY_FOLLOWED); - /* should allocate an additional short-lived page for pagevec */ - if (err =3D=3D -EAGAIN) { - struct page *const newpage =3D - alloc_page(GFP_NOFS | __GFP_NOFAIL); - - set_page_private(newpage, Z_EROFS_SHORTLIVED_PAGE); - err =3D z_erofs_attach_page(fe, newpage, - Z_EROFS_PAGE_TYPE_EXCLUSIVE, true); - if (!err) - goto retry; + err =3D z_erofs_attach_page(fe, &((struct z_erofs_bvec) { + .page =3D page, + .offset =3D offset - map->m_la, + .end =3D end, + }), page_type); + /* should allocate an additional short-lived page for bvset */ + if (err =3D=3D -EAGAIN && !fe->candidate_bvpage) { + fe->candidate_bvpage =3D alloc_page(GFP_NOFS | __GFP_NOFAIL); + set_page_private(fe->candidate_bvpage, + Z_EROFS_SHORTLIVED_PAGE); + goto retry; } =20 - if (err) + if (err) { + DBG_BUGON(err =3D=3D -EAGAIN && fe->candidate_bvpage); goto err_out; + } =20 index =3D page->index - (map->m_la >> PAGE_SHIFT); =20 @@ -781,29 +867,24 @@ static bool z_erofs_page_is_invalidated(struct page *= page) static int z_erofs_parse_out_bvecs(struct z_erofs_pcluster *pcl, struct page **pages, struct page **pagepool) { - struct z_erofs_pagevec_ctor ctor; - enum z_erofs_page_type page_type; + struct z_erofs_bvec_iter biter; + struct page *old_bvpage; int i, err =3D 0; =20 - z_erofs_pagevec_ctor_init(&ctor, Z_EROFS_NR_INLINE_PAGEVECS, - pcl->pagevec, 0); + z_erofs_bvec_iter_begin(&biter, &pcl->bvset, + Z_EROFS_NR_INLINE_PAGEVECS, 0); for (i =3D 0; i < pcl->vcnt; ++i) { - struct page *page =3D z_erofs_pagevec_dequeue(&ctor, &page_type); + struct z_erofs_bvec bvec; unsigned int pagenr; =20 - /* all pages in pagevec ought to be valid */ - DBG_BUGON(!page); - DBG_BUGON(z_erofs_page_is_invalidated(page)); - - if (z_erofs_put_shortlivedpage(pagepool, page)) - continue; + z_erofs_bvec_dequeue(&biter, &bvec, &old_bvpage); =20 - if (page_type =3D=3D Z_EROFS_VLE_PAGE_TYPE_HEAD) - pagenr =3D 0; - else - pagenr =3D z_erofs_onlinepage_index(page); + if (old_bvpage) + z_erofs_put_shortlivedpage(pagepool, old_bvpage); =20 + pagenr =3D (bvec.offset + pcl->pageofs_out) >> PAGE_SHIFT; DBG_BUGON(pagenr >=3D pcl->nr_pages); + DBG_BUGON(z_erofs_page_is_invalidated(bvec.page)); /* * currently EROFS doesn't support multiref(dedup), * so here erroring out one multiref page. @@ -814,9 +895,12 @@ static int z_erofs_parse_out_bvecs(struct z_erofs_pclu= ster *pcl, z_erofs_onlinepage_endio(pages[pagenr]); err =3D -EFSCORRUPTED; } - pages[pagenr] =3D page; + pages[pagenr] =3D bvec.page; } - z_erofs_pagevec_ctor_exit(&ctor, true); + + old_bvpage =3D z_erofs_bvec_iter_end(&biter); + if (old_bvpage) + z_erofs_put_shortlivedpage(pagepool, old_bvpage); return err; } =20 @@ -986,6 +1070,7 @@ static int z_erofs_decompress_pcluster(struct super_bl= ock *sb, kvfree(pages); =20 pcl->nr_pages =3D 0; + pcl->bvset.nextpage =3D NULL; pcl->vcnt =3D 0; =20 /* pcluster lock MUST be taken before the following line */ diff --git a/fs/erofs/zdata.h b/fs/erofs/zdata.h index 58053bb5066f..d03e333e4fde 100644 --- a/fs/erofs/zdata.h +++ b/fs/erofs/zdata.h @@ -21,6 +21,21 @@ */ typedef void *z_erofs_next_pcluster_t; =20 +struct z_erofs_bvec { + struct page *page; + int offset; + unsigned int end; +}; + +#define __Z_EROFS_BVSET(name, total) \ +struct name { \ + /* point to the next page which contains the following bvecs */ \ + struct page *nextpage; \ + struct z_erofs_bvec bvec[total]; \ +} +__Z_EROFS_BVSET(z_erofs_bvset,); +__Z_EROFS_BVSET(z_erofs_bvset_inline, Z_EROFS_NR_INLINE_PAGEVECS); + /* * Structure fields follow one of the following exclusion rules. * @@ -41,22 +56,25 @@ struct z_erofs_pcluster { /* A: lower limit of decompressed length and if full length or not */ unsigned int length; =20 + /* L: total number of bvecs */ + unsigned int vcnt; + /* I: page offset of start position of decompression */ unsigned short pageofs_out; =20 /* I: page offset of inline compressed data */ unsigned short pageofs_in; =20 - /* L: maximum relative page index in pagevec[] */ + /* L: maximum relative page index in bvecs */ unsigned short nr_pages; =20 - /* L: total number of pages in pagevec[] */ - unsigned int vcnt; - union { /* L: inline a certain number of pagevecs for bootstrap */ erofs_vtptr_t pagevec[Z_EROFS_NR_INLINE_PAGEVECS]; =20 + /* L: inline a certain number of bvec for bootstrap */ + struct z_erofs_bvset_inline bvset; + /* I: can be used to free the pcluster by RCU. */ struct rcu_head rcu; }; --=20 2.24.4 From nobody Sat Apr 18 10:52:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30ED3C433EF for ; Thu, 14 Jul 2022 13:21:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239816AbiGNNVo (ORCPT ); Thu, 14 Jul 2022 09:21:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239751AbiGNNVK (ORCPT ); Thu, 14 Jul 2022 09:21:10 -0400 Received: from out30-45.freemail.mail.aliyun.com (out30-45.freemail.mail.aliyun.com [115.124.30.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 767CC5E307 for ; Thu, 14 Jul 2022 06:21:09 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04400;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VJJkPHv_1657804865; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJJkPHv_1657804865) by smtp.aliyun-inc.com; Thu, 14 Jul 2022 21:21:06 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang Subject: [PATCH 05/16] erofs: drop the old pagevec approach Date: Thu, 14 Jul 2022 21:20:40 +0800 Message-Id: <20220714132051.46012-6-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> References: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Remove the old pagevec approach but keep z_erofs_page_type for now. It will be reworked in the following commits as well. Also rename Z_EROFS_NR_INLINE_PAGEVECS as Z_EROFS_INLINE_BVECS with the new value 2 since it's actually enough to bootstrap. Signed-off-by: Gao Xiang --- fs/erofs/zdata.c | 17 +++-- fs/erofs/zdata.h | 9 +-- fs/erofs/zpvec.h | 159 ----------------------------------------------- 3 files changed, 16 insertions(+), 169 deletions(-) delete mode 100644 fs/erofs/zpvec.h diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index f52c54058f31..e96704db106e 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -27,6 +27,17 @@ static struct z_erofs_pcluster_slab pcluster_pool[] __re= ad_mostly =3D { _PCLP(Z_EROFS_PCLUSTER_MAX_PAGES) }; =20 +/* page type in pagevec for decompress subsystem */ +enum z_erofs_page_type { + /* including Z_EROFS_VLE_PAGE_TAIL_EXCLUSIVE */ + Z_EROFS_PAGE_TYPE_EXCLUSIVE, + + Z_EROFS_VLE_PAGE_TYPE_TAIL_SHARED, + + Z_EROFS_VLE_PAGE_TYPE_HEAD, + Z_EROFS_VLE_PAGE_TYPE_MAX +}; + struct z_erofs_bvec_iter { struct page *bvpage; struct z_erofs_bvset *bvset; @@ -273,7 +284,6 @@ struct z_erofs_decompress_frontend { struct inode *const inode; struct erofs_map_blocks map; struct z_erofs_bvec_iter biter; - struct z_erofs_pagevec_ctor vector; =20 struct page *candidate_bvpage; struct z_erofs_pcluster *pcl, *tailpcl; @@ -636,7 +646,7 @@ static int z_erofs_collector_begin(struct z_erofs_decom= press_frontend *fe) return ret; } z_erofs_bvec_iter_begin(&fe->biter, &fe->pcl->bvset, - Z_EROFS_NR_INLINE_PAGEVECS, fe->pcl->vcnt); + Z_EROFS_INLINE_BVECS, fe->pcl->vcnt); /* since file-backed online pages are traversed in reverse order */ fe->icpage_ptr =3D fe->pcl->compressed_pages + z_erofs_pclusterpages(fe->pcl); @@ -871,8 +881,7 @@ static int z_erofs_parse_out_bvecs(struct z_erofs_pclus= ter *pcl, struct page *old_bvpage; int i, err =3D 0; =20 - z_erofs_bvec_iter_begin(&biter, &pcl->bvset, - Z_EROFS_NR_INLINE_PAGEVECS, 0); + z_erofs_bvec_iter_begin(&biter, &pcl->bvset, Z_EROFS_INLINE_BVECS, 0); for (i =3D 0; i < pcl->vcnt; ++i) { struct z_erofs_bvec bvec; unsigned int pagenr; diff --git a/fs/erofs/zdata.h b/fs/erofs/zdata.h index d03e333e4fde..a755c5a44d87 100644 --- a/fs/erofs/zdata.h +++ b/fs/erofs/zdata.h @@ -7,10 +7,10 @@ #define __EROFS_FS_ZDATA_H =20 #include "internal.h" -#include "zpvec.h" +#include "tagptr.h" =20 #define Z_EROFS_PCLUSTER_MAX_PAGES (Z_EROFS_PCLUSTER_MAX_SIZE / PAGE_SIZE) -#define Z_EROFS_NR_INLINE_PAGEVECS 3 +#define Z_EROFS_INLINE_BVECS 2 =20 #define Z_EROFS_PCLUSTER_FULL_LENGTH 0x00000001 #define Z_EROFS_PCLUSTER_LENGTH_BIT 1 @@ -34,7 +34,7 @@ struct name { \ struct z_erofs_bvec bvec[total]; \ }; __Z_EROFS_BVSET(z_erofs_bvset,) -__Z_EROFS_BVSET(z_erofs_bvset_inline, Z_EROFS_NR_INLINE_PAGEVECS) +__Z_EROFS_BVSET(z_erofs_bvset_inline, Z_EROFS_INLINE_BVECS) =20 /* * Structure fields follow one of the following exclusion rules. @@ -69,9 +69,6 @@ struct z_erofs_pcluster { unsigned short nr_pages; =20 union { - /* L: inline a certain number of pagevecs for bootstrap */ - erofs_vtptr_t pagevec[Z_EROFS_NR_INLINE_PAGEVECS]; - /* L: inline a certain number of bvec for bootstrap */ struct z_erofs_bvset_inline bvset; =20 diff --git a/fs/erofs/zpvec.h b/fs/erofs/zpvec.h deleted file mode 100644 index b05464f4a808..000000000000 --- a/fs/erofs/zpvec.h +++ /dev/null @@ -1,159 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* - * Copyright (C) 2018 HUAWEI, Inc. - * https://www.huawei.com/ - */ -#ifndef __EROFS_FS_ZPVEC_H -#define __EROFS_FS_ZPVEC_H - -#include "tagptr.h" - -/* page type in pagevec for decompress subsystem */ -enum z_erofs_page_type { - /* including Z_EROFS_VLE_PAGE_TAIL_EXCLUSIVE */ - Z_EROFS_PAGE_TYPE_EXCLUSIVE, - - Z_EROFS_VLE_PAGE_TYPE_TAIL_SHARED, - - Z_EROFS_VLE_PAGE_TYPE_HEAD, - Z_EROFS_VLE_PAGE_TYPE_MAX -}; - -extern void __compiletime_error("Z_EROFS_PAGE_TYPE_EXCLUSIVE !=3D 0") - __bad_page_type_exclusive(void); - -/* pagevec tagged pointer */ -typedef tagptr2_t erofs_vtptr_t; - -/* pagevec collector */ -struct z_erofs_pagevec_ctor { - struct page *curr, *next; - erofs_vtptr_t *pages; - - unsigned int nr, index; -}; - -static inline void z_erofs_pagevec_ctor_exit(struct z_erofs_pagevec_ctor *= ctor, - bool atomic) -{ - if (!ctor->curr) - return; - - if (atomic) - kunmap_atomic(ctor->pages); - else - kunmap(ctor->curr); -} - -static inline struct page * -z_erofs_pagevec_ctor_next_page(struct z_erofs_pagevec_ctor *ctor, - unsigned int nr) -{ - unsigned int index; - - /* keep away from occupied pages */ - if (ctor->next) - return ctor->next; - - for (index =3D 0; index < nr; ++index) { - const erofs_vtptr_t t =3D ctor->pages[index]; - const unsigned int tags =3D tagptr_unfold_tags(t); - - if (tags =3D=3D Z_EROFS_PAGE_TYPE_EXCLUSIVE) - return tagptr_unfold_ptr(t); - } - DBG_BUGON(nr >=3D ctor->nr); - return NULL; -} - -static inline void -z_erofs_pagevec_ctor_pagedown(struct z_erofs_pagevec_ctor *ctor, - bool atomic) -{ - struct page *next =3D z_erofs_pagevec_ctor_next_page(ctor, ctor->nr); - - z_erofs_pagevec_ctor_exit(ctor, atomic); - - ctor->curr =3D next; - ctor->next =3D NULL; - ctor->pages =3D atomic ? - kmap_atomic(ctor->curr) : kmap(ctor->curr); - - ctor->nr =3D PAGE_SIZE / sizeof(struct page *); - ctor->index =3D 0; -} - -static inline void z_erofs_pagevec_ctor_init(struct z_erofs_pagevec_ctor *= ctor, - unsigned int nr, - erofs_vtptr_t *pages, - unsigned int i) -{ - ctor->nr =3D nr; - ctor->curr =3D ctor->next =3D NULL; - ctor->pages =3D pages; - - if (i >=3D nr) { - i -=3D nr; - z_erofs_pagevec_ctor_pagedown(ctor, false); - while (i > ctor->nr) { - i -=3D ctor->nr; - z_erofs_pagevec_ctor_pagedown(ctor, false); - } - } - ctor->next =3D z_erofs_pagevec_ctor_next_page(ctor, i); - ctor->index =3D i; -} - -static inline bool z_erofs_pagevec_enqueue(struct z_erofs_pagevec_ctor *ct= or, - struct page *page, - enum z_erofs_page_type type, - bool pvec_safereuse) -{ - if (!ctor->next) { - /* some pages cannot be reused as pvec safely without I/O */ - if (type =3D=3D Z_EROFS_PAGE_TYPE_EXCLUSIVE && !pvec_safereuse) - type =3D Z_EROFS_VLE_PAGE_TYPE_TAIL_SHARED; - - if (type !=3D Z_EROFS_PAGE_TYPE_EXCLUSIVE && - ctor->index + 1 =3D=3D ctor->nr) - return false; - } - - if (ctor->index >=3D ctor->nr) - z_erofs_pagevec_ctor_pagedown(ctor, false); - - /* exclusive page type must be 0 */ - if (Z_EROFS_PAGE_TYPE_EXCLUSIVE !=3D (uintptr_t)NULL) - __bad_page_type_exclusive(); - - /* should remind that collector->next never equal to 1, 2 */ - if (type =3D=3D (uintptr_t)ctor->next) { - ctor->next =3D page; - } - ctor->pages[ctor->index++] =3D tagptr_fold(erofs_vtptr_t, page, type); - return true; -} - -static inline struct page * -z_erofs_pagevec_dequeue(struct z_erofs_pagevec_ctor *ctor, - enum z_erofs_page_type *type) -{ - erofs_vtptr_t t; - - if (ctor->index >=3D ctor->nr) { - DBG_BUGON(!ctor->next); - z_erofs_pagevec_ctor_pagedown(ctor, true); - } - - t =3D ctor->pages[ctor->index]; - - *type =3D tagptr_unfold_tags(t); - - /* should remind that collector->next never equal to 1, 2 */ - if (*type =3D=3D (uintptr_t)ctor->next) - ctor->next =3D tagptr_unfold_ptr(t); - - ctor->pages[ctor->index++] =3D tagptr_fold(erofs_vtptr_t, NULL, 0); - return tagptr_unfold_ptr(t); -} -#endif --=20 2.24.4 From nobody Sat Apr 18 10:52:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3DC24C433EF for ; Thu, 14 Jul 2022 13:21:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230468AbiGNNVb (ORCPT ); Thu, 14 Jul 2022 09:21:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239757AbiGNNVM (ORCPT ); Thu, 14 Jul 2022 09:21:12 -0400 Received: from out30-45.freemail.mail.aliyun.com (out30-45.freemail.mail.aliyun.com [115.124.30.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1853A5D0C0 for ; Thu, 14 Jul 2022 06:21:10 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R811e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045170;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VJJkPIs_1657804866; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJJkPIs_1657804866) by smtp.aliyun-inc.com; Thu, 14 Jul 2022 21:21:07 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang Subject: [PATCH 06/16] erofs: introduce `z_erofs_parse_in_bvecs' Date: Thu, 14 Jul 2022 21:20:41 +0800 Message-Id: <20220714132051.46012-7-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> References: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" `z_erofs_decompress_pcluster()' is too long therefore it'd be better to introduce another helper to parse compressed pages (or laterly, compressed bvecs.) BTW, since `compressed_bvecs' is too long as a part of the function name, `in_bvecs' is used here instead. Signed-off-by: Gao Xiang --- fs/erofs/zdata.c | 132 ++++++++++++++++++++++++++++------------------- 1 file changed, 80 insertions(+), 52 deletions(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index e96704db106e..757d352bc2c7 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -913,6 +913,76 @@ static int z_erofs_parse_out_bvecs(struct z_erofs_pclu= ster *pcl, return err; } =20 +static struct page **z_erofs_parse_in_bvecs(struct erofs_sb_info *sbi, + struct z_erofs_pcluster *pcl, struct page **pages, + struct page **pagepool, bool *overlapped) +{ + unsigned int pclusterpages =3D z_erofs_pclusterpages(pcl); + struct page **compressed_pages; + int i, err =3D 0; + + /* XXX: will have a better approach in the following commits */ + compressed_pages =3D kmalloc_array(pclusterpages, sizeof(struct page *), + GFP_KERNEL | __GFP_NOFAIL); + *overlapped =3D false; + + for (i =3D 0; i < pclusterpages; ++i) { + unsigned int pagenr; + struct page *page =3D pcl->compressed_pages[i]; + + /* compressed pages ought to be present before decompressing */ + if (!page) { + DBG_BUGON(1); + continue; + } + compressed_pages[i] =3D page; + + if (z_erofs_is_inline_pcluster(pcl)) { + if (!PageUptodate(page)) + err =3D -EIO; + continue; + } + + DBG_BUGON(z_erofs_page_is_invalidated(page)); + if (!z_erofs_is_shortlived_page(page)) { + if (erofs_page_is_managed(sbi, page)) { + if (!PageUptodate(page)) + err =3D -EIO; + continue; + } + + /* + * only if non-head page can be selected + * for inplace decompression + */ + pagenr =3D z_erofs_onlinepage_index(page); + + DBG_BUGON(pagenr >=3D pcl->nr_pages); + if (pages[pagenr]) { + DBG_BUGON(1); + SetPageError(pages[pagenr]); + z_erofs_onlinepage_endio(pages[pagenr]); + err =3D -EFSCORRUPTED; + } + pages[pagenr] =3D page; + + *overlapped =3D true; + } + + /* PG_error needs checking for all non-managed pages */ + if (PageError(page)) { + DBG_BUGON(PageUptodate(page)); + err =3D -EIO; + } + } + + if (err) { + kfree(compressed_pages); + return ERR_PTR(err); + } + return compressed_pages; +} + static int z_erofs_decompress_pcluster(struct super_block *sb, struct z_erofs_pcluster *pcl, struct page **pagepool) @@ -957,54 +1027,11 @@ static int z_erofs_decompress_pcluster(struct super_= block *sb, pages[i] =3D NULL; =20 err =3D z_erofs_parse_out_bvecs(pcl, pages, pagepool); - - overlapped =3D false; - compressed_pages =3D pcl->compressed_pages; - - for (i =3D 0; i < pclusterpages; ++i) { - unsigned int pagenr; - - page =3D compressed_pages[i]; - /* all compressed pages ought to be valid */ - DBG_BUGON(!page); - - if (z_erofs_is_inline_pcluster(pcl)) { - if (!PageUptodate(page)) - err =3D -EIO; - continue; - } - - DBG_BUGON(z_erofs_page_is_invalidated(page)); - if (!z_erofs_is_shortlived_page(page)) { - if (erofs_page_is_managed(sbi, page)) { - if (!PageUptodate(page)) - err =3D -EIO; - continue; - } - - /* - * only if non-head page can be selected - * for inplace decompression - */ - pagenr =3D z_erofs_onlinepage_index(page); - - DBG_BUGON(pagenr >=3D nr_pages); - if (pages[pagenr]) { - DBG_BUGON(1); - SetPageError(pages[pagenr]); - z_erofs_onlinepage_endio(pages[pagenr]); - err =3D -EFSCORRUPTED; - } - pages[pagenr] =3D page; - - overlapped =3D true; - } - - /* PG_error needs checking for all non-managed pages */ - if (PageError(page)) { - DBG_BUGON(PageUptodate(page)); - err =3D -EIO; - } + compressed_pages =3D z_erofs_parse_in_bvecs(sbi, pcl, pages, + pagepool, &overlapped); + if (IS_ERR(compressed_pages)) { + err =3D PTR_ERR(compressed_pages); + compressed_pages =3D NULL; } =20 if (err) @@ -1040,21 +1067,22 @@ static int z_erofs_decompress_pcluster(struct super= _block *sb, out: /* must handle all compressed pages before actual file pages */ if (z_erofs_is_inline_pcluster(pcl)) { - page =3D compressed_pages[0]; - WRITE_ONCE(compressed_pages[0], NULL); + page =3D pcl->compressed_pages[0]; + WRITE_ONCE(pcl->compressed_pages[0], NULL); put_page(page); } else { for (i =3D 0; i < pclusterpages; ++i) { - page =3D compressed_pages[i]; + page =3D pcl->compressed_pages[i]; =20 if (erofs_page_is_managed(sbi, page)) continue; =20 /* recycle all individual short-lived pages */ (void)z_erofs_put_shortlivedpage(pagepool, page); - WRITE_ONCE(compressed_pages[i], NULL); + WRITE_ONCE(pcl->compressed_pages[i], NULL); } } + kfree(compressed_pages); =20 for (i =3D 0; i < nr_pages; ++i) { page =3D pages[i]; --=20 2.24.4 From nobody Sat Apr 18 10:52:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5BEBCC433EF for ; Thu, 14 Jul 2022 13:21:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239369AbiGNNVk (ORCPT ); Thu, 14 Jul 2022 09:21:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239682AbiGNNVN (ORCPT ); Thu, 14 Jul 2022 09:21:13 -0400 Received: from out30-45.freemail.mail.aliyun.com (out30-45.freemail.mail.aliyun.com [115.124.30.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BB8C5D5A1 for ; Thu, 14 Jul 2022 06:21:11 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046060;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VJJkPJv_1657804868; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJJkPJv_1657804868) by smtp.aliyun-inc.com; Thu, 14 Jul 2022 21:21:09 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang Subject: [PATCH 07/16] erofs: switch compressed_pages[] to bufvec Date: Thu, 14 Jul 2022 21:20:42 +0800 Message-Id: <20220714132051.46012-8-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> References: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Convert compressed_pages[] to bufvec in order to avoid using page->private to keep onlinepage_index (decompressed offset) for inplace I/O pages. In the future, we only rely on folio->private to keep a countdown to unlock folios and set folio_uptodate. Signed-off-by: Gao Xiang --- fs/erofs/zdata.c | 113 +++++++++++++++++++++++------------------------ fs/erofs/zdata.h | 4 +- 2 files changed, 57 insertions(+), 60 deletions(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index 757d352bc2c7..f2e3f07baad7 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -134,7 +134,7 @@ static int z_erofs_create_pcluster_pool(void) =20 for (pcs =3D pcluster_pool; pcs < pcluster_pool + ARRAY_SIZE(pcluster_pool); ++pcs) { - size =3D struct_size(a, compressed_pages, pcs->maxpages); + size =3D struct_size(a, compressed_bvecs, pcs->maxpages); =20 sprintf(pcs->name, "erofs_pcluster-%u", pcs->maxpages); pcs->slab =3D kmem_cache_create(pcs->name, size, 0, @@ -287,16 +287,16 @@ struct z_erofs_decompress_frontend { =20 struct page *candidate_bvpage; struct z_erofs_pcluster *pcl, *tailpcl; - /* a pointer used to pick up inplace I/O pages */ - struct page **icpage_ptr; z_erofs_next_pcluster_t owned_head; - enum z_erofs_collectmode mode; =20 bool readahead; /* used for applying cache strategy on the fly */ bool backmost; erofs_off_t headoffset; + + /* a pointer used to pick up inplace I/O pages */ + unsigned int icur; }; =20 #define DECOMPRESS_FRONTEND_INIT(__i) { \ @@ -319,24 +319,21 @@ static void z_erofs_bind_cache(struct z_erofs_decompr= ess_frontend *fe, */ gfp_t gfp =3D (mapping_gfp_mask(mc) & ~__GFP_DIRECT_RECLAIM) | __GFP_NOMEMALLOC | __GFP_NORETRY | __GFP_NOWARN; - struct page **pages; - pgoff_t index; + unsigned int i; =20 if (fe->mode < COLLECT_PRIMARY_FOLLOWED) return; =20 - pages =3D pcl->compressed_pages; - index =3D pcl->obj.index; - for (; index < pcl->obj.index + pcl->pclusterpages; ++index, ++pages) { + for (i =3D 0; i < pcl->pclusterpages; ++i) { struct page *page; compressed_page_t t; struct page *newpage =3D NULL; =20 /* the compressed page was loaded before */ - if (READ_ONCE(*pages)) + if (READ_ONCE(pcl->compressed_bvecs[i].page)) continue; =20 - page =3D find_get_page(mc, index); + page =3D find_get_page(mc, pcl->obj.index + i); =20 if (page) { t =3D tag_compressed_page_justfound(page); @@ -357,7 +354,8 @@ static void z_erofs_bind_cache(struct z_erofs_decompres= s_frontend *fe, } } =20 - if (!cmpxchg_relaxed(pages, NULL, tagptr_cast_ptr(t))) + if (!cmpxchg_relaxed(&pcl->compressed_bvecs[i].page, NULL, + tagptr_cast_ptr(t))) continue; =20 if (page) @@ -388,7 +386,7 @@ int erofs_try_to_free_all_cached_pages(struct erofs_sb_= info *sbi, * therefore no need to worry about available decompression users. */ for (i =3D 0; i < pcl->pclusterpages; ++i) { - struct page *page =3D pcl->compressed_pages[i]; + struct page *page =3D pcl->compressed_bvecs[i].page; =20 if (!page) continue; @@ -401,7 +399,7 @@ int erofs_try_to_free_all_cached_pages(struct erofs_sb_= info *sbi, continue; =20 /* barrier is implied in the following 'unlock_page' */ - WRITE_ONCE(pcl->compressed_pages[i], NULL); + WRITE_ONCE(pcl->compressed_bvecs[i].page, NULL); detach_page_private(page); unlock_page(page); } @@ -411,36 +409,39 @@ int erofs_try_to_free_all_cached_pages(struct erofs_s= b_info *sbi, int erofs_try_to_free_cached_page(struct page *page) { struct z_erofs_pcluster *const pcl =3D (void *)page_private(page); - int ret =3D 0; /* 0 - busy */ + int ret, i; =20 - if (erofs_workgroup_try_to_freeze(&pcl->obj, 1)) { - unsigned int i; + if (!erofs_workgroup_try_to_freeze(&pcl->obj, 1)) + return 0; =20 - DBG_BUGON(z_erofs_is_inline_pcluster(pcl)); - for (i =3D 0; i < pcl->pclusterpages; ++i) { - if (pcl->compressed_pages[i] =3D=3D page) { - WRITE_ONCE(pcl->compressed_pages[i], NULL); - ret =3D 1; - break; - } + ret =3D 0; + DBG_BUGON(z_erofs_is_inline_pcluster(pcl)); + for (i =3D 0; i < pcl->pclusterpages; ++i) { + if (pcl->compressed_bvecs[i].page =3D=3D page) { + WRITE_ONCE(pcl->compressed_bvecs[i].page, NULL); + ret =3D 1; + break; } - erofs_workgroup_unfreeze(&pcl->obj, 1); - - if (ret) - detach_page_private(page); } + erofs_workgroup_unfreeze(&pcl->obj, 1); + if (ret) + detach_page_private(page); return ret; } =20 /* page_type must be Z_EROFS_PAGE_TYPE_EXCLUSIVE */ static bool z_erofs_try_inplace_io(struct z_erofs_decompress_frontend *fe, - struct page *page) + struct z_erofs_bvec *bvec) { struct z_erofs_pcluster *const pcl =3D fe->pcl; =20 - while (fe->icpage_ptr > pcl->compressed_pages) - if (!cmpxchg(--fe->icpage_ptr, NULL, page)) + while (fe->icur > 0) { + if (!cmpxchg(&pcl->compressed_bvecs[--fe->icur].page, + NULL, bvec->page)) { + pcl->compressed_bvecs[fe->icur] =3D *bvec; return true; + } + } return false; } =20 @@ -454,7 +455,7 @@ static int z_erofs_attach_page(struct z_erofs_decompres= s_frontend *fe, if (fe->mode >=3D COLLECT_PRIMARY && type =3D=3D Z_EROFS_PAGE_TYPE_EXCLUSIVE) { /* give priority for inplaceio to use file pages first */ - if (z_erofs_try_inplace_io(fe, bvec->page)) + if (z_erofs_try_inplace_io(fe, bvec)) return 0; /* otherwise, check if it can be used as a bvpage */ if (fe->mode >=3D COLLECT_PRIMARY_FOLLOWED && @@ -648,8 +649,7 @@ static int z_erofs_collector_begin(struct z_erofs_decom= press_frontend *fe) z_erofs_bvec_iter_begin(&fe->biter, &fe->pcl->bvset, Z_EROFS_INLINE_BVECS, fe->pcl->vcnt); /* since file-backed online pages are traversed in reverse order */ - fe->icpage_ptr =3D fe->pcl->compressed_pages + - z_erofs_pclusterpages(fe->pcl); + fe->icur =3D z_erofs_pclusterpages(fe->pcl); return 0; } =20 @@ -769,7 +769,8 @@ static int z_erofs_do_read_page(struct z_erofs_decompre= ss_frontend *fe, goto err_out; } get_page(fe->map.buf.page); - WRITE_ONCE(fe->pcl->compressed_pages[0], fe->map.buf.page); + WRITE_ONCE(fe->pcl->compressed_bvecs[0].page, + fe->map.buf.page); fe->mode =3D COLLECT_PRIMARY_FOLLOWED_NOINPLACE; } else { /* bind cache first when cached decompression is preferred */ @@ -927,8 +928,9 @@ static struct page **z_erofs_parse_in_bvecs(struct erof= s_sb_info *sbi, *overlapped =3D false; =20 for (i =3D 0; i < pclusterpages; ++i) { - unsigned int pagenr; - struct page *page =3D pcl->compressed_pages[i]; + struct z_erofs_bvec *bvec =3D &pcl->compressed_bvecs[i]; + struct page *page =3D bvec->page; + unsigned int pgnr; =20 /* compressed pages ought to be present before decompressing */ if (!page) { @@ -951,21 +953,15 @@ static struct page **z_erofs_parse_in_bvecs(struct er= ofs_sb_info *sbi, continue; } =20 - /* - * only if non-head page can be selected - * for inplace decompression - */ - pagenr =3D z_erofs_onlinepage_index(page); - - DBG_BUGON(pagenr >=3D pcl->nr_pages); - if (pages[pagenr]) { + pgnr =3D (bvec->offset + pcl->pageofs_out) >> PAGE_SHIFT; + DBG_BUGON(pgnr >=3D pcl->nr_pages); + if (pages[pgnr]) { DBG_BUGON(1); - SetPageError(pages[pagenr]); - z_erofs_onlinepage_endio(pages[pagenr]); + SetPageError(pages[pgnr]); + z_erofs_onlinepage_endio(pages[pgnr]); err =3D -EFSCORRUPTED; } - pages[pagenr] =3D page; - + pages[pgnr] =3D page; *overlapped =3D true; } =20 @@ -1067,19 +1063,19 @@ static int z_erofs_decompress_pcluster(struct super= _block *sb, out: /* must handle all compressed pages before actual file pages */ if (z_erofs_is_inline_pcluster(pcl)) { - page =3D pcl->compressed_pages[0]; - WRITE_ONCE(pcl->compressed_pages[0], NULL); + page =3D pcl->compressed_bvecs[0].page; + WRITE_ONCE(pcl->compressed_bvecs[0].page, NULL); put_page(page); } else { for (i =3D 0; i < pclusterpages; ++i) { - page =3D pcl->compressed_pages[i]; + page =3D pcl->compressed_bvecs[i].page; =20 if (erofs_page_is_managed(sbi, page)) continue; =20 /* recycle all individual short-lived pages */ (void)z_erofs_put_shortlivedpage(pagepool, page); - WRITE_ONCE(pcl->compressed_pages[i], NULL); + WRITE_ONCE(pcl->compressed_bvecs[i].page, NULL); } } kfree(compressed_pages); @@ -1193,7 +1189,7 @@ static struct page *pickup_page_for_submission(struct= z_erofs_pcluster *pcl, int justfound; =20 repeat: - page =3D READ_ONCE(pcl->compressed_pages[nr]); + page =3D READ_ONCE(pcl->compressed_bvecs[nr].page); oldpage =3D page; =20 if (!page) @@ -1209,7 +1205,7 @@ static struct page *pickup_page_for_submission(struct= z_erofs_pcluster *pcl, * otherwise, it will go inplace I/O path instead. */ if (page->private =3D=3D Z_EROFS_PREALLOCATED_PAGE) { - WRITE_ONCE(pcl->compressed_pages[nr], page); + WRITE_ONCE(pcl->compressed_bvecs[nr].page, page); set_page_private(page, 0); tocache =3D true; goto out_tocache; @@ -1235,14 +1231,14 @@ static struct page *pickup_page_for_submission(stru= ct z_erofs_pcluster *pcl, =20 /* the page is still in manage cache */ if (page->mapping =3D=3D mc) { - WRITE_ONCE(pcl->compressed_pages[nr], page); + WRITE_ONCE(pcl->compressed_bvecs[nr].page, page); =20 ClearPageError(page); if (!PagePrivate(page)) { /* * impossible to be !PagePrivate(page) for * the current restriction as well if - * the page is already in compressed_pages[]. + * the page is already in compressed_bvecs[]. */ DBG_BUGON(!justfound); =20 @@ -1271,7 +1267,8 @@ static struct page *pickup_page_for_submission(struct= z_erofs_pcluster *pcl, put_page(page); out_allocpage: page =3D erofs_allocpage(pagepool, gfp | __GFP_NOFAIL); - if (oldpage !=3D cmpxchg(&pcl->compressed_pages[nr], oldpage, page)) { + if (oldpage !=3D cmpxchg(&pcl->compressed_bvecs[nr].page, + oldpage, page)) { erofs_pagepool_add(pagepool, page); cond_resched(); goto repeat; diff --git a/fs/erofs/zdata.h b/fs/erofs/zdata.h index a755c5a44d87..a70f1b73e901 100644 --- a/fs/erofs/zdata.h +++ b/fs/erofs/zdata.h @@ -87,8 +87,8 @@ struct z_erofs_pcluster { /* I: compression algorithm format */ unsigned char algorithmformat; =20 - /* A: compressed pages (can be cached or inplaced pages) */ - struct page *compressed_pages[]; + /* A: compressed bvecs (can be cached or inplaced pages) */ + struct z_erofs_bvec compressed_bvecs[]; }; =20 /* let's avoid the valid 32-bit kernel addresses */ --=20 2.24.4 From nobody Sat Apr 18 10:52:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB85BC43334 for ; Thu, 14 Jul 2022 13:21:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239803AbiGNNVh (ORCPT ); Thu, 14 Jul 2022 09:21:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239609AbiGNNVO (ORCPT ); Thu, 14 Jul 2022 09:21:14 -0400 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D7ED5D5B1 for ; Thu, 14 Jul 2022 06:21:12 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VJJkPKY_1657804869; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJJkPKY_1657804869) by smtp.aliyun-inc.com; Thu, 14 Jul 2022 21:21:10 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang Subject: [PATCH 08/16] erofs: rework online page handling Date: Thu, 14 Jul 2022 21:20:43 +0800 Message-Id: <20220714132051.46012-9-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> References: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Since all decompressed offsets have been integrated to bvecs[], this patch avoids all sub-indexes so that page->private only includes a part count and an eio flag, thus in the future folio->private can have the same meaning. In addition, PG_error will not be used anymore after this patch and we're heading to use page->private (later folio->private) and page->mapping (later folio->mapping) only. Signed-off-by: Gao Xiang --- fs/erofs/zdata.c | 51 ++++++++++++++---------------------- fs/erofs/zdata.h | 68 ++++++++++++++---------------------------------- 2 files changed, 38 insertions(+), 81 deletions(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index f2e3f07baad7..9065e160d6a6 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -743,7 +743,7 @@ static int z_erofs_do_read_page(struct z_erofs_decompre= ss_frontend *fe, map->m_llen =3D 0; err =3D z_erofs_map_blocks_iter(inode, map, 0); if (err) - goto err_out; + goto out; } else { if (fe->pcl) goto hitted; @@ -755,7 +755,7 @@ static int z_erofs_do_read_page(struct z_erofs_decompre= ss_frontend *fe, =20 err =3D z_erofs_collector_begin(fe); if (err) - goto err_out; + goto out; =20 if (z_erofs_is_inline_pcluster(fe->pcl)) { void *mp; @@ -766,7 +766,7 @@ static int z_erofs_do_read_page(struct z_erofs_decompre= ss_frontend *fe, err =3D PTR_ERR(mp); erofs_err(inode->i_sb, "failed to get inline page, err %d", err); - goto err_out; + goto out; } get_page(fe->map.buf.page); WRITE_ONCE(fe->pcl->compressed_bvecs[0].page, @@ -823,16 +823,15 @@ static int z_erofs_do_read_page(struct z_erofs_decomp= ress_frontend *fe, =20 if (err) { DBG_BUGON(err =3D=3D -EAGAIN && fe->candidate_bvpage); - goto err_out; + goto out; } =20 - index =3D page->index - (map->m_la >> PAGE_SHIFT); - - z_erofs_onlinepage_fixup(page, index, true); - + z_erofs_onlinepage_split(page); /* bump up the number of spiltted parts of a page */ ++spiltted; + /* also update nr_pages */ + index =3D page->index - (map->m_la >> PAGE_SHIFT); fe->pcl->nr_pages =3D max_t(pgoff_t, fe->pcl->nr_pages, index + 1); next_part: /* can be used for verification */ @@ -843,16 +842,13 @@ static int z_erofs_do_read_page(struct z_erofs_decomp= ress_frontend *fe, goto repeat; =20 out: + if (err) + z_erofs_page_mark_eio(page); z_erofs_onlinepage_endio(page); =20 erofs_dbg("%s, finish page: %pK spiltted: %u map->m_llen %llu", __func__, page, spiltted, map->m_llen); return err; - - /* if some error occurred while processing this page */ -err_out: - SetPageError(page); - goto out; } =20 static bool z_erofs_get_sync_decompress_policy(struct erofs_sb_info *sbi, @@ -901,7 +897,7 @@ static int z_erofs_parse_out_bvecs(struct z_erofs_pclus= ter *pcl, */ if (pages[pagenr]) { DBG_BUGON(1); - SetPageError(pages[pagenr]); + z_erofs_page_mark_eio(pages[pagenr]); z_erofs_onlinepage_endio(pages[pagenr]); err =3D -EFSCORRUPTED; } @@ -957,19 +953,13 @@ static struct page **z_erofs_parse_in_bvecs(struct er= ofs_sb_info *sbi, DBG_BUGON(pgnr >=3D pcl->nr_pages); if (pages[pgnr]) { DBG_BUGON(1); - SetPageError(pages[pgnr]); + z_erofs_page_mark_eio(pages[pgnr]); z_erofs_onlinepage_endio(pages[pgnr]); err =3D -EFSCORRUPTED; } pages[pgnr] =3D page; *overlapped =3D true; } - - /* PG_error needs checking for all non-managed pages */ - if (PageError(page)) { - DBG_BUGON(PageUptodate(page)); - err =3D -EIO; - } } =20 if (err) { @@ -981,7 +971,7 @@ static struct page **z_erofs_parse_in_bvecs(struct erof= s_sb_info *sbi, =20 static int z_erofs_decompress_pcluster(struct super_block *sb, struct z_erofs_pcluster *pcl, - struct page **pagepool) + struct page **pagepool, int err) { struct erofs_sb_info *const sbi =3D EROFS_SB(sb); unsigned int pclusterpages =3D z_erofs_pclusterpages(pcl); @@ -990,7 +980,6 @@ static int z_erofs_decompress_pcluster(struct super_blo= ck *sb, struct page **pages, **compressed_pages, *page; =20 bool overlapped, partial; - int err; =20 might_sleep(); DBG_BUGON(!READ_ONCE(pcl->nr_pages)); @@ -1090,10 +1079,8 @@ static int z_erofs_decompress_pcluster(struct super_= block *sb, /* recycle all individual short-lived pages */ if (z_erofs_put_shortlivedpage(pagepool, page)) continue; - - if (err < 0) - SetPageError(page); - + if (err) + z_erofs_page_mark_eio(page); z_erofs_onlinepage_endio(page); } =20 @@ -1129,7 +1116,8 @@ static void z_erofs_decompress_queue(const struct z_e= rofs_decompressqueue *io, pcl =3D container_of(owned, struct z_erofs_pcluster, next); owned =3D READ_ONCE(pcl->next); =20 - z_erofs_decompress_pcluster(io->sb, pcl, pagepool); + z_erofs_decompress_pcluster(io->sb, pcl, pagepool, + io->eio ? -EIO : 0); erofs_workgroup_put(&pcl->obj); } } @@ -1233,7 +1221,6 @@ static struct page *pickup_page_for_submission(struct= z_erofs_pcluster *pcl, if (page->mapping =3D=3D mc) { WRITE_ONCE(pcl->compressed_bvecs[nr].page, page); =20 - ClearPageError(page); if (!PagePrivate(page)) { /* * impossible to be !PagePrivate(page) for @@ -1305,6 +1292,7 @@ jobqueue_init(struct super_block *sb, q =3D fgq; init_completion(&fgq->u.done); atomic_set(&fgq->pending_bios, 0); + q->eio =3D true; } q->sb =3D sb; q->head =3D Z_EROFS_PCLUSTER_TAIL_CLOSED; @@ -1365,15 +1353,14 @@ static void z_erofs_decompressqueue_endio(struct bi= o *bio) DBG_BUGON(PageUptodate(page)); DBG_BUGON(z_erofs_page_is_invalidated(page)); =20 - if (err) - SetPageError(page); - if (erofs_page_is_managed(EROFS_SB(q->sb), page)) { if (!err) SetPageUptodate(page); unlock_page(page); } } + if (err) + q->eio =3D true; z_erofs_decompress_kickoff(q, tagptr_unfold_tags(t), -1); bio_put(bio); } diff --git a/fs/erofs/zdata.h b/fs/erofs/zdata.h index a70f1b73e901..852da31e2e91 100644 --- a/fs/erofs/zdata.h +++ b/fs/erofs/zdata.h @@ -109,6 +109,8 @@ struct z_erofs_decompressqueue { struct completion done; struct work_struct work; } u; + + bool eio; }; =20 static inline bool z_erofs_is_inline_pcluster(struct z_erofs_pcluster *pcl) @@ -123,38 +125,17 @@ static inline unsigned int z_erofs_pclusterpages(stru= ct z_erofs_pcluster *pcl) return pcl->pclusterpages; } =20 -#define Z_EROFS_ONLINEPAGE_COUNT_BITS 2 -#define Z_EROFS_ONLINEPAGE_COUNT_MASK ((1 << Z_EROFS_ONLINEPAGE_COUNT_BI= TS) - 1) -#define Z_EROFS_ONLINEPAGE_INDEX_SHIFT (Z_EROFS_ONLINEPAGE_COUNT_BITS) - /* - * waiters (aka. ongoing_packs): # to unlock the page - * sub-index: 0 - for partial page, >=3D 1 full page sub-index + * bit 31: I/O error occurred on this page + * bit 0 - 30: remaining parts to complete this page */ -typedef atomic_t z_erofs_onlinepage_t; - -/* type punning */ -union z_erofs_onlinepage_converter { - z_erofs_onlinepage_t *o; - unsigned long *v; -}; - -static inline unsigned int z_erofs_onlinepage_index(struct page *page) -{ - union z_erofs_onlinepage_converter u; - - DBG_BUGON(!PagePrivate(page)); - u.v =3D &page_private(page); - - return atomic_read(u.o) >> Z_EROFS_ONLINEPAGE_INDEX_SHIFT; -} +#define Z_EROFS_PAGE_EIO (1 << 31) =20 static inline void z_erofs_onlinepage_init(struct page *page) { union { - z_erofs_onlinepage_t o; + atomic_t o; unsigned long v; - /* keep from being unlocked in advance */ } u =3D { .o =3D ATOMIC_INIT(1) }; =20 set_page_private(page, u.v); @@ -162,45 +143,34 @@ static inline void z_erofs_onlinepage_init(struct pag= e *page) SetPagePrivate(page); } =20 -static inline void z_erofs_onlinepage_fixup(struct page *page, - uintptr_t index, bool down) +static inline void z_erofs_onlinepage_split(struct page *page) { - union z_erofs_onlinepage_converter u =3D { .v =3D &page_private(page) }; - int orig, orig_index, val; - -repeat: - orig =3D atomic_read(u.o); - orig_index =3D orig >> Z_EROFS_ONLINEPAGE_INDEX_SHIFT; - if (orig_index) { - if (!index) - return; + atomic_inc((atomic_t *)&page->private); +} =20 - DBG_BUGON(orig_index !=3D index); - } +static inline void z_erofs_page_mark_eio(struct page *page) +{ + int orig; =20 - val =3D (index << Z_EROFS_ONLINEPAGE_INDEX_SHIFT) | - ((orig & Z_EROFS_ONLINEPAGE_COUNT_MASK) + (unsigned int)down); - if (atomic_cmpxchg(u.o, orig, val) !=3D orig) - goto repeat; + do { + orig =3D atomic_read((atomic_t *)&page->private); + } while (atomic_cmpxchg((atomic_t *)&page->private, orig, + orig | Z_EROFS_PAGE_EIO) !=3D orig); } =20 static inline void z_erofs_onlinepage_endio(struct page *page) { - union z_erofs_onlinepage_converter u; unsigned int v; =20 DBG_BUGON(!PagePrivate(page)); - u.v =3D &page_private(page); - - v =3D atomic_dec_return(u.o); - if (!(v & Z_EROFS_ONLINEPAGE_COUNT_MASK)) { + v =3D atomic_dec_return((atomic_t *)&page->private); + if (!(v & ~Z_EROFS_PAGE_EIO)) { set_page_private(page, 0); ClearPagePrivate(page); - if (!PageError(page)) + if (!(v & Z_EROFS_PAGE_EIO)) SetPageUptodate(page); unlock_page(page); } - erofs_dbg("%s, page %p value %x", __func__, page, atomic_read(u.o)); } =20 #define Z_EROFS_VMAP_ONSTACK_PAGES \ --=20 2.24.4 From nobody Sat Apr 18 10:52:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14A61CCA47B for ; Thu, 14 Jul 2022 13:21:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238613AbiGNNVr (ORCPT ); Thu, 14 Jul 2022 09:21:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239657AbiGNNVQ (ORCPT ); Thu, 14 Jul 2022 09:21:16 -0400 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24D1F5A2DB for ; Thu, 14 Jul 2022 06:21:14 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R601e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046051;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VJJkPLG_1657804870; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJJkPLG_1657804870) by smtp.aliyun-inc.com; Thu, 14 Jul 2022 21:21:12 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang Subject: [PATCH 09/16] erofs: get rid of `enum z_erofs_page_type' Date: Thu, 14 Jul 2022 21:20:44 +0800 Message-Id: <20220714132051.46012-10-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> References: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Remove it since pagevec[] is no longer used. Signed-off-by: Gao Xiang --- fs/erofs/zdata.c | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index 9065e160d6a6..cdfb2706e4ae 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -27,17 +27,6 @@ static struct z_erofs_pcluster_slab pcluster_pool[] __re= ad_mostly =3D { _PCLP(Z_EROFS_PCLUSTER_MAX_PAGES) }; =20 -/* page type in pagevec for decompress subsystem */ -enum z_erofs_page_type { - /* including Z_EROFS_VLE_PAGE_TAIL_EXCLUSIVE */ - Z_EROFS_PAGE_TYPE_EXCLUSIVE, - - Z_EROFS_VLE_PAGE_TYPE_TAIL_SHARED, - - Z_EROFS_VLE_PAGE_TYPE_HEAD, - Z_EROFS_VLE_PAGE_TYPE_MAX -}; - struct z_erofs_bvec_iter { struct page *bvpage; struct z_erofs_bvset *bvset; @@ -429,7 +418,6 @@ int erofs_try_to_free_cached_page(struct page *page) return ret; } =20 -/* page_type must be Z_EROFS_PAGE_TYPE_EXCLUSIVE */ static bool z_erofs_try_inplace_io(struct z_erofs_decompress_frontend *fe, struct z_erofs_bvec *bvec) { @@ -447,13 +435,11 @@ static bool z_erofs_try_inplace_io(struct z_erofs_dec= ompress_frontend *fe, =20 /* callers must be with pcluster lock held */ static int z_erofs_attach_page(struct z_erofs_decompress_frontend *fe, - struct z_erofs_bvec *bvec, - enum z_erofs_page_type type) + struct z_erofs_bvec *bvec, bool exclusive) { int ret; =20 - if (fe->mode >=3D COLLECT_PRIMARY && - type =3D=3D Z_EROFS_PAGE_TYPE_EXCLUSIVE) { + if (fe->mode >=3D COLLECT_PRIMARY && exclusive) { /* give priority for inplaceio to use file pages first */ if (z_erofs_try_inplace_io(fe, bvec)) return 0; @@ -718,10 +704,9 @@ static int z_erofs_do_read_page(struct z_erofs_decompr= ess_frontend *fe, struct erofs_sb_info *const sbi =3D EROFS_I_SB(inode); struct erofs_map_blocks *const map =3D &fe->map; const loff_t offset =3D page_offset(page); - bool tight =3D true; + bool tight =3D true, exclusive; =20 enum z_erofs_cache_alloctype cache_strategy; - enum z_erofs_page_type page_type; unsigned int cur, end, spiltted, index; int err =3D 0; =20 @@ -798,12 +783,7 @@ static int z_erofs_do_read_page(struct z_erofs_decompr= ess_frontend *fe, goto next_part; } =20 - /* let's derive page type */ - page_type =3D cur ? Z_EROFS_VLE_PAGE_TYPE_HEAD : - (!spiltted ? Z_EROFS_PAGE_TYPE_EXCLUSIVE : - (tight ? Z_EROFS_PAGE_TYPE_EXCLUSIVE : - Z_EROFS_VLE_PAGE_TYPE_TAIL_SHARED)); - + exclusive =3D (!cur && (!spiltted || tight)); if (cur) tight &=3D (fe->mode >=3D COLLECT_PRIMARY_FOLLOWED); =20 @@ -812,7 +792,7 @@ static int z_erofs_do_read_page(struct z_erofs_decompre= ss_frontend *fe, .page =3D page, .offset =3D offset - map->m_la, .end =3D end, - }), page_type); + }), exclusive); /* should allocate an additional short-lived page for bvset */ if (err =3D=3D -EAGAIN && !fe->candidate_bvpage) { fe->candidate_bvpage =3D alloc_page(GFP_NOFS | __GFP_NOFAIL); --=20 2.24.4 From nobody Sat Apr 18 10:52:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80A71C43334 for ; Thu, 14 Jul 2022 13:21:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239781AbiGNNVt (ORCPT ); Thu, 14 Jul 2022 09:21:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239739AbiGNNVS (ORCPT ); Thu, 14 Jul 2022 09:21:18 -0400 Received: from out30-56.freemail.mail.aliyun.com (out30-56.freemail.mail.aliyun.com [115.124.30.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 527AD5D59D for ; Thu, 14 Jul 2022 06:21:17 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046050;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VJJkPMN_1657804872; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJJkPMN_1657804872) by smtp.aliyun-inc.com; Thu, 14 Jul 2022 21:21:13 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang Subject: [PATCH 10/16] erofs: clean up `enum z_erofs_collectmode' Date: Thu, 14 Jul 2022 21:20:45 +0800 Message-Id: <20220714132051.46012-11-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> References: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" `enum z_erofs_collectmode' is really ambiguous, but I'm not quite sure if there are better naming, basically it's used to judge whether inplace I/O can be used due to the current status of pclusters in the chain. Rename it as `enum z_erofs_pclustermode' instead. Signed-off-by: Gao Xiang --- fs/erofs/zdata.c | 63 ++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index cdfb2706e4ae..55bcd6e5ae9a 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -227,30 +227,29 @@ int __init z_erofs_init_zip_subsystem(void) return err; } =20 -enum z_erofs_collectmode { - COLLECT_SECONDARY, - COLLECT_PRIMARY, +enum z_erofs_pclustermode { + Z_EROFS_PCLUSTER_INFLIGHT, /* - * The current collection was the tail of an exist chain, in addition - * that the previous processed chained collections are all decided to + * The current pclusters was the tail of an exist chain, in addition + * that the previous processed chained pclusters are all decided to * be hooked up to it. - * A new chain will be created for the remaining collections which are - * not processed yet, therefore different from COLLECT_PRIMARY_FOLLOWED, - * the next collection cannot reuse the whole page safely in - * the following scenario: + * A new chain will be created for the remaining pclusters which are + * not processed yet, so different from Z_EROFS_PCLUSTER_FOLLOWED, + * the next pcluster cannot reuse the whole page safely for inplace I/O + * in the following scenario: * ________________________________________________________________ * | tail (partial) page | head (partial) page | - * | (belongs to the next cl) | (belongs to the current cl) | - * |_______PRIMARY_FOLLOWED_______|________PRIMARY_HOOKED___________| + * | (belongs to the next pcl) | (belongs to the current pcl) | + * |_______PCLUSTER_FOLLOWED______|________PCLUSTER_HOOKED__________| */ - COLLECT_PRIMARY_HOOKED, + Z_EROFS_PCLUSTER_HOOKED, /* - * a weak form of COLLECT_PRIMARY_FOLLOWED, the difference is that it + * 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 * pagevec) since it can be directly decoded without I/O submission. */ - COLLECT_PRIMARY_FOLLOWED_NOINPLACE, + Z_EROFS_PCLUSTER_FOLLOWED_NOINPLACE, /* * The current collection has been linked with the owned chain, and * could also be linked with the remaining collections, which means @@ -261,12 +260,12 @@ enum z_erofs_collectmode { * ________________________________________________________________ * | tail (partial) page | head (partial) page | * | (of the current cl) | (of the previous collection) | - * | PRIMARY_FOLLOWED or | | - * |_____PRIMARY_HOOKED___|____________PRIMARY_FOLLOWED____________| + * | PCLUSTER_FOLLOWED or | | + * |_____PCLUSTER_HOOKED__|___________PCLUSTER_FOLLOWED____________| * * [ (*) the above page can be used as inplace I/O. ] */ - COLLECT_PRIMARY_FOLLOWED, + Z_EROFS_PCLUSTER_FOLLOWED, }; =20 struct z_erofs_decompress_frontend { @@ -277,7 +276,7 @@ struct z_erofs_decompress_frontend { struct page *candidate_bvpage; struct z_erofs_pcluster *pcl, *tailpcl; z_erofs_next_pcluster_t owned_head; - enum z_erofs_collectmode mode; + enum z_erofs_pclustermode mode; =20 bool readahead; /* used for applying cache strategy on the fly */ @@ -290,7 +289,7 @@ struct z_erofs_decompress_frontend { =20 #define DECOMPRESS_FRONTEND_INIT(__i) { \ .inode =3D __i, .owned_head =3D Z_EROFS_PCLUSTER_TAIL, \ - .mode =3D COLLECT_PRIMARY_FOLLOWED, .backmost =3D true } + .mode =3D Z_EROFS_PCLUSTER_FOLLOWED, .backmost =3D true } =20 static struct page *z_pagemap_global[Z_EROFS_VMAP_GLOBAL_PAGES]; static DEFINE_MUTEX(z_pagemap_global_lock); @@ -310,7 +309,7 @@ static void z_erofs_bind_cache(struct z_erofs_decompres= s_frontend *fe, __GFP_NOMEMALLOC | __GFP_NORETRY | __GFP_NOWARN; unsigned int i; =20 - if (fe->mode < COLLECT_PRIMARY_FOLLOWED) + if (fe->mode < Z_EROFS_PCLUSTER_FOLLOWED) return; =20 for (i =3D 0; i < pcl->pclusterpages; ++i) { @@ -358,7 +357,7 @@ static void z_erofs_bind_cache(struct z_erofs_decompres= s_frontend *fe, * managed cache since it can be moved to the bypass queue instead. */ if (standalone) - fe->mode =3D COLLECT_PRIMARY_FOLLOWED_NOINPLACE; + fe->mode =3D Z_EROFS_PCLUSTER_FOLLOWED_NOINPLACE; } =20 /* called by erofs_shrinker to get rid of all compressed_pages */ @@ -439,12 +438,12 @@ static int z_erofs_attach_page(struct z_erofs_decompr= ess_frontend *fe, { int ret; =20 - if (fe->mode >=3D COLLECT_PRIMARY && exclusive) { + if (exclusive) { /* give priority for inplaceio to use file pages first */ if (z_erofs_try_inplace_io(fe, bvec)) return 0; /* otherwise, check if it can be used as a bvpage */ - if (fe->mode >=3D COLLECT_PRIMARY_FOLLOWED && + if (fe->mode >=3D Z_EROFS_PCLUSTER_FOLLOWED && !fe->candidate_bvpage) fe->candidate_bvpage =3D bvec->page; } @@ -463,7 +462,7 @@ static void z_erofs_try_to_claim_pcluster(struct z_erof= s_decompress_frontend *f) *owned_head) =3D=3D Z_EROFS_PCLUSTER_NIL) { *owned_head =3D &pcl->next; /* so we can attach this pcluster to our submission chain. */ - f->mode =3D COLLECT_PRIMARY_FOLLOWED; + f->mode =3D Z_EROFS_PCLUSTER_FOLLOWED; return; } =20 @@ -474,12 +473,12 @@ static void z_erofs_try_to_claim_pcluster(struct z_er= ofs_decompress_frontend *f) if (cmpxchg(&pcl->next, Z_EROFS_PCLUSTER_TAIL, *owned_head) =3D=3D Z_EROFS_PCLUSTER_TAIL) { *owned_head =3D Z_EROFS_PCLUSTER_TAIL; - f->mode =3D COLLECT_PRIMARY_HOOKED; + f->mode =3D Z_EROFS_PCLUSTER_HOOKED; f->tailpcl =3D NULL; return; } /* type 3, it belongs to a chain, but it isn't the end of the chain */ - f->mode =3D COLLECT_PRIMARY; + f->mode =3D Z_EROFS_PCLUSTER_INFLIGHT; } =20 static int z_erofs_lookup_pcluster(struct z_erofs_decompress_frontend *fe) @@ -554,7 +553,7 @@ static int z_erofs_register_pcluster(struct z_erofs_dec= ompress_frontend *fe) /* new pclusters should be claimed as type 1, primary and followed */ pcl->next =3D fe->owned_head; pcl->pageofs_out =3D map->m_la & ~PAGE_MASK; - fe->mode =3D COLLECT_PRIMARY_FOLLOWED; + fe->mode =3D Z_EROFS_PCLUSTER_FOLLOWED; =20 /* * lock all primary followed works before visible to others @@ -676,7 +675,7 @@ static bool z_erofs_collector_end(struct z_erofs_decomp= ress_frontend *fe) * if all pending pages are added, don't hold its reference * any longer if the pcluster isn't hosted by ourselves. */ - if (fe->mode < COLLECT_PRIMARY_FOLLOWED_NOINPLACE) + if (fe->mode < Z_EROFS_PCLUSTER_FOLLOWED_NOINPLACE) erofs_workgroup_put(&pcl->obj); =20 fe->pcl =3D NULL; @@ -756,7 +755,7 @@ static int z_erofs_do_read_page(struct z_erofs_decompre= ss_frontend *fe, get_page(fe->map.buf.page); WRITE_ONCE(fe->pcl->compressed_bvecs[0].page, fe->map.buf.page); - fe->mode =3D COLLECT_PRIMARY_FOLLOWED_NOINPLACE; + fe->mode =3D Z_EROFS_PCLUSTER_FOLLOWED_NOINPLACE; } else { /* bind cache first when cached decompression is preferred */ if (should_alloc_managed_pages(fe, sbi->opt.cache_strategy, @@ -774,8 +773,8 @@ static int z_erofs_do_read_page(struct z_erofs_decompre= ss_frontend *fe, * those chains are handled asynchronously thus the page cannot be used * for inplace I/O or pagevec (should be processed in strict order.) */ - tight &=3D (fe->mode >=3D COLLECT_PRIMARY_HOOKED && - fe->mode !=3D COLLECT_PRIMARY_FOLLOWED_NOINPLACE); + tight &=3D (fe->mode >=3D Z_EROFS_PCLUSTER_HOOKED && + fe->mode !=3D Z_EROFS_PCLUSTER_FOLLOWED_NOINPLACE); =20 cur =3D end - min_t(unsigned int, offset + end - map->m_la, end); if (!(map->m_flags & EROFS_MAP_MAPPED)) { @@ -785,7 +784,7 @@ static int z_erofs_do_read_page(struct z_erofs_decompre= ss_frontend *fe, =20 exclusive =3D (!cur && (!spiltted || tight)); if (cur) - tight &=3D (fe->mode >=3D COLLECT_PRIMARY_FOLLOWED); + tight &=3D (fe->mode >=3D Z_EROFS_PCLUSTER_FOLLOWED); =20 retry: err =3D z_erofs_attach_page(fe, &((struct z_erofs_bvec) { --=20 2.24.4 From nobody Sat Apr 18 10:52:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4BBB2CCA47B for ; Thu, 14 Jul 2022 13:21:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239827AbiGNNVv (ORCPT ); Thu, 14 Jul 2022 09:21:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239747AbiGNNVT (ORCPT ); Thu, 14 Jul 2022 09:21:19 -0400 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4429A5D5A4 for ; Thu, 14 Jul 2022 06:21:18 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R881e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046051;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VJJkPNP_1657804874; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJJkPNP_1657804874) by smtp.aliyun-inc.com; Thu, 14 Jul 2022 21:21:15 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang Subject: [PATCH 11/16] erofs: get rid of `z_pagemap_global' Date: Thu, 14 Jul 2022 21:20:46 +0800 Message-Id: <20220714132051.46012-12-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> References: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In order to introduce multi-reference pclusters for compressed data deduplication, let's get rid of the global page array for now since it needs to be re-designed then at least. Signed-off-by: Gao Xiang --- fs/erofs/zdata.c | 28 ++++------------------------ fs/erofs/zdata.h | 1 - 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index 55bcd6e5ae9a..f24b866bc975 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -291,9 +291,6 @@ struct z_erofs_decompress_frontend { .inode =3D __i, .owned_head =3D Z_EROFS_PCLUSTER_TAIL, \ .mode =3D Z_EROFS_PCLUSTER_FOLLOWED, .backmost =3D true } =20 -static struct page *z_pagemap_global[Z_EROFS_VMAP_GLOBAL_PAGES]; -static DEFINE_MUTEX(z_pagemap_global_lock); - static void z_erofs_bind_cache(struct z_erofs_decompress_frontend *fe, enum z_erofs_cache_alloctype type, struct page **pagepool) @@ -966,26 +963,11 @@ static int z_erofs_decompress_pcluster(struct super_b= lock *sb, mutex_lock(&pcl->lock); nr_pages =3D pcl->nr_pages; =20 - if (nr_pages <=3D Z_EROFS_VMAP_ONSTACK_PAGES) { + if (nr_pages <=3D Z_EROFS_VMAP_ONSTACK_PAGES) pages =3D pages_onstack; - } else if (nr_pages <=3D Z_EROFS_VMAP_GLOBAL_PAGES && - mutex_trylock(&z_pagemap_global_lock)) { - pages =3D z_pagemap_global; - } else { - gfp_t gfp_flags =3D GFP_KERNEL; - - if (nr_pages > Z_EROFS_VMAP_GLOBAL_PAGES) - gfp_flags |=3D __GFP_NOFAIL; - + else pages =3D kvmalloc_array(nr_pages, sizeof(struct page *), - gfp_flags); - - /* fallback to global pagemap for the lowmem scenario */ - if (!pages) { - mutex_lock(&z_pagemap_global_lock); - pages =3D z_pagemap_global; - } - } + GFP_KERNEL | __GFP_NOFAIL); =20 for (i =3D 0; i < nr_pages; ++i) pages[i] =3D NULL; @@ -1063,9 +1045,7 @@ static int z_erofs_decompress_pcluster(struct super_b= lock *sb, z_erofs_onlinepage_endio(page); } =20 - if (pages =3D=3D z_pagemap_global) - mutex_unlock(&z_pagemap_global_lock); - else if (pages !=3D pages_onstack) + if (pages !=3D pages_onstack) kvfree(pages); =20 pcl->nr_pages =3D 0; diff --git a/fs/erofs/zdata.h b/fs/erofs/zdata.h index 852da31e2e91..5964c942799e 100644 --- a/fs/erofs/zdata.h +++ b/fs/erofs/zdata.h @@ -175,6 +175,5 @@ static inline void z_erofs_onlinepage_endio(struct page= *page) =20 #define Z_EROFS_VMAP_ONSTACK_PAGES \ min_t(unsigned int, THREAD_SIZE / 8 / sizeof(struct page *), 96U) -#define Z_EROFS_VMAP_GLOBAL_PAGES 2048 =20 #endif --=20 2.24.4 From nobody Sat Apr 18 10:52:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D3CDCCA481 for ; Thu, 14 Jul 2022 13:21:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238742AbiGNNVy (ORCPT ); Thu, 14 Jul 2022 09:21:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239748AbiGNNVU (ORCPT ); Thu, 14 Jul 2022 09:21:20 -0400 Received: from out30-42.freemail.mail.aliyun.com (out30-42.freemail.mail.aliyun.com [115.124.30.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C0535E30A for ; Thu, 14 Jul 2022 06:21:19 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R251e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04400;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VJJkPOX_1657804875; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJJkPOX_1657804875) by smtp.aliyun-inc.com; Thu, 14 Jul 2022 21:21:17 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang Subject: [PATCH 12/16] erofs: introduce struct z_erofs_decompress_backend Date: Thu, 14 Jul 2022 21:20:47 +0800 Message-Id: <20220714132051.46012-13-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> References: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Let's introduce struct z_erofs_decompress_backend in order to pass on the decompression backend context between helper functions more easier and avoid too many arguments. Signed-off-by: Gao Xiang --- fs/erofs/zdata.c | 142 +++++++++++++++++++++++++---------------------- fs/erofs/zdata.h | 3 +- 2 files changed, 76 insertions(+), 69 deletions(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index f24b866bc975..7aea6bb1e018 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -847,9 +847,22 @@ static bool z_erofs_page_is_invalidated(struct page *p= age) return !page->mapping && !z_erofs_is_shortlived_page(page); } =20 -static int z_erofs_parse_out_bvecs(struct z_erofs_pcluster *pcl, - struct page **pages, struct page **pagepool) +struct z_erofs_decompress_backend { + struct page *onstack_pages[Z_EROFS_ONSTACK_PAGES]; + struct super_block *sb; + struct z_erofs_pcluster *pcl; + + /* pages with the longest decompressed length for deduplication */ + struct page **decompressed_pages; + /* pages to keep the compressed data */ + struct page **compressed_pages; + + struct page **pagepool; +}; + +static int z_erofs_parse_out_bvecs(struct z_erofs_decompress_backend *be) { + struct z_erofs_pcluster *pcl =3D be->pcl; struct z_erofs_bvec_iter biter; struct page *old_bvpage; int i, err =3D 0; @@ -857,39 +870,39 @@ static int z_erofs_parse_out_bvecs(struct z_erofs_pcl= uster *pcl, z_erofs_bvec_iter_begin(&biter, &pcl->bvset, Z_EROFS_INLINE_BVECS, 0); for (i =3D 0; i < pcl->vcnt; ++i) { struct z_erofs_bvec bvec; - unsigned int pagenr; + unsigned int pgnr; =20 z_erofs_bvec_dequeue(&biter, &bvec, &old_bvpage); =20 if (old_bvpage) - z_erofs_put_shortlivedpage(pagepool, old_bvpage); + z_erofs_put_shortlivedpage(be->pagepool, old_bvpage); =20 - pagenr =3D (bvec.offset + pcl->pageofs_out) >> PAGE_SHIFT; - DBG_BUGON(pagenr >=3D pcl->nr_pages); + pgnr =3D (bvec.offset + pcl->pageofs_out) >> PAGE_SHIFT; + DBG_BUGON(pgnr >=3D pcl->nr_pages); DBG_BUGON(z_erofs_page_is_invalidated(bvec.page)); /* * currently EROFS doesn't support multiref(dedup), * so here erroring out one multiref page. */ - if (pages[pagenr]) { + if (be->decompressed_pages[pgnr]) { DBG_BUGON(1); - z_erofs_page_mark_eio(pages[pagenr]); - z_erofs_onlinepage_endio(pages[pagenr]); + z_erofs_page_mark_eio(be->decompressed_pages[pgnr]); + z_erofs_onlinepage_endio(be->decompressed_pages[pgnr]); err =3D -EFSCORRUPTED; } - pages[pagenr] =3D bvec.page; + be->decompressed_pages[pgnr] =3D bvec.page; } =20 old_bvpage =3D z_erofs_bvec_iter_end(&biter); if (old_bvpage) - z_erofs_put_shortlivedpage(pagepool, old_bvpage); + z_erofs_put_shortlivedpage(be->pagepool, old_bvpage); return err; } =20 -static struct page **z_erofs_parse_in_bvecs(struct erofs_sb_info *sbi, - struct z_erofs_pcluster *pcl, struct page **pages, - struct page **pagepool, bool *overlapped) +static int z_erofs_parse_in_bvecs(struct z_erofs_decompress_backend *be, + bool *overlapped) { + struct z_erofs_pcluster *pcl =3D be->pcl; unsigned int pclusterpages =3D z_erofs_pclusterpages(pcl); struct page **compressed_pages; int i, err =3D 0; @@ -919,7 +932,7 @@ static struct page **z_erofs_parse_in_bvecs(struct erof= s_sb_info *sbi, =20 DBG_BUGON(z_erofs_page_is_invalidated(page)); if (!z_erofs_is_shortlived_page(page)) { - if (erofs_page_is_managed(sbi, page)) { + if (erofs_page_is_managed(EROFS_SB(be->sb), page)) { if (!PageUptodate(page)) err =3D -EIO; continue; @@ -927,59 +940,55 @@ static struct page **z_erofs_parse_in_bvecs(struct er= ofs_sb_info *sbi, =20 pgnr =3D (bvec->offset + pcl->pageofs_out) >> PAGE_SHIFT; DBG_BUGON(pgnr >=3D pcl->nr_pages); - if (pages[pgnr]) { + if (be->decompressed_pages[pgnr]) { DBG_BUGON(1); - z_erofs_page_mark_eio(pages[pgnr]); - z_erofs_onlinepage_endio(pages[pgnr]); + z_erofs_page_mark_eio( + be->decompressed_pages[pgnr]); + z_erofs_onlinepage_endio( + be->decompressed_pages[pgnr]); err =3D -EFSCORRUPTED; } - pages[pgnr] =3D page; + be->decompressed_pages[pgnr] =3D page; *overlapped =3D true; } } =20 if (err) { kfree(compressed_pages); - return ERR_PTR(err); + return err; } - return compressed_pages; + be->compressed_pages =3D compressed_pages; + return 0; } =20 -static int z_erofs_decompress_pcluster(struct super_block *sb, - struct z_erofs_pcluster *pcl, - struct page **pagepool, int err) +static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *= be, + int err) { - struct erofs_sb_info *const sbi =3D EROFS_SB(sb); + struct erofs_sb_info *const sbi =3D EROFS_SB(be->sb); + struct z_erofs_pcluster *pcl =3D be->pcl; unsigned int pclusterpages =3D z_erofs_pclusterpages(pcl); - unsigned int i, inputsize, outputsize, llen, nr_pages; - struct page *pages_onstack[Z_EROFS_VMAP_ONSTACK_PAGES]; - struct page **pages, **compressed_pages, *page; - + unsigned int i, inputsize, outputsize, llen, nr_pages, err2; + struct page *page; bool overlapped, partial; =20 - might_sleep(); DBG_BUGON(!READ_ONCE(pcl->nr_pages)); - mutex_lock(&pcl->lock); nr_pages =3D pcl->nr_pages; =20 - if (nr_pages <=3D Z_EROFS_VMAP_ONSTACK_PAGES) - pages =3D pages_onstack; - else - pages =3D kvmalloc_array(nr_pages, sizeof(struct page *), - GFP_KERNEL | __GFP_NOFAIL); - - for (i =3D 0; i < nr_pages; ++i) - pages[i] =3D NULL; - - err =3D z_erofs_parse_out_bvecs(pcl, pages, pagepool); - compressed_pages =3D z_erofs_parse_in_bvecs(sbi, pcl, pages, - pagepool, &overlapped); - if (IS_ERR(compressed_pages)) { - err =3D PTR_ERR(compressed_pages); - compressed_pages =3D NULL; + if (nr_pages <=3D Z_EROFS_ONSTACK_PAGES) { + be->decompressed_pages =3D be->onstack_pages; + memset(be->decompressed_pages, 0, + sizeof(struct page *) * nr_pages); + } else { + be->decompressed_pages =3D + kvcalloc(nr_pages, sizeof(struct page *), + GFP_KERNEL | __GFP_NOFAIL); } =20 + err =3D z_erofs_parse_out_bvecs(be); + err2 =3D z_erofs_parse_in_bvecs(be, &overlapped); + if (err2) + err =3D err2; if (err) goto out; =20 @@ -998,9 +1007,9 @@ static int z_erofs_decompress_pcluster(struct super_bl= ock *sb, inputsize =3D pclusterpages * PAGE_SIZE; =20 err =3D z_erofs_decompress(&(struct z_erofs_decompress_req) { - .sb =3D sb, - .in =3D compressed_pages, - .out =3D pages, + .sb =3D be->sb, + .in =3D be->compressed_pages, + .out =3D be->decompressed_pages, .pageofs_in =3D pcl->pageofs_in, .pageofs_out =3D pcl->pageofs_out, .inputsize =3D inputsize, @@ -1008,7 +1017,7 @@ static int z_erofs_decompress_pcluster(struct super_b= lock *sb, .alg =3D pcl->algorithmformat, .inplace_io =3D overlapped, .partial_decoding =3D partial - }, pagepool); + }, be->pagepool); =20 out: /* must handle all compressed pages before actual file pages */ @@ -1024,29 +1033,29 @@ static int z_erofs_decompress_pcluster(struct super= _block *sb, continue; =20 /* recycle all individual short-lived pages */ - (void)z_erofs_put_shortlivedpage(pagepool, page); + (void)z_erofs_put_shortlivedpage(be->pagepool, page); WRITE_ONCE(pcl->compressed_bvecs[i].page, NULL); } } - kfree(compressed_pages); + kfree(be->compressed_pages); =20 for (i =3D 0; i < nr_pages; ++i) { - page =3D pages[i]; + page =3D be->decompressed_pages[i]; if (!page) continue; =20 DBG_BUGON(z_erofs_page_is_invalidated(page)); =20 /* recycle all individual short-lived pages */ - if (z_erofs_put_shortlivedpage(pagepool, page)) + if (z_erofs_put_shortlivedpage(be->pagepool, page)) continue; if (err) z_erofs_page_mark_eio(page); z_erofs_onlinepage_endio(page); } =20 - if (pages !=3D pages_onstack) - kvfree(pages); + if (be->decompressed_pages !=3D be->onstack_pages) + kvfree(be->decompressed_pages); =20 pcl->nr_pages =3D 0; pcl->bvset.nextpage =3D NULL; @@ -1061,23 +1070,23 @@ static int z_erofs_decompress_pcluster(struct super= _block *sb, static void z_erofs_decompress_queue(const struct z_erofs_decompressqueue = *io, struct page **pagepool) { + struct z_erofs_decompress_backend be =3D { + .sb =3D io->sb, + .pagepool =3D pagepool, + }; z_erofs_next_pcluster_t owned =3D io->head; =20 while (owned !=3D Z_EROFS_PCLUSTER_TAIL_CLOSED) { - struct z_erofs_pcluster *pcl; - - /* no possible that 'owned' equals Z_EROFS_WORK_TPTR_TAIL */ + /* impossible that 'owned' equals Z_EROFS_WORK_TPTR_TAIL */ DBG_BUGON(owned =3D=3D Z_EROFS_PCLUSTER_TAIL); - - /* no possible that 'owned' equals NULL */ + /* impossible that 'owned' equals Z_EROFS_PCLUSTER_NIL */ DBG_BUGON(owned =3D=3D Z_EROFS_PCLUSTER_NIL); =20 - pcl =3D container_of(owned, struct z_erofs_pcluster, next); - owned =3D READ_ONCE(pcl->next); + be.pcl =3D container_of(owned, struct z_erofs_pcluster, next); + owned =3D READ_ONCE(be.pcl->next); =20 - z_erofs_decompress_pcluster(io->sb, pcl, pagepool, - io->eio ? -EIO : 0); - erofs_workgroup_put(&pcl->obj); + z_erofs_decompress_pcluster(&be, io->eio ? -EIO : 0); + erofs_workgroup_put(&be.pcl->obj); } } =20 @@ -1103,7 +1112,6 @@ static void z_erofs_decompress_kickoff(struct z_erofs= _decompressqueue *io, if (sync) { if (!atomic_add_return(bios, &io->pending_bios)) complete(&io->u.done); - return; } =20 diff --git a/fs/erofs/zdata.h b/fs/erofs/zdata.h index 5964c942799e..ec09ca035fbb 100644 --- a/fs/erofs/zdata.h +++ b/fs/erofs/zdata.h @@ -173,7 +173,6 @@ static inline void z_erofs_onlinepage_endio(struct page= *page) } } =20 -#define Z_EROFS_VMAP_ONSTACK_PAGES \ - min_t(unsigned int, THREAD_SIZE / 8 / sizeof(struct page *), 96U) +#define Z_EROFS_ONSTACK_PAGES 32 =20 #endif --=20 2.24.4 From nobody Sat Apr 18 10:52:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88254C43334 for ; Thu, 14 Jul 2022 13:21:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239790AbiGNNV5 (ORCPT ); Thu, 14 Jul 2022 09:21:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239760AbiGNNVW (ORCPT ); Thu, 14 Jul 2022 09:21:22 -0400 Received: from out30-42.freemail.mail.aliyun.com (out30-42.freemail.mail.aliyun.com [115.124.30.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FB7E5E328 for ; Thu, 14 Jul 2022 06:21:21 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R101e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VJJkPPf_1657804877; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJJkPPf_1657804877) by smtp.aliyun-inc.com; Thu, 14 Jul 2022 21:21:18 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang Subject: [PATCH 13/16] erofs: try to leave (de)compressed_pages on stack if possible Date: Thu, 14 Jul 2022 21:20:48 +0800 Message-Id: <20220714132051.46012-14-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> References: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" For the most cases, small pclusters can be decompressed with page arrays on stack. Try to leave both (de)compressed_pages on stack if possible as before. Signed-off-by: Gao Xiang --- fs/erofs/zdata.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index 7aea6bb1e018..4093d8a4ce93 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -858,6 +858,7 @@ struct z_erofs_decompress_backend { struct page **compressed_pages; =20 struct page **pagepool; + unsigned int onstack_used; }; =20 static int z_erofs_parse_out_bvecs(struct z_erofs_decompress_backend *be) @@ -904,14 +905,9 @@ static int z_erofs_parse_in_bvecs(struct z_erofs_decom= press_backend *be, { struct z_erofs_pcluster *pcl =3D be->pcl; unsigned int pclusterpages =3D z_erofs_pclusterpages(pcl); - struct page **compressed_pages; int i, err =3D 0; =20 - /* XXX: will have a better approach in the following commits */ - compressed_pages =3D kmalloc_array(pclusterpages, sizeof(struct page *), - GFP_KERNEL | __GFP_NOFAIL); *overlapped =3D false; - for (i =3D 0; i < pclusterpages; ++i) { struct z_erofs_bvec *bvec =3D &pcl->compressed_bvecs[i]; struct page *page =3D bvec->page; @@ -922,7 +918,7 @@ static int z_erofs_parse_in_bvecs(struct z_erofs_decomp= ress_backend *be, DBG_BUGON(1); continue; } - compressed_pages[i] =3D page; + be->compressed_pages[i] =3D page; =20 if (z_erofs_is_inline_pcluster(pcl)) { if (!PageUptodate(page)) @@ -953,11 +949,8 @@ static int z_erofs_parse_in_bvecs(struct z_erofs_decom= press_backend *be, } } =20 - if (err) { - kfree(compressed_pages); + if (err) return err; - } - be->compressed_pages =3D compressed_pages; return 0; } =20 @@ -975,15 +968,28 @@ static int z_erofs_decompress_pcluster(struct z_erofs= _decompress_backend *be, mutex_lock(&pcl->lock); nr_pages =3D pcl->nr_pages; =20 + /* allocate (de)compressed page arrays if cannot be kept on stack */ + be->decompressed_pages =3D NULL; + be->compressed_pages =3D NULL; + be->onstack_used =3D 0; if (nr_pages <=3D Z_EROFS_ONSTACK_PAGES) { be->decompressed_pages =3D be->onstack_pages; + be->onstack_used =3D nr_pages; memset(be->decompressed_pages, 0, sizeof(struct page *) * nr_pages); - } else { + } + + if (pclusterpages + be->onstack_used <=3D Z_EROFS_ONSTACK_PAGES) + be->compressed_pages =3D be->onstack_pages + be->onstack_used; + + if (!be->decompressed_pages) be->decompressed_pages =3D kvcalloc(nr_pages, sizeof(struct page *), GFP_KERNEL | __GFP_NOFAIL); - } + if (!be->compressed_pages) + be->compressed_pages =3D + kvcalloc(pclusterpages, sizeof(struct page *), + GFP_KERNEL | __GFP_NOFAIL); =20 err =3D z_erofs_parse_out_bvecs(be); err2 =3D z_erofs_parse_in_bvecs(be, &overlapped); @@ -1037,7 +1043,9 @@ static int z_erofs_decompress_pcluster(struct z_erofs= _decompress_backend *be, WRITE_ONCE(pcl->compressed_bvecs[i].page, NULL); } } - kfree(be->compressed_pages); + if (be->compressed_pages < be->onstack_pages || + be->compressed_pages >=3D be->onstack_pages + Z_EROFS_ONSTACK_PAGES) + kvfree(be->compressed_pages); =20 for (i =3D 0; i < nr_pages; ++i) { page =3D be->decompressed_pages[i]; --=20 2.24.4 From nobody Sat Apr 18 10:52:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2B4AC43334 for ; Thu, 14 Jul 2022 13:22:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232071AbiGNNWC (ORCPT ); Thu, 14 Jul 2022 09:22:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239723AbiGNNVY (ORCPT ); Thu, 14 Jul 2022 09:21:24 -0400 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C0A95E32F for ; Thu, 14 Jul 2022 06:21:23 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045168;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VJJkPQf_1657804878; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJJkPQf_1657804878) by smtp.aliyun-inc.com; Thu, 14 Jul 2022 21:21:20 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang Subject: [PATCH 14/16] erofs: introduce z_erofs_do_decompressed_bvec() Date: Thu, 14 Jul 2022 21:20:49 +0800 Message-Id: <20220714132051.46012-15-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> References: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Both out_bvecs and in_bvecs share the common logic for decompressed buffers. So let's make a helper for this. Signed-off-by: Gao Xiang --- fs/erofs/zdata.c | 49 ++++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index 4093d8a4ce93..391755dafecd 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -861,6 +861,26 @@ struct z_erofs_decompress_backend { unsigned int onstack_used; }; =20 +static int z_erofs_do_decompressed_bvec(struct z_erofs_decompress_backend = *be, + struct z_erofs_bvec *bvec) +{ + unsigned int pgnr =3D (bvec->offset + be->pcl->pageofs_out) >> PAGE_SHIFT; + struct page *oldpage; + + DBG_BUGON(pgnr >=3D be->pcl->nr_pages); + oldpage =3D be->decompressed_pages[pgnr]; + be->decompressed_pages[pgnr] =3D bvec->page; + + /* error out if one pcluster is refenenced multiple times. */ + if (oldpage) { + DBG_BUGON(1); + z_erofs_page_mark_eio(oldpage); + z_erofs_onlinepage_endio(oldpage); + return -EFSCORRUPTED; + } + return 0; +} + static int z_erofs_parse_out_bvecs(struct z_erofs_decompress_backend *be) { struct z_erofs_pcluster *pcl =3D be->pcl; @@ -871,27 +891,14 @@ static int z_erofs_parse_out_bvecs(struct z_erofs_dec= ompress_backend *be) z_erofs_bvec_iter_begin(&biter, &pcl->bvset, Z_EROFS_INLINE_BVECS, 0); for (i =3D 0; i < pcl->vcnt; ++i) { struct z_erofs_bvec bvec; - unsigned int pgnr; =20 z_erofs_bvec_dequeue(&biter, &bvec, &old_bvpage); =20 if (old_bvpage) z_erofs_put_shortlivedpage(be->pagepool, old_bvpage); =20 - pgnr =3D (bvec.offset + pcl->pageofs_out) >> PAGE_SHIFT; - DBG_BUGON(pgnr >=3D pcl->nr_pages); DBG_BUGON(z_erofs_page_is_invalidated(bvec.page)); - /* - * currently EROFS doesn't support multiref(dedup), - * so here erroring out one multiref page. - */ - if (be->decompressed_pages[pgnr]) { - DBG_BUGON(1); - z_erofs_page_mark_eio(be->decompressed_pages[pgnr]); - z_erofs_onlinepage_endio(be->decompressed_pages[pgnr]); - err =3D -EFSCORRUPTED; - } - be->decompressed_pages[pgnr] =3D bvec.page; + err =3D z_erofs_do_decompressed_bvec(be, &bvec); } =20 old_bvpage =3D z_erofs_bvec_iter_end(&biter); @@ -911,7 +918,6 @@ static int z_erofs_parse_in_bvecs(struct z_erofs_decomp= ress_backend *be, for (i =3D 0; i < pclusterpages; ++i) { struct z_erofs_bvec *bvec =3D &pcl->compressed_bvecs[i]; struct page *page =3D bvec->page; - unsigned int pgnr; =20 /* compressed pages ought to be present before decompressing */ if (!page) { @@ -933,18 +939,7 @@ static int z_erofs_parse_in_bvecs(struct z_erofs_decom= press_backend *be, err =3D -EIO; continue; } - - pgnr =3D (bvec->offset + pcl->pageofs_out) >> PAGE_SHIFT; - DBG_BUGON(pgnr >=3D pcl->nr_pages); - if (be->decompressed_pages[pgnr]) { - DBG_BUGON(1); - z_erofs_page_mark_eio( - be->decompressed_pages[pgnr]); - z_erofs_onlinepage_endio( - be->decompressed_pages[pgnr]); - err =3D -EFSCORRUPTED; - } - be->decompressed_pages[pgnr] =3D page; + err =3D z_erofs_do_decompressed_bvec(be, bvec); *overlapped =3D true; } } --=20 2.24.4 From nobody Sat Apr 18 10:52:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 298E3C433EF for ; Thu, 14 Jul 2022 13:22:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239859AbiGNNWH (ORCPT ); Thu, 14 Jul 2022 09:22:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239765AbiGNNVZ (ORCPT ); Thu, 14 Jul 2022 09:21:25 -0400 Received: from out30-42.freemail.mail.aliyun.com (out30-42.freemail.mail.aliyun.com [115.124.30.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 086CD5D0C0 for ; Thu, 14 Jul 2022 06:21:23 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VJJkPRP_1657804880; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJJkPRP_1657804880) by smtp.aliyun-inc.com; Thu, 14 Jul 2022 21:21:21 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang Subject: [PATCH 15/16] erofs: record the longest decompressed size in this round Date: Thu, 14 Jul 2022 21:20:50 +0800 Message-Id: <20220714132051.46012-16-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> References: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Currently, `pcl->length' records the longest decompressed length as long as the pcluster itself isn't reclaimed. However, such number is unneeded for the general cases since it doesn't indicate the exact decompressed size in this round. Instead, let's record the decompressed size for this round instead, thus `pcl->nr_pages' can be completely dropped and pageofs_out is also designed to be kept in sync with `pcl->length'. Signed-off-by: Gao Xiang --- fs/erofs/zdata.c | 76 +++++++++++++++++------------------------------- fs/erofs/zdata.h | 11 +++---- 2 files changed, 30 insertions(+), 57 deletions(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index 391755dafecd..8dcfc2a9704e 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -482,7 +482,6 @@ static int z_erofs_lookup_pcluster(struct z_erofs_decom= press_frontend *fe) { struct erofs_map_blocks *map =3D &fe->map; struct z_erofs_pcluster *pcl =3D fe->pcl; - unsigned int length; =20 /* to avoid unexpected loop formed by corrupted images */ if (fe->owned_head =3D=3D &pcl->next || pcl =3D=3D fe->tailpcl) { @@ -495,24 +494,6 @@ static int z_erofs_lookup_pcluster(struct z_erofs_deco= mpress_frontend *fe) return -EFSCORRUPTED; } =20 - length =3D READ_ONCE(pcl->length); - if (length & Z_EROFS_PCLUSTER_FULL_LENGTH) { - if ((map->m_llen << Z_EROFS_PCLUSTER_LENGTH_BIT) > length) { - DBG_BUGON(1); - return -EFSCORRUPTED; - } - } else { - unsigned int llen =3D map->m_llen << Z_EROFS_PCLUSTER_LENGTH_BIT; - - if (map->m_flags & EROFS_MAP_FULL_MAPPED) - llen |=3D Z_EROFS_PCLUSTER_FULL_LENGTH; - - while (llen > length && - length !=3D cmpxchg_relaxed(&pcl->length, length, llen)) { - cpu_relax(); - length =3D READ_ONCE(pcl->length); - } - } mutex_lock(&pcl->lock); /* used to check tail merging loop due to corrupted images */ if (fe->owned_head =3D=3D Z_EROFS_PCLUSTER_TAIL) @@ -543,9 +524,8 @@ static int z_erofs_register_pcluster(struct z_erofs_dec= ompress_frontend *fe) =20 atomic_set(&pcl->obj.refcount, 1); pcl->algorithmformat =3D map->m_algorithmformat; - pcl->length =3D (map->m_llen << Z_EROFS_PCLUSTER_LENGTH_BIT) | - (map->m_flags & EROFS_MAP_FULL_MAPPED ? - Z_EROFS_PCLUSTER_FULL_LENGTH : 0); + pcl->length =3D 0; + pcl->partial =3D true; =20 /* new pclusters should be claimed as type 1, primary and followed */ pcl->next =3D fe->owned_head; @@ -703,7 +683,7 @@ static int z_erofs_do_read_page(struct z_erofs_decompre= ss_frontend *fe, bool tight =3D true, exclusive; =20 enum z_erofs_cache_alloctype cache_strategy; - unsigned int cur, end, spiltted, index; + unsigned int cur, end, spiltted; int err =3D 0; =20 /* register locked file pages as online pages in pack */ @@ -806,12 +786,17 @@ static int z_erofs_do_read_page(struct z_erofs_decomp= ress_frontend *fe, /* bump up the number of spiltted parts of a page */ ++spiltted; =20 - /* also update nr_pages */ - index =3D page->index - (map->m_la >> PAGE_SHIFT); - fe->pcl->nr_pages =3D max_t(pgoff_t, fe->pcl->nr_pages, index + 1); + if (fe->pcl->length < offset + end - map->m_la) { + fe->pcl->length =3D offset + end - map->m_la; + fe->pcl->pageofs_out =3D map->m_la & ~PAGE_MASK; + } + if ((map->m_flags & EROFS_MAP_FULL_MAPPED) && + fe->pcl->length =3D=3D map->m_llen) + fe->pcl->partial =3D false; next_part: - /* can be used for verification */ + /* shorten the remaining extent to update progress */ map->m_llen =3D offset + cur - map->m_la; + map->m_flags &=3D ~EROFS_MAP_FULL_MAPPED; =20 end =3D cur; if (end > 0) @@ -858,7 +843,7 @@ struct z_erofs_decompress_backend { struct page **compressed_pages; =20 struct page **pagepool; - unsigned int onstack_used; + unsigned int onstack_used, nr_pages; }; =20 static int z_erofs_do_decompressed_bvec(struct z_erofs_decompress_backend = *be, @@ -867,7 +852,7 @@ static int z_erofs_do_decompressed_bvec(struct z_erofs_= decompress_backend *be, unsigned int pgnr =3D (bvec->offset + be->pcl->pageofs_out) >> PAGE_SHIFT; struct page *oldpage; =20 - DBG_BUGON(pgnr >=3D be->pcl->nr_pages); + DBG_BUGON(pgnr >=3D be->nr_pages); oldpage =3D be->decompressed_pages[pgnr]; be->decompressed_pages[pgnr] =3D bvec->page; =20 @@ -955,23 +940,22 @@ static int z_erofs_decompress_pcluster(struct z_erofs= _decompress_backend *be, struct erofs_sb_info *const sbi =3D EROFS_SB(be->sb); struct z_erofs_pcluster *pcl =3D be->pcl; unsigned int pclusterpages =3D z_erofs_pclusterpages(pcl); - unsigned int i, inputsize, outputsize, llen, nr_pages, err2; + unsigned int i, inputsize, err2; struct page *page; - bool overlapped, partial; + bool overlapped; =20 - DBG_BUGON(!READ_ONCE(pcl->nr_pages)); mutex_lock(&pcl->lock); - nr_pages =3D pcl->nr_pages; + be->nr_pages =3D PAGE_ALIGN(pcl->length + pcl->pageofs_out) >> PAGE_SHIFT; =20 /* allocate (de)compressed page arrays if cannot be kept on stack */ be->decompressed_pages =3D NULL; be->compressed_pages =3D NULL; be->onstack_used =3D 0; - if (nr_pages <=3D Z_EROFS_ONSTACK_PAGES) { + if (be->nr_pages <=3D Z_EROFS_ONSTACK_PAGES) { be->decompressed_pages =3D be->onstack_pages; - be->onstack_used =3D nr_pages; + be->onstack_used =3D be->nr_pages; memset(be->decompressed_pages, 0, - sizeof(struct page *) * nr_pages); + sizeof(struct page *) * be->nr_pages); } =20 if (pclusterpages + be->onstack_used <=3D Z_EROFS_ONSTACK_PAGES) @@ -979,7 +963,7 @@ static int z_erofs_decompress_pcluster(struct z_erofs_d= ecompress_backend *be, =20 if (!be->decompressed_pages) be->decompressed_pages =3D - kvcalloc(nr_pages, sizeof(struct page *), + kvcalloc(be->nr_pages, sizeof(struct page *), GFP_KERNEL | __GFP_NOFAIL); if (!be->compressed_pages) be->compressed_pages =3D @@ -993,15 +977,6 @@ static int z_erofs_decompress_pcluster(struct z_erofs_= decompress_backend *be, if (err) goto out; =20 - llen =3D pcl->length >> Z_EROFS_PCLUSTER_LENGTH_BIT; - if (nr_pages << PAGE_SHIFT >=3D pcl->pageofs_out + llen) { - outputsize =3D llen; - partial =3D !(pcl->length & Z_EROFS_PCLUSTER_FULL_LENGTH); - } else { - outputsize =3D (nr_pages << PAGE_SHIFT) - pcl->pageofs_out; - partial =3D true; - } - if (z_erofs_is_inline_pcluster(pcl)) inputsize =3D pcl->tailpacking_size; else @@ -1014,10 +989,10 @@ static int z_erofs_decompress_pcluster(struct z_erof= s_decompress_backend *be, .pageofs_in =3D pcl->pageofs_in, .pageofs_out =3D pcl->pageofs_out, .inputsize =3D inputsize, - .outputsize =3D outputsize, + .outputsize =3D pcl->length, .alg =3D pcl->algorithmformat, .inplace_io =3D overlapped, - .partial_decoding =3D partial + .partial_decoding =3D pcl->partial, }, be->pagepool); =20 out: @@ -1042,7 +1017,7 @@ static int z_erofs_decompress_pcluster(struct z_erofs= _decompress_backend *be, be->compressed_pages >=3D be->onstack_pages + Z_EROFS_ONSTACK_PAGES) kvfree(be->compressed_pages); =20 - for (i =3D 0; i < nr_pages; ++i) { + for (i =3D 0; i < be->nr_pages; ++i) { page =3D be->decompressed_pages[i]; if (!page) continue; @@ -1060,7 +1035,8 @@ static int z_erofs_decompress_pcluster(struct z_erofs= _decompress_backend *be, if (be->decompressed_pages !=3D be->onstack_pages) kvfree(be->decompressed_pages); =20 - pcl->nr_pages =3D 0; + pcl->length =3D 0; + pcl->partial =3D true; pcl->bvset.nextpage =3D NULL; pcl->vcnt =3D 0; =20 diff --git a/fs/erofs/zdata.h b/fs/erofs/zdata.h index ec09ca035fbb..a7fd44d21d9e 100644 --- a/fs/erofs/zdata.h +++ b/fs/erofs/zdata.h @@ -12,9 +12,6 @@ #define Z_EROFS_PCLUSTER_MAX_PAGES (Z_EROFS_PCLUSTER_MAX_SIZE / PAGE_SIZE) #define Z_EROFS_INLINE_BVECS 2 =20 -#define Z_EROFS_PCLUSTER_FULL_LENGTH 0x00000001 -#define Z_EROFS_PCLUSTER_LENGTH_BIT 1 - /* * let's leave a type here in case of introducing * another tagged pointer later. @@ -53,7 +50,7 @@ struct z_erofs_pcluster { /* A: point to next chained pcluster or TAILs */ z_erofs_next_pcluster_t next; =20 - /* A: lower limit of decompressed length and if full length or not */ + /* L: the maximum decompression size of this round */ unsigned int length; =20 /* L: total number of bvecs */ @@ -65,9 +62,6 @@ struct z_erofs_pcluster { /* I: page offset of inline compressed data */ unsigned short pageofs_in; =20 - /* L: maximum relative page index in bvecs */ - unsigned short nr_pages; - union { /* L: inline a certain number of bvec for bootstrap */ struct z_erofs_bvset_inline bvset; @@ -87,6 +81,9 @@ struct z_erofs_pcluster { /* I: compression algorithm format */ unsigned char algorithmformat; =20 + /* L: whether partial decompression or not */ + bool partial; + /* A: compressed bvecs (can be cached or inplaced pages) */ struct z_erofs_bvec compressed_bvecs[]; }; --=20 2.24.4 From nobody Sat Apr 18 10:52:27 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF85BC433EF for ; Thu, 14 Jul 2022 13:22:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239165AbiGNNWO (ORCPT ); Thu, 14 Jul 2022 09:22:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239777AbiGNNV1 (ORCPT ); Thu, 14 Jul 2022 09:21:27 -0400 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B43B95E330 for ; Thu, 14 Jul 2022 06:21:25 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R211e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045168;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VJJkPSH_1657804881; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJJkPSH_1657804881) by smtp.aliyun-inc.com; Thu, 14 Jul 2022 21:21:23 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang Subject: [PATCH 16/16] erofs: introduce multi-reference pclusters (fully-referenced) Date: Thu, 14 Jul 2022 21:20:51 +0800 Message-Id: <20220714132051.46012-17-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> References: <20220714132051.46012-1-hsiangkao@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Let's introduce multi-reference pclusters at runtime. In details, if one pcluster is requested by multiple extents at almost the same time (even belong to different files), the longest extent will be decompressed as representative and the other extents are actually copied from the longest one. After this patch, fully-referenced extents can be correctly handled and the full decoding check needs to be bypassed for partial-referenced extents. Signed-off-by: Gao Xiang --- fs/erofs/compress.h | 2 +- fs/erofs/decompressor.c | 2 +- fs/erofs/zdata.c | 120 +++++++++++++++++++++++++++------------- fs/erofs/zdata.h | 3 + 4 files changed, 88 insertions(+), 39 deletions(-) diff --git a/fs/erofs/compress.h b/fs/erofs/compress.h index 19e6c56a9f47..26fa170090b8 100644 --- a/fs/erofs/compress.h +++ b/fs/erofs/compress.h @@ -17,7 +17,7 @@ struct z_erofs_decompress_req { =20 /* indicate the algorithm will be used for decompression */ unsigned int alg; - bool inplace_io, partial_decoding; + bool inplace_io, partial_decoding, fillgaps; }; =20 struct z_erofs_decompressor { diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c index 6dca1900c733..91b9bff10198 100644 --- a/fs/erofs/decompressor.c +++ b/fs/erofs/decompressor.c @@ -83,7 +83,7 @@ static int z_erofs_lz4_prepare_dstpages(struct z_erofs_lz= 4_decompress_ctx *ctx, j =3D 0; =20 /* 'valid' bounced can only be tested after a complete round */ - if (test_bit(j, bounced)) { + if (!rq->fillgaps && test_bit(j, bounced)) { DBG_BUGON(i < lz4_max_distance_pages); DBG_BUGON(top >=3D lz4_max_distance_pages); availables[top++] =3D rq->out[i - lz4_max_distance_pages]; diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index 8dcfc2a9704e..601cfcb07c50 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -467,7 +467,8 @@ static void z_erofs_try_to_claim_pcluster(struct z_erof= s_decompress_frontend *f) * type 2, link to the end of an existing open chain, be careful * that its submission is controlled by the original attached chain. */ - if (cmpxchg(&pcl->next, Z_EROFS_PCLUSTER_TAIL, + if (*owned_head !=3D &pcl->next && pcl !=3D f->tailpcl && + cmpxchg(&pcl->next, Z_EROFS_PCLUSTER_TAIL, *owned_head) =3D=3D Z_EROFS_PCLUSTER_TAIL) { *owned_head =3D Z_EROFS_PCLUSTER_TAIL; f->mode =3D Z_EROFS_PCLUSTER_HOOKED; @@ -480,20 +481,8 @@ static void z_erofs_try_to_claim_pcluster(struct z_ero= fs_decompress_frontend *f) =20 static int z_erofs_lookup_pcluster(struct z_erofs_decompress_frontend *fe) { - struct erofs_map_blocks *map =3D &fe->map; struct z_erofs_pcluster *pcl =3D fe->pcl; =20 - /* to avoid unexpected loop formed by corrupted images */ - if (fe->owned_head =3D=3D &pcl->next || pcl =3D=3D fe->tailpcl) { - DBG_BUGON(1); - return -EFSCORRUPTED; - } - - if (pcl->pageofs_out !=3D (map->m_la & ~PAGE_MASK)) { - DBG_BUGON(1); - return -EFSCORRUPTED; - } - mutex_lock(&pcl->lock); /* used to check tail merging loop due to corrupted images */ if (fe->owned_head =3D=3D Z_EROFS_PCLUSTER_TAIL) @@ -785,6 +774,8 @@ static int z_erofs_do_read_page(struct z_erofs_decompre= ss_frontend *fe, z_erofs_onlinepage_split(page); /* bump up the number of spiltted parts of a page */ ++spiltted; + fe->pcl->multibases =3D + (fe->pcl->pageofs_out !=3D (map->m_la & ~PAGE_MASK)); =20 if (fe->pcl->length < offset + end - map->m_la) { fe->pcl->length =3D offset + end - map->m_la; @@ -842,36 +833,90 @@ struct z_erofs_decompress_backend { /* pages to keep the compressed data */ struct page **compressed_pages; =20 + struct list_head decompressed_secondary_bvecs; struct page **pagepool; unsigned int onstack_used, nr_pages; }; =20 -static int z_erofs_do_decompressed_bvec(struct z_erofs_decompress_backend = *be, - struct z_erofs_bvec *bvec) +struct z_erofs_bvec_item { + struct z_erofs_bvec bvec; + struct list_head list; +}; + +static void z_erofs_do_decompressed_bvec(struct z_erofs_decompress_backend= *be, + struct z_erofs_bvec *bvec) { - unsigned int pgnr =3D (bvec->offset + be->pcl->pageofs_out) >> PAGE_SHIFT; - struct page *oldpage; + struct z_erofs_bvec_item *item; =20 - DBG_BUGON(pgnr >=3D be->nr_pages); - oldpage =3D be->decompressed_pages[pgnr]; - be->decompressed_pages[pgnr] =3D bvec->page; + if (!((bvec->offset + be->pcl->pageofs_out) & ~PAGE_MASK)) { + unsigned int pgnr; + struct page *oldpage; =20 - /* error out if one pcluster is refenenced multiple times. */ - if (oldpage) { - DBG_BUGON(1); - z_erofs_page_mark_eio(oldpage); - z_erofs_onlinepage_endio(oldpage); - return -EFSCORRUPTED; + pgnr =3D (bvec->offset + be->pcl->pageofs_out) >> PAGE_SHIFT; + DBG_BUGON(pgnr >=3D be->nr_pages); + oldpage =3D be->decompressed_pages[pgnr]; + be->decompressed_pages[pgnr] =3D bvec->page; + + if (!oldpage) + return; + } + + /* (cold path) one pcluster is requested multiple times */ + item =3D kmalloc(sizeof(*item), GFP_KERNEL | __GFP_NOFAIL); + item->bvec =3D *bvec; + list_add(&item->list, &be->decompressed_secondary_bvecs); +} + +static void z_erofs_fill_other_copies(struct z_erofs_decompress_backend *b= e, + int err) +{ + unsigned int off0 =3D be->pcl->pageofs_out; + struct list_head *p, *n; + + list_for_each_safe(p, n, &be->decompressed_secondary_bvecs) { + struct z_erofs_bvec_item *bvi; + unsigned int end, cur; + void *dst, *src; + + bvi =3D container_of(p, struct z_erofs_bvec_item, list); + cur =3D bvi->bvec.offset < 0 ? -bvi->bvec.offset : 0; + end =3D min_t(unsigned int, be->pcl->length - bvi->bvec.offset, + bvi->bvec.end); + dst =3D kmap_local_page(bvi->bvec.page); + while (cur < end) { + unsigned int pgnr, scur, len; + + pgnr =3D (bvi->bvec.offset + cur + off0) >> PAGE_SHIFT; + DBG_BUGON(pgnr >=3D be->nr_pages); + + scur =3D bvi->bvec.offset + cur - + ((pgnr << PAGE_SHIFT) - off0); + len =3D min_t(unsigned int, end - cur, PAGE_SIZE - scur); + if (!be->decompressed_pages[pgnr]) { + err =3D -EFSCORRUPTED; + cur +=3D len; + continue; + } + src =3D kmap_local_page(be->decompressed_pages[pgnr]); + memcpy(dst + cur, src + scur, len); + kunmap_local(src); + cur +=3D len; + } + kunmap_local(dst); + if (err) + z_erofs_page_mark_eio(bvi->bvec.page); + z_erofs_onlinepage_endio(bvi->bvec.page); + list_del(p); + kfree(bvi); } - return 0; } =20 -static int z_erofs_parse_out_bvecs(struct z_erofs_decompress_backend *be) +static void z_erofs_parse_out_bvecs(struct z_erofs_decompress_backend *be) { struct z_erofs_pcluster *pcl =3D be->pcl; struct z_erofs_bvec_iter biter; struct page *old_bvpage; - int i, err =3D 0; + int i; =20 z_erofs_bvec_iter_begin(&biter, &pcl->bvset, Z_EROFS_INLINE_BVECS, 0); for (i =3D 0; i < pcl->vcnt; ++i) { @@ -883,13 +928,12 @@ static int z_erofs_parse_out_bvecs(struct z_erofs_dec= ompress_backend *be) z_erofs_put_shortlivedpage(be->pagepool, old_bvpage); =20 DBG_BUGON(z_erofs_page_is_invalidated(bvec.page)); - err =3D z_erofs_do_decompressed_bvec(be, &bvec); + z_erofs_do_decompressed_bvec(be, &bvec); } =20 old_bvpage =3D z_erofs_bvec_iter_end(&biter); if (old_bvpage) z_erofs_put_shortlivedpage(be->pagepool, old_bvpage); - return err; } =20 static int z_erofs_parse_in_bvecs(struct z_erofs_decompress_backend *be, @@ -924,7 +968,7 @@ static int z_erofs_parse_in_bvecs(struct z_erofs_decomp= ress_backend *be, err =3D -EIO; continue; } - err =3D z_erofs_do_decompressed_bvec(be, bvec); + z_erofs_do_decompressed_bvec(be, bvec); *overlapped =3D true; } } @@ -940,7 +984,7 @@ static int z_erofs_decompress_pcluster(struct z_erofs_d= ecompress_backend *be, struct erofs_sb_info *const sbi =3D EROFS_SB(be->sb); struct z_erofs_pcluster *pcl =3D be->pcl; unsigned int pclusterpages =3D z_erofs_pclusterpages(pcl); - unsigned int i, inputsize, err2; + unsigned int i, inputsize; struct page *page; bool overlapped; =20 @@ -970,10 +1014,8 @@ static int z_erofs_decompress_pcluster(struct z_erofs= _decompress_backend *be, kvcalloc(pclusterpages, sizeof(struct page *), GFP_KERNEL | __GFP_NOFAIL); =20 - err =3D z_erofs_parse_out_bvecs(be); - err2 =3D z_erofs_parse_in_bvecs(be, &overlapped); - if (err2) - err =3D err2; + z_erofs_parse_out_bvecs(be); + err =3D z_erofs_parse_in_bvecs(be, &overlapped); if (err) goto out; =20 @@ -993,6 +1035,7 @@ static int z_erofs_decompress_pcluster(struct z_erofs_= decompress_backend *be, .alg =3D pcl->algorithmformat, .inplace_io =3D overlapped, .partial_decoding =3D pcl->partial, + .fillgaps =3D pcl->multibases, }, be->pagepool); =20 out: @@ -1016,6 +1059,7 @@ static int z_erofs_decompress_pcluster(struct z_erofs= _decompress_backend *be, if (be->compressed_pages < be->onstack_pages || be->compressed_pages >=3D be->onstack_pages + Z_EROFS_ONSTACK_PAGES) kvfree(be->compressed_pages); + z_erofs_fill_other_copies(be, err); =20 for (i =3D 0; i < be->nr_pages; ++i) { page =3D be->decompressed_pages[i]; @@ -1052,6 +1096,8 @@ static void z_erofs_decompress_queue(const struct z_e= rofs_decompressqueue *io, struct z_erofs_decompress_backend be =3D { .sb =3D io->sb, .pagepool =3D pagepool, + .decompressed_secondary_bvecs =3D + LIST_HEAD_INIT(be.decompressed_secondary_bvecs), }; z_erofs_next_pcluster_t owned =3D io->head; =20 diff --git a/fs/erofs/zdata.h b/fs/erofs/zdata.h index a7fd44d21d9e..515fa2b28b97 100644 --- a/fs/erofs/zdata.h +++ b/fs/erofs/zdata.h @@ -84,6 +84,9 @@ struct z_erofs_pcluster { /* L: whether partial decompression or not */ bool partial; =20 + /* L: indicate several pageofs_outs or not */ + bool multibases; + /* A: compressed bvecs (can be cached or inplaced pages) */ struct z_erofs_bvec compressed_bvecs[]; }; --=20 2.24.4