From nobody Thu Sep 18 23:16:07 2025 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 E5503C43217 for ; Thu, 1 Dec 2022 07:43:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229681AbiLAHnJ (ORCPT ); Thu, 1 Dec 2022 02:43:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229520AbiLAHnC (ORCPT ); Thu, 1 Dec 2022 02:43:02 -0500 Received: from out30-8.freemail.mail.aliyun.com (out30-8.freemail.mail.aliyun.com [115.124.30.8]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A8781837D for ; Wed, 30 Nov 2022 23:43:01 -0800 (PST) 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=ay29a033018046050;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VW7gJ--_1669880577; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VW7gJ--_1669880577) by smtp.aliyun-inc.com; Thu, 01 Dec 2022 15:42:58 +0800 From: Jingbo Xu To: xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH v4 1/2] erofs: support large folios for fscache mode Date: Thu, 1 Dec 2022 15:42:55 +0800 Message-Id: <20221201074256.16639-2-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20221201074256.16639-1-jefflexu@linux.alibaba.com> References: <20221201074256.16639-1-jefflexu@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" When large folios supported, one folio can be split into several slices, each of which may be mapped to META/UNMAPPED/MAPPED, and the folio can be unlocked as a whole only when all slices have completed. Thus always allocate erofs_fscache_request for each .read_folio() or .readahead(), in which case the allocated request is responsible for unlocking folios when all slices have completed. As described above, each folio or folio range can be mapped into several slices, while these slices may be mapped to different cookies, and thus each slice needs its own netfs_cache_resources. Here we introduce chained requests to support this, where each .read_folio() or .readahead() calling can correspond to multiple requests. Each request has its own netfs_cache_resources and thus is used to access one cookie. Among these requests, there's a primary request, with the others pointing to the primary request. Signed-off-by: Jingbo Xu Reviewed-by: Jia Zhu --- fs/erofs/fscache.c | 148 ++++++++++++++++++++++++--------------------- 1 file changed, 80 insertions(+), 68 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 3e794891cd91..f14886c479bd 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -12,6 +12,7 @@ static LIST_HEAD(erofs_domain_list); static struct vfsmount *erofs_pseudo_mnt; =20 struct erofs_fscache_request { + struct erofs_fscache_request *primary; struct netfs_cache_resources cache_resources; struct address_space *mapping; /* The mapping being accessed */ loff_t start; /* Start position */ @@ -38,6 +39,26 @@ static struct erofs_fscache_request *erofs_fscache_req_a= lloc(struct address_spac return req; } =20 +static struct erofs_fscache_request *erofs_fscache_req_chain(struct erofs_= fscache_request *primary, + size_t len) +{ + struct erofs_fscache_request *req; + + /* use primary request for the first submission */ + if (!primary->submitted) { + refcount_inc(&primary->ref); + return primary; + } + + req =3D erofs_fscache_req_alloc(primary->mapping, + primary->start + primary->submitted, len); + if (!IS_ERR(req)) { + req->primary =3D primary; + refcount_inc(&primary->ref); + } + return req; +} + static void erofs_fscache_req_complete(struct erofs_fscache_request *req) { struct folio *folio; @@ -56,17 +77,19 @@ static void erofs_fscache_req_complete(struct erofs_fsc= ache_request *req) folio_unlock(folio); } rcu_read_unlock(); - - if (req->cache_resources.ops) - req->cache_resources.ops->end_operation(&req->cache_resources); - - kfree(req); } =20 static void erofs_fscache_req_put(struct erofs_fscache_request *req) { - if (refcount_dec_and_test(&req->ref)) - erofs_fscache_req_complete(req); + if (refcount_dec_and_test(&req->ref)) { + if (req->cache_resources.ops) + req->cache_resources.ops->end_operation(&req->cache_resources); + if (!req->primary) + erofs_fscache_req_complete(req); + else + erofs_fscache_req_put(req->primary); + kfree(req); + } } =20 static void erofs_fscache_subreq_complete(void *priv, @@ -74,8 +97,12 @@ static void erofs_fscache_subreq_complete(void *priv, { struct erofs_fscache_request *req =3D priv; =20 - if (IS_ERR_VALUE(transferred_or_error)) - req->error =3D transferred_or_error; + if (IS_ERR_VALUE(transferred_or_error)) { + if (req->primary) + req->primary->error =3D transferred_or_error; + else + req->error =3D transferred_or_error; + } erofs_fscache_req_put(req); } =20 @@ -131,7 +158,6 @@ static int erofs_fscache_read_folios_async(struct fscac= he_cookie *cookie, done +=3D slen; } DBG_BUGON(done !=3D len); - req->submitted +=3D len; return 0; } =20 @@ -167,32 +193,19 @@ static int erofs_fscache_meta_read_folio(struct file = *data, struct folio *folio) return ret; } =20 -/* - * Read into page cache in the range described by (@pos, @len). - * - * On return, if the output @unlock is true, the caller is responsible for= page - * unlocking; otherwise the callee will take this responsibility through r= equest - * completion. - * - * The return value is the number of bytes successfully handled, or negati= ve - * error code on failure. The only exception is that, the length of the ra= nge - * instead of the error code is returned on failure after request is alloc= ated, - * so that .readahead() could advance rac accordingly. - */ -static int erofs_fscache_data_read(struct address_space *mapping, - loff_t pos, size_t len, bool *unlock) +static int erofs_fscache_data_read_slice(struct erofs_fscache_request *pri= mary) { + struct address_space *mapping =3D primary->mapping; struct inode *inode =3D mapping->host; struct super_block *sb =3D inode->i_sb; struct erofs_fscache_request *req; struct erofs_map_blocks map; struct erofs_map_dev mdev; struct iov_iter iter; + loff_t pos =3D primary->start + primary->submitted; size_t count; int ret; =20 - *unlock =3D true; - map.m_la =3D pos; ret =3D erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW); if (ret) @@ -220,17 +233,19 @@ static int erofs_fscache_data_read(struct address_spa= ce *mapping, } iov_iter_zero(PAGE_SIZE - size, &iter); erofs_put_metabuf(&buf); - return PAGE_SIZE; + primary->submitted +=3D PAGE_SIZE; + return 0; } =20 + count =3D primary->len - primary->submitted; if (!(map.m_flags & EROFS_MAP_MAPPED)) { - count =3D len; iov_iter_xarray(&iter, READ, &mapping->i_pages, pos, count); iov_iter_zero(count, &iter); - return count; + primary->submitted +=3D count; + return 0; } =20 - count =3D min_t(size_t, map.m_llen - (pos - map.m_la), len); + count =3D min_t(size_t, map.m_llen - (pos - map.m_la), count); DBG_BUGON(!count || count % PAGE_SIZE); =20 mdev =3D (struct erofs_map_dev) { @@ -241,68 +256,65 @@ static int erofs_fscache_data_read(struct address_spa= ce *mapping, if (ret) return ret; =20 - req =3D erofs_fscache_req_alloc(mapping, pos, count); + req =3D erofs_fscache_req_chain(primary, count); if (IS_ERR(req)) return PTR_ERR(req); =20 - *unlock =3D false; ret =3D erofs_fscache_read_folios_async(mdev.m_fscache->cookie, req, mdev.m_pa + (pos - map.m_la), count); - if (ret) - req->error =3D ret; - erofs_fscache_req_put(req); - return count; + primary->submitted +=3D count; + return ret; } =20 -static int erofs_fscache_read_folio(struct file *file, struct folio *folio) +static int erofs_fscache_data_read(struct erofs_fscache_request *req) { - bool unlock; int ret; =20 - DBG_BUGON(folio_size(folio) !=3D EROFS_BLKSIZ); + do { + ret =3D erofs_fscache_data_read_slice(req); + if (ret) + req->error =3D ret; + } while (!ret && req->submitted < req->len); =20 - ret =3D erofs_fscache_data_read(folio_mapping(folio), folio_pos(folio), - folio_size(folio), &unlock); - if (unlock) { - if (ret > 0) - folio_mark_uptodate(folio); + return ret; +} + +static int erofs_fscache_read_folio(struct file *file, struct folio *folio) +{ + struct erofs_fscache_request *req; + int ret; + + req =3D erofs_fscache_req_alloc(folio_mapping(folio), + folio_pos(folio), folio_size(folio)); + if (IS_ERR(req)) { folio_unlock(folio); + return PTR_ERR(req); } - return ret < 0 ? ret : 0; + + ret =3D erofs_fscache_data_read(req); + erofs_fscache_req_put(req); + return ret; } =20 static void erofs_fscache_readahead(struct readahead_control *rac) { - struct folio *folio; - size_t len, done =3D 0; - loff_t start, pos; - bool unlock; - int ret, size; + struct erofs_fscache_request *req; =20 if (!readahead_count(rac)) return; =20 - start =3D readahead_pos(rac); - len =3D readahead_length(rac); + req =3D erofs_fscache_req_alloc(rac->mapping, + readahead_pos(rac), readahead_length(rac)); + if (IS_ERR(req)) + return; =20 - do { - pos =3D start + done; - ret =3D erofs_fscache_data_read(rac->mapping, pos, - len - done, &unlock); - if (ret <=3D 0) - return; + /* The request completion will drop refs on the folios. */ + while (readahead_folio(rac)) + ; =20 - size =3D ret; - while (size) { - folio =3D readahead_folio(rac); - size -=3D folio_size(folio); - if (unlock) { - folio_mark_uptodate(folio); - folio_unlock(folio); - } - } - } while ((done +=3D ret) < len); + erofs_fscache_data_read(req); + erofs_fscache_req_put(req); } =20 static const struct address_space_operations erofs_fscache_meta_aops =3D { --=20 2.19.1.6.gb485710b From nobody Thu Sep 18 23:16:07 2025 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 09FB0C43217 for ; Thu, 1 Dec 2022 07:43:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229807AbiLAHnN (ORCPT ); Thu, 1 Dec 2022 02:43:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229551AbiLAHnD (ORCPT ); Thu, 1 Dec 2022 02:43:03 -0500 Received: from out30-1.freemail.mail.aliyun.com (out30-1.freemail.mail.aliyun.com [115.124.30.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E700718392 for ; Wed, 30 Nov 2022 23:43:01 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046051;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VW7ouC6_1669880578; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VW7ouC6_1669880578) by smtp.aliyun-inc.com; Thu, 01 Dec 2022 15:42:59 +0800 From: Jingbo Xu To: xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH v4 2/2] erofs: enable large folios for fscache mode Date: Thu, 1 Dec 2022 15:42:56 +0800 Message-Id: <20221201074256.16639-3-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20221201074256.16639-1-jefflexu@linux.alibaba.com> References: <20221201074256.16639-1-jefflexu@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" Enable large folios for fscache mode. Enable this feature for non-compressed format for now, until the compression part supports large folios later. One thing worth noting is that, the feature is not enabled for the meta data routine since meta inodes don't need large folios for now, nor do they support readahead yet. Also document this new feature. Signed-off-by: Jingbo Xu Reviewed-by: Jia Zhu --- Documentation/filesystems/erofs.rst | 2 ++ fs/erofs/inode.c | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Documentation/filesystems/erofs.rst b/Documentation/filesystem= s/erofs.rst index 82af67fdaf99..1c1f7404b338 100644 --- a/Documentation/filesystems/erofs.rst +++ b/Documentation/filesystems/erofs.rst @@ -72,6 +72,8 @@ Here are the main features of EROFS: =20 - Support merging tail-end data into a special inode as fragments. =20 + - Support large folios for uncompressed files. + - Support direct I/O on uncompressed files to avoid double caching for lo= op devices; =20 diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c index e457b8a59ee7..85932086d23f 100644 --- a/fs/erofs/inode.c +++ b/fs/erofs/inode.c @@ -295,8 +295,7 @@ static int erofs_fill_inode(struct inode *inode) goto out_unlock; } inode->i_mapping->a_ops =3D &erofs_raw_access_aops; - if (!erofs_is_fscache_mode(inode->i_sb)) - mapping_set_large_folios(inode->i_mapping); + mapping_set_large_folios(inode->i_mapping); #ifdef CONFIG_EROFS_FS_ONDEMAND if (erofs_is_fscache_mode(inode->i_sb)) inode->i_mapping->a_ops =3D &erofs_fscache_access_aops; --=20 2.19.1.6.gb485710b