From nobody Sat Apr 18 07:41:34 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 461CAC43334 for ; Fri, 15 Jul 2022 15:42:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231782AbiGOPma (ORCPT ); Fri, 15 Jul 2022 11:42:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229772AbiGOPmS (ORCPT ); Fri, 15 Jul 2022 11:42: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 52DDA51A03 for ; Fri, 15 Jul 2022 08:42:16 -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=ay29a033018046060;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0VJPnC1Z_1657899731; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJPnC1Z_1657899731) by smtp.aliyun-inc.com; Fri, 15 Jul 2022 23:42:12 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang , Yue Hu Subject: [PATCH v2 01/16] erofs: get rid of unneeded `inode', `map' and `sb' Date: Fri, 15 Jul 2022 23:41:48 +0800 Message-Id: <20220715154203.48093-2-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220715154203.48093-1-hsiangkao@linux.alibaba.com> References: <20220715154203.48093-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. Reviewed-by: Yue Hu Signed-off-by: Gao Xiang Acked-by: Chao Yu --- 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 07:41:34 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 51D1AC43334 for ; Fri, 15 Jul 2022 15:42:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235568AbiGOPmr (ORCPT ); Fri, 15 Jul 2022 11:42:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233608AbiGOPmZ (ORCPT ); Fri, 15 Jul 2022 11:42:25 -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 5EE605508B for ; Fri, 15 Jul 2022 08:42:24 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R691e4;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=5;SR=0;TI=SMTPD_---0VJPnC2I_1657899733; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJPnC2I_1657899733) by smtp.aliyun-inc.com; Fri, 15 Jul 2022 23:42:14 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang , Yue Hu Subject: [PATCH v2 02/16] erofs: clean up z_erofs_collector_begin() Date: Fri, 15 Jul 2022 23:41:49 +0800 Message-Id: <20220715154203.48093-3-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220715154203.48093-1-hsiangkao@linux.alibaba.com> References: <20220715154203.48093-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. Reviewed-by: Yue Hu Signed-off-by: Gao Xiang Acked-by: Chao Yu --- 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 07:41:34 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 43BCCC433EF for ; Fri, 15 Jul 2022 15:42:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235177AbiGOPme (ORCPT ); Fri, 15 Jul 2022 11:42:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233196AbiGOPmU (ORCPT ); Fri, 15 Jul 2022 11:42:20 -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 AD17751A03 for ; Fri, 15 Jul 2022 08:42:19 -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=e01e04400;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0VJPnC30_1657899734; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJPnC30_1657899734) by smtp.aliyun-inc.com; Fri, 15 Jul 2022 23:42:15 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang , Yue Hu Subject: [PATCH v2 03/16] erofs: introduce `z_erofs_parse_out_bvecs()' Date: Fri, 15 Jul 2022 23:41:50 +0800 Message-Id: <20220715154203.48093-4-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220715154203.48093-1-hsiangkao@linux.alibaba.com> References: <20220715154203.48093-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. Reviewed-by: Yue Hu Signed-off-by: Gao Xiang Acked-by: Chao Yu --- 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 07:41:34 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 E064EC433EF for ; Fri, 15 Jul 2022 15:42:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235558AbiGOPmp (ORCPT ); Fri, 15 Jul 2022 11:42:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233615AbiGOPmZ (ORCPT ); Fri, 15 Jul 2022 11:42:25 -0400 Received: from out30-57.freemail.mail.aliyun.com (out30-57.freemail.mail.aliyun.com [115.124.30.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B931528A7 for ; Fri, 15 Jul 2022 08:42:20 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R631e4;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_---0VJPnC3d_1657899735; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJPnC3d_1657899735) by smtp.aliyun-inc.com; Fri, 15 Jul 2022 23:42:16 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang Subject: [PATCH v2 04/16] erofs: introduce bufvec to store decompressed buffers Date: Fri, 15 Jul 2022 23:41:51 +0800 Message-Id: <20220715154203.48093-5-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220715154203.48093-1-hsiangkao@linux.alibaba.com> References: <20220715154203.48093-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. It's calculated by `page_offset(page) - map->m_la'; - 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 Acked-by: Chao Yu --- 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..f8daadb19e37 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 07:41:34 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 A62AACCA481 for ; Fri, 15 Jul 2022 15:42:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235030AbiGOPmh (ORCPT ); Fri, 15 Jul 2022 11:42:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233356AbiGOPmY (ORCPT ); Fri, 15 Jul 2022 11:42:24 -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 EDF4351A03 for ; Fri, 15 Jul 2022 08:42:22 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R751e4;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_---0VJPnC44_1657899737; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJPnC44_1657899737) by smtp.aliyun-inc.com; Fri, 15 Jul 2022 23:42:17 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang Subject: [PATCH v2 05/16] erofs: drop the old pagevec approach Date: Fri, 15 Jul 2022 23:41:52 +0800 Message-Id: <20220715154203.48093-6-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220715154203.48093-1-hsiangkao@linux.alibaba.com> References: <20220715154203.48093-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 Acked-by: Chao Yu --- fs/erofs/zdata.c | 21 +++++-- fs/erofs/zdata.h | 9 +-- fs/erofs/zpvec.h | 159 ----------------------------------------------- 3 files changed, 18 insertions(+), 171 deletions(-) delete mode 100644 fs/erofs/zpvec.h diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index f52c54058f31..6295f3312f6f 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 +/* (obsoleted) page type for online pages */ +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; @@ -248,7 +259,7 @@ enum z_erofs_collectmode { * a weak form of COLLECT_PRIMARY_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. + * bvpage) since it can be directly decoded without I/O submission. */ COLLECT_PRIMARY_FOLLOWED_NOINPLACE, /* @@ -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); @@ -776,7 +786,7 @@ static int z_erofs_do_read_page(struct z_erofs_decompre= ss_frontend *fe, * Ensure the current partial page belongs to this submit chain rather * than other concurrent submit chains or the noio(bypass) chain since * those chains are handled asynchronously thus the page cannot be used - * for inplace I/O or pagevec (should be processed in strict order.) + * for inplace I/O or bvpage (should be processed in a strict order.) */ tight &=3D (fe->mode >=3D COLLECT_PRIMARY_HOOKED && fe->mode !=3D COLLECT_PRIMARY_FOLLOWED_NOINPLACE); @@ -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 f8daadb19e37..468f6308fc90 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 07:41:34 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 0041ECCA47C for ; Fri, 15 Jul 2022 15:42:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235480AbiGOPmk (ORCPT ); Fri, 15 Jul 2022 11:42:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233592AbiGOPmZ (ORCPT ); Fri, 15 Jul 2022 11:42:25 -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 5AF8653D0C for ; Fri, 15 Jul 2022 08:42:23 -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=ay29a033018046059;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VJPnC4R_1657899738; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJPnC4R_1657899738) by smtp.aliyun-inc.com; Fri, 15 Jul 2022 23:42:19 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang Subject: [PATCH v2 06/16] erofs: introduce `z_erofs_parse_in_bvecs' Date: Fri, 15 Jul 2022 23:41:53 +0800 Message-Id: <20220715154203.48093-7-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220715154203.48093-1-hsiangkao@linux.alibaba.com> References: <20220715154203.48093-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 Acked-by: Chao Yu --- 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 6295f3312f6f..423d4daf7ed9 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 07:41:34 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 BE02BCCA480 for ; Fri, 15 Jul 2022 15:42:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235744AbiGOPmz (ORCPT ); Fri, 15 Jul 2022 11:42:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234937AbiGOPm1 (ORCPT ); Fri, 15 Jul 2022 11:42:27 -0400 Received: from out30-44.freemail.mail.aliyun.com (out30-44.freemail.mail.aliyun.com [115.124.30.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 805FE53D0C for ; Fri, 15 Jul 2022 08:42:24 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R471e4;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_---0VJPnC51_1657899739; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJPnC51_1657899739) by smtp.aliyun-inc.com; Fri, 15 Jul 2022 23:42:20 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang Subject: [PATCH v2 07/16] erofs: switch compressed_pages[] to bufvec Date: Fri, 15 Jul 2022 23:41:54 +0800 Message-Id: <20220715154203.48093-8-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220715154203.48093-1-hsiangkao@linux.alibaba.com> References: <20220715154203.48093-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 Acked-by: Chao Yu --- 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 423d4daf7ed9..2ea8c97be5b6 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 468f6308fc90..5d236c8b40c5 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 07:41:34 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 9D4ACC433EF for ; Fri, 15 Jul 2022 15:42:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235603AbiGOPmw (ORCPT ); Fri, 15 Jul 2022 11:42:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234734AbiGOPm1 (ORCPT ); Fri, 15 Jul 2022 11:42:27 -0400 Received: from out199-8.us.a.mail.aliyun.com (out199-8.us.a.mail.aliyun.com [47.90.199.8]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78B2351A03 for ; Fri, 15 Jul 2022 08:42:25 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;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_---0VJPnC5b_1657899740; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJPnC5b_1657899740) by smtp.aliyun-inc.com; Fri, 15 Jul 2022 23:42:21 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang Subject: [PATCH v2 08/16] erofs: rework online page handling Date: Fri, 15 Jul 2022 23:41:55 +0800 Message-Id: <20220715154203.48093-9-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220715154203.48093-1-hsiangkao@linux.alibaba.com> References: <20220715154203.48093-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 Acked-by: Chao Yu --- fs/erofs/zdata.c | 57 ++++++++++++++++------------------------ fs/erofs/zdata.h | 68 ++++++++++++++---------------------------------- 2 files changed, 42 insertions(+), 83 deletions(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index 2ea8c97be5b6..2d5e2ed3e5f5 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,16 +971,15 @@ static struct page **z_erofs_parse_in_bvecs(struct er= ofs_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); unsigned int i, inputsize, outputsize, llen, nr_pages; struct page *pages_onstack[Z_EROFS_VMAP_ONSTACK_PAGES]; struct page **pages, **compressed_pages, *page; - + int err2; bool overlapped, partial; - int err; =20 might_sleep(); DBG_BUGON(!READ_ONCE(pcl->nr_pages)); @@ -1022,7 +1011,9 @@ static int z_erofs_decompress_pcluster(struct super_b= lock *sb, for (i =3D 0; i < nr_pages; ++i) pages[i] =3D NULL; =20 - err =3D z_erofs_parse_out_bvecs(pcl, pages, pagepool); + err2 =3D z_erofs_parse_out_bvecs(pcl, pages, pagepool); + if (err2) + err =3D err2; compressed_pages =3D z_erofs_parse_in_bvecs(sbi, pcl, pages, pagepool, &overlapped); if (IS_ERR(compressed_pages)) { @@ -1090,10 +1081,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 +1118,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 +1223,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 +1294,7 @@ jobqueue_init(struct super_block *sb, q =3D fgq; init_completion(&fgq->u.done); atomic_set(&fgq->pending_bios, 0); + q->eio =3D false; } q->sb =3D sb; q->head =3D Z_EROFS_PCLUSTER_TAIL_CLOSED; @@ -1365,15 +1355,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 5d236c8b40c5..75f6fd435388 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 07:41:34 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 89D1FCCA481 for ; Fri, 15 Jul 2022 15:42:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235802AbiGOPm5 (ORCPT ); Fri, 15 Jul 2022 11:42:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234996AbiGOPm1 (ORCPT ); Fri, 15 Jul 2022 11:42:27 -0400 Received: from out199-12.us.a.mail.aliyun.com (out199-12.us.a.mail.aliyun.com [47.90.199.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 646B9528A7 for ; Fri, 15 Jul 2022 08:42:26 -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=ay29a033018046051;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VJPnC6._1657899741; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJPnC6._1657899741) by smtp.aliyun-inc.com; Fri, 15 Jul 2022 23:42:22 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang Subject: [PATCH v2 09/16] erofs: get rid of `enum z_erofs_page_type' Date: Fri, 15 Jul 2022 23:41:56 +0800 Message-Id: <20220715154203.48093-10-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220715154203.48093-1-hsiangkao@linux.alibaba.com> References: <20220715154203.48093-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 Acked-by: Chao Yu --- 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 2d5e2ed3e5f5..f2a513299d82 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 -/* (obsoleted) page type for online pages */ -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 07:41:34 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 29994C433EF for ; Fri, 15 Jul 2022 15:43:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235589AbiGOPnF (ORCPT ); Fri, 15 Jul 2022 11:43:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235095AbiGOPmb (ORCPT ); Fri, 15 Jul 2022 11:42:31 -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 4EE7259249 for ; Fri, 15 Jul 2022 08:42:29 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R201e4;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_---0VJPnC6b_1657899743; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJPnC6b_1657899743) by smtp.aliyun-inc.com; Fri, 15 Jul 2022 23:42:24 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang Subject: [PATCH v2 10/16] erofs: clean up `enum z_erofs_collectmode' Date: Fri, 15 Jul 2022 23:41:57 +0800 Message-Id: <20220715154203.48093-11-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220715154203.48093-1-hsiangkao@linux.alibaba.com> References: <20220715154203.48093-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 Acked-by: Chao Yu --- 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 f2a513299d82..d1f907f4757d 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 * bvpage) 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 bvpage (should be processed in a 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 07:41:34 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 CA1CBC43334 for ; Fri, 15 Jul 2022 15:43:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235533AbiGOPnC (ORCPT ); Fri, 15 Jul 2022 11:43:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235080AbiGOPmb (ORCPT ); Fri, 15 Jul 2022 11:42:31 -0400 Received: from out30-44.freemail.mail.aliyun.com (out30-44.freemail.mail.aliyun.com [115.124.30.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DBFF58841 for ; Fri, 15 Jul 2022 08:42:28 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R521e4;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_---0VJPnC79_1657899744; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJPnC79_1657899744) by smtp.aliyun-inc.com; Fri, 15 Jul 2022 23:42:25 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang Subject: [PATCH v2 11/16] erofs: get rid of `z_pagemap_global' Date: Fri, 15 Jul 2022 23:41:58 +0800 Message-Id: <20220715154203.48093-12-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220715154203.48093-1-hsiangkao@linux.alibaba.com> References: <20220715154203.48093-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 Acked-by: Chao Yu --- 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 d1f907f4757d..3f735ca0415e 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; @@ -1065,9 +1047,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 75f6fd435388..43c91bd2d84f 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 07:41:34 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 88C9BCCA47C for ; Fri, 15 Jul 2022 15:43:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235924AbiGOPnZ (ORCPT ); Fri, 15 Jul 2022 11:43:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235510AbiGOPml (ORCPT ); Fri, 15 Jul 2022 11:42:41 -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 E36FD5E317 for ; Fri, 15 Jul 2022 08:42:34 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R891e4;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_---0VJPnC7r_1657899745; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJPnC7r_1657899745) by smtp.aliyun-inc.com; Fri, 15 Jul 2022 23:42:26 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang Subject: [PATCH v2 12/16] erofs: introduce struct z_erofs_decompress_backend Date: Fri, 15 Jul 2022 23:41:59 +0800 Message-Id: <20220715154203.48093-13-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220715154203.48093-1-hsiangkao@linux.alibaba.com> References: <20220715154203.48093-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 Acked-by: Chao Yu --- fs/erofs/zdata.c | 140 +++++++++++++++++++++++++---------------------- fs/erofs/zdata.h | 3 +- 2 files changed, 76 insertions(+), 67 deletions(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index 3f735ca0415e..1cf377ed1452 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,60 +940,58 @@ 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; + struct page *page; int err2; 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; + 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 - err2 =3D z_erofs_parse_out_bvecs(pcl, pages, pagepool); + err2 =3D z_erofs_parse_out_bvecs(be); + if (err2) + err =3D err2; + err2 =3D z_erofs_parse_in_bvecs(be, &overlapped); if (err2) err =3D err2; - 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) goto out; @@ -1000,9 +1011,9 @@ static int z_erofs_decompress_pcluster(struct super_b= lock *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, @@ -1010,7 +1021,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 */ @@ -1026,29 +1037,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; @@ -1063,23 +1074,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 @@ -1105,7 +1116,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 43c91bd2d84f..be0f19aa0d2d 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 07:41:34 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 7755EC43334 for ; Fri, 15 Jul 2022 15:43:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235862AbiGOPnV (ORCPT ); Fri, 15 Jul 2022 11:43:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235507AbiGOPml (ORCPT ); Fri, 15 Jul 2022 11:42:41 -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 CA1645D59F for ; Fri, 15 Jul 2022 08:42:34 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R201e4;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_---0VJPnC8L_1657899746; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJPnC8L_1657899746) by smtp.aliyun-inc.com; Fri, 15 Jul 2022 23:42:27 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang Subject: [PATCH v2 13/16] erofs: try to leave (de)compressed_pages on stack if possible Date: Fri, 15 Jul 2022 23:42:00 +0800 Message-Id: <20220715154203.48093-14-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220715154203.48093-1-hsiangkao@linux.alibaba.com> References: <20220715154203.48093-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 Acked-by: Chao Yu --- 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 1cf377ed1452..d93ba0adcf9e 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 @@ -976,15 +969,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 err2 =3D z_erofs_parse_out_bvecs(be); if (err2) @@ -1041,7 +1047,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 07:41:34 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 53A94C43334 for ; Fri, 15 Jul 2022 15:43:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235817AbiGOPnL (ORCPT ); Fri, 15 Jul 2022 11:43:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235064AbiGOPmg (ORCPT ); Fri, 15 Jul 2022 11:42:36 -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 8BB055B7BC for ; Fri, 15 Jul 2022 08:42:32 -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=ay29a033018046059;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VJPnC8s_1657899747; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJPnC8s_1657899747) by smtp.aliyun-inc.com; Fri, 15 Jul 2022 23:42:28 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang Subject: [PATCH v2 14/16] erofs: introduce z_erofs_do_decompressed_bvec() Date: Fri, 15 Jul 2022 23:42:01 +0800 Message-Id: <20220715154203.48093-15-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220715154203.48093-1-hsiangkao@linux.alibaba.com> References: <20220715154203.48093-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 Acked-by: Chao Yu --- 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 d93ba0adcf9e..d4db2c1d53a6 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 07:41:34 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 ECB1EC433EF for ; Fri, 15 Jul 2022 15:43:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235639AbiGOPnH (ORCPT ); Fri, 15 Jul 2022 11:43:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235029AbiGOPmf (ORCPT ); Fri, 15 Jul 2022 11:42:35 -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 9A7135B7AF for ; Fri, 15 Jul 2022 08:42:32 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R511e4;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_---0VJPnC9N_1657899749; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJPnC9N_1657899749) by smtp.aliyun-inc.com; Fri, 15 Jul 2022 23:42:29 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang Subject: [PATCH v2 15/16] erofs: record the longest decompressed size in this round Date: Fri, 15 Jul 2022 23:42:02 +0800 Message-Id: <20220715154203.48093-16-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220715154203.48093-1-hsiangkao@linux.alibaba.com> References: <20220715154203.48093-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 Acked-by: Chao Yu --- fs/erofs/zdata.c | 78 +++++++++++++++++------------------------------- fs/erofs/zdata.h | 11 +++---- 2 files changed, 31 insertions(+), 58 deletions(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index d4db2c1d53a6..0ef672372a69 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 ((map->m_flags & EROFS_MAP_FULL_MAPPED) && + fe->pcl->length =3D=3D map->m_llen) + fe->pcl->partial =3D false; + 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; + } 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,24 +940,23 @@ 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; - struct page *page; + unsigned int i, inputsize; int err2; - bool overlapped, partial; + struct page *page; + 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) @@ -980,7 +964,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 @@ -997,15 +981,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 @@ -1018,10 +993,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: @@ -1046,7 +1021,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; @@ -1064,7 +1039,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 be0f19aa0d2d..4ae3b763bc27 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 07:41:34 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 5D0EBC433EF for ; Fri, 15 Jul 2022 15:43:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235854AbiGOPnS (ORCPT ); Fri, 15 Jul 2022 11:43:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235463AbiGOPmk (ORCPT ); Fri, 15 Jul 2022 11:42:40 -0400 Received: from out30-57.freemail.mail.aliyun.com (out30-57.freemail.mail.aliyun.com [115.124.30.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60AB05C9C7 for ; Fri, 15 Jul 2022 08:42:34 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R581e4;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_---0VJPnC9n_1657899750; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VJPnC9n_1657899750) by smtp.aliyun-inc.com; Fri, 15 Jul 2022 23:42:31 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu Cc: LKML , Gao Xiang Subject: [PATCH v2 16/16] erofs: introduce multi-reference pclusters (fully-referenced) Date: Fri, 15 Jul 2022 23:42:03 +0800 Message-Id: <20220715154203.48093-17-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20220715154203.48093-1-hsiangkao@linux.alibaba.com> References: <20220715154203.48093-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 Acked-by: Chao Yu --- fs/erofs/compress.h | 2 +- fs/erofs/decompressor.c | 2 +- fs/erofs/zdata.c | 118 ++++++++++++++++++++++++++++------------ fs/erofs/zdata.h | 3 + 4 files changed, 87 insertions(+), 38 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 45be8f4aeb68..2d55569f96ac 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 0ef672372a69..d2b8bc20965c 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; + if (fe->pcl->pageofs_out !=3D (map->m_la & ~PAGE_MASK)) + fe->pcl->multibases =3D true; =20 if ((map->m_flags & EROFS_MAP_FULL_MAPPED) && fe->pcl->length =3D=3D map->m_llen) @@ -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; } } @@ -971,13 +1015,10 @@ static int z_erofs_decompress_pcluster(struct z_erof= s_decompress_backend *be, kvcalloc(pclusterpages, sizeof(struct page *), GFP_KERNEL | __GFP_NOFAIL); =20 - err2 =3D z_erofs_parse_out_bvecs(be); - if (err2) - err =3D err2; + 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 @@ -997,6 +1038,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: @@ -1020,6 +1062,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]; @@ -1041,6 +1084,7 @@ static int z_erofs_decompress_pcluster(struct z_erofs= _decompress_backend *be, =20 pcl->length =3D 0; pcl->partial =3D true; + pcl->multibases =3D false; pcl->bvset.nextpage =3D NULL; pcl->vcnt =3D 0; =20 @@ -1056,6 +1100,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 4ae3b763bc27..e7f04c4fbb81 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