From nobody Tue Nov 5 09:31:45 2024 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 C77D5C636D3 for ; Fri, 3 Feb 2023 03:01:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232273AbjBCDB4 (ORCPT ); Thu, 2 Feb 2023 22:01:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232152AbjBCDBt (ORCPT ); Thu, 2 Feb 2023 22:01:49 -0500 Received: from out30-112.freemail.mail.aliyun.com (out30-112.freemail.mail.aliyun.com [115.124.30.112]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AA1010A9D; Thu, 2 Feb 2023 19:01:47 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046056;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VampZ0n_1675393304; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VampZ0n_1675393304) by smtp.aliyun-inc.com; Fri, 03 Feb 2023 11:01:45 +0800 From: Jingbo Xu To: xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org Cc: huyue2@coolpad.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v3 1/9] erofs: support readahead in meta routine Date: Fri, 3 Feb 2023 11:01:35 +0800 Message-Id: <20230203030143.73105-2-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230203030143.73105-1-jefflexu@linux.alibaba.com> References: <20230203030143.73105-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" In prep for the following support for readahead for page cache sharing, add support for readahead in meta routine. Signed-off-by: Jingbo Xu --- fs/erofs/fscache.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 014e20962376..e2ebe8f7dbe9 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -193,6 +193,30 @@ static int erofs_fscache_meta_read_folio(struct file *= data, struct folio *folio) return ret; } =20 +static void erofs_fscache_meta_readahead(struct readahead_control *rac) +{ + int ret; + struct erofs_fscache *ctx =3D rac->mapping->host->i_private; + struct erofs_fscache_request *req; + + if (!readahead_count(rac)) + return; + + req =3D erofs_fscache_req_alloc(rac->mapping, + readahead_pos(rac), readahead_length(rac)); + if (IS_ERR(req)) + return; + + /* The request completion will drop refs on the folios. */ + while (readahead_folio(rac)) + ; + + ret =3D erofs_fscache_read_folios_async(ctx->cookie, req, req->start, req= ->len); + if (ret) + req->error =3D ret; + erofs_fscache_req_put(req); +} + static int erofs_fscache_data_read_slice(struct erofs_fscache_request *pri= mary) { struct address_space *mapping =3D primary->mapping; @@ -319,6 +343,7 @@ static void erofs_fscache_readahead(struct readahead_co= ntrol *rac) =20 static const struct address_space_operations erofs_fscache_meta_aops =3D { .read_folio =3D erofs_fscache_meta_read_folio, + .readahead =3D erofs_fscache_meta_readahead, }; =20 const struct address_space_operations erofs_fscache_access_aops =3D { --=20 2.19.1.6.gb485710b From nobody Tue Nov 5 09:31:45 2024 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 00ECDC61DA4 for ; Fri, 3 Feb 2023 03:01:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232234AbjBCDBv (ORCPT ); Thu, 2 Feb 2023 22:01:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229602AbjBCDBt (ORCPT ); Thu, 2 Feb 2023 22:01:49 -0500 Received: from out30-119.freemail.mail.aliyun.com (out30-119.freemail.mail.aliyun.com [115.124.30.119]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57EAF19F32; Thu, 2 Feb 2023 19:01:48 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R621e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046059;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VampZ1A_1675393305; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VampZ1A_1675393305) by smtp.aliyun-inc.com; Fri, 03 Feb 2023 11:01:46 +0800 From: Jingbo Xu To: xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org Cc: huyue2@coolpad.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v3 2/9] erofs: remove unused device mapping in the meta routine Date: Fri, 3 Feb 2023 11:01:36 +0800 Message-Id: <20230203030143.73105-3-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230203030143.73105-1-jefflexu@linux.alibaba.com> References: <20230203030143.73105-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" Currently there're two anonymous inodes (inode and anon_inode in struct erofs_fscache) may be used for each blob. The former is only for bootstrap and used as the address_space of page cache, while the latter is used for both bootstrap and data blobs when share domain mode enabled and behaves as a sentinel in the shared domain. In prep for the following support for page cache sharing, following patch will unify these two anonymous inodes. That is, the unified anonymous inode not only acts as the address_space of page cache, but also a sentinel in share domain mode. However the current meta routine can't work if above change applied. Current meta routine will make a device mapping, and superblock of the filesystem is required to do the device mapping. Currently the superblock is derived from the input meta folio, which is reasonable since the anonymous inode (used for the address_space of page cache) is always allocated from the filesystem's sb. However after anonymous inodes are unified, that is no longer always true. For example, in share domain mode, the unified anonymous inode will be allocated from pseudo mnt, and the superblock derived from the folio is actually a pseudo sb, which can't be used for the device mapping at all. As for the meta routine itself, currently metadata is always on bootstrap, which means device mapping is not needed so far. After removing the redundant device mapping logic, we can derive the required fscache_ctx from anonymous inode's i_private. Signed-off-by: Jingbo Xu --- fs/erofs/fscache.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index e2ebe8f7dbe9..14af4ebce54d 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -164,18 +164,8 @@ static int erofs_fscache_read_folios_async(struct fsca= che_cookie *cookie, static int erofs_fscache_meta_read_folio(struct file *data, struct folio *= folio) { int ret; - struct super_block *sb =3D folio_mapping(folio)->host->i_sb; + struct erofs_fscache *ctx =3D folio_mapping(folio)->host->i_private; struct erofs_fscache_request *req; - struct erofs_map_dev mdev =3D { - .m_deviceid =3D 0, - .m_pa =3D folio_pos(folio), - }; - - ret =3D erofs_map_dev(sb, &mdev); - if (ret) { - folio_unlock(folio); - return ret; - } =20 req =3D erofs_fscache_req_alloc(folio_mapping(folio), folio_pos(folio), folio_size(folio)); @@ -184,8 +174,8 @@ static int erofs_fscache_meta_read_folio(struct file *d= ata, struct folio *folio) return PTR_ERR(req); } =20 - ret =3D erofs_fscache_read_folios_async(mdev.m_fscache->cookie, - req, mdev.m_pa, folio_size(folio)); + ret =3D erofs_fscache_read_folios_async(ctx->cookie, req, + folio_pos(folio), folio_size(folio)); if (ret) req->error =3D ret; =20 @@ -494,6 +484,7 @@ struct erofs_fscache *erofs_fscache_acquire_cookie(stru= ct super_block *sb, inode->i_size =3D OFFSET_MAX; inode->i_mapping->a_ops =3D &erofs_fscache_meta_aops; mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS); + inode->i_private =3D ctx; =20 ctx->inode =3D inode; } --=20 2.19.1.6.gb485710b From nobody Tue Nov 5 09:31:45 2024 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 A9E49C636D3 for ; Fri, 3 Feb 2023 03:02:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232296AbjBCDB7 (ORCPT ); Thu, 2 Feb 2023 22:01:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232182AbjBCDBv (ORCPT ); Thu, 2 Feb 2023 22:01:51 -0500 Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C8642528A; Thu, 2 Feb 2023 19:01:49 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VamlnzE_1675393306; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VamlnzE_1675393306) by smtp.aliyun-inc.com; Fri, 03 Feb 2023 11:01:46 +0800 From: Jingbo Xu To: xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org Cc: huyue2@coolpad.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v3 3/9] erofs: unify anonymous inodes for blob Date: Fri, 3 Feb 2023 11:01:37 +0800 Message-Id: <20230203030143.73105-4-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230203030143.73105-1-jefflexu@linux.alibaba.com> References: <20230203030143.73105-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" Currently only bootstrap will allocate anonymous inode for the address_space of page cache. In prep for the following support for page cache sharing, as the first step, always allocate anonymous inode for this use for both bootstrap and data blobs. Since now anonymous inode is also allocated for data blobs, release these anonymous inodes when .put_super() is called, or we'll get "VFS: Busy inodes after unmount." warning. Similarly, the fscache contexts for data blobs are initialized prior to the root inode, thus .kill_sb() shall also contain the cleanup routine, so that these fscache contexts can be cleaned up when mount fails while root inode has not been initialized yet. Also remove the redundant set_nlink() when initializing anonymous inode, since i_nlink has already been initialized to 1 when the inode gets allocated. Until then there're two anonymous inodes (inode and anon_inode in struct erofs_fscache) may be used for each blob. The former is used as the address_space of page cache, while the latter is used as a sentinel in the shared domain. In prep for the following support for page cache sharing, unify these two anonymous inodes. Signed-off-by: Jingbo Xu --- fs/erofs/fscache.c | 101 ++++++++++++++++++++------------------------ fs/erofs/internal.h | 6 +-- fs/erofs/super.c | 2 + 3 files changed, 49 insertions(+), 60 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 14af4ebce54d..7f2e2d17e8e0 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -343,8 +343,6 @@ const struct address_space_operations erofs_fscache_acc= ess_aops =3D { =20 static void erofs_fscache_domain_put(struct erofs_domain *domain) { - if (!domain) - return; mutex_lock(&erofs_domain_list_lock); if (refcount_dec_and_test(&domain->ref)) { list_del(&domain->list); @@ -448,12 +446,12 @@ static int erofs_fscache_register_domain(struct super= _block *sb) =20 static struct erofs_fscache *erofs_fscache_acquire_cookie(struct super_block *sb, - char *name, - unsigned int flags) + struct super_block *isb, char *name) { struct fscache_volume *volume =3D EROFS_SB(sb)->volume; struct erofs_fscache *ctx; struct fscache_cookie *cookie; + struct inode *inode; int ret; =20 ctx =3D kzalloc(sizeof(*ctx), GFP_KERNEL); @@ -467,33 +465,27 @@ struct erofs_fscache *erofs_fscache_acquire_cookie(st= ruct super_block *sb, ret =3D -EINVAL; goto err; } - fscache_use_cookie(cookie, false); - ctx->cookie =3D cookie; - - if (flags & EROFS_REG_COOKIE_NEED_INODE) { - struct inode *const inode =3D new_inode(sb); - - if (!inode) { - erofs_err(sb, "failed to get anon inode for %s", name); - ret =3D -ENOMEM; - goto err_cookie; - } - - set_nlink(inode, 1); - inode->i_size =3D OFFSET_MAX; - inode->i_mapping->a_ops =3D &erofs_fscache_meta_aops; - mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS); - inode->i_private =3D ctx; =20 - ctx->inode =3D inode; + inode =3D new_inode(isb); + if (!inode) { + erofs_err(sb, "failed to get anon inode for %s", name); + ret =3D -ENOMEM; + goto err_cookie; } =20 + inode->i_size =3D OFFSET_MAX; + inode->i_mapping->a_ops =3D &erofs_fscache_meta_aops; + mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS); + inode->i_private =3D ctx; + + ctx->cookie =3D cookie; + ctx->inode =3D inode; return ctx; =20 err_cookie: - fscache_unuse_cookie(ctx->cookie, NULL, NULL); - fscache_relinquish_cookie(ctx->cookie, false); + fscache_unuse_cookie(cookie, NULL, NULL); + fscache_relinquish_cookie(cookie, false); err: kfree(ctx); return ERR_PTR(ret); @@ -510,38 +502,34 @@ static void erofs_fscache_relinquish_cookie(struct er= ofs_fscache *ctx) =20 static struct erofs_fscache *erofs_fscache_domain_init_cookie(struct super_block = *sb, - char *name, - unsigned int flags) + char *name) { - int err; - struct inode *inode; struct erofs_fscache *ctx; struct erofs_domain *domain =3D EROFS_SB(sb)->domain; =20 - ctx =3D erofs_fscache_acquire_cookie(sb, name, flags); + ctx =3D erofs_fscache_acquire_cookie(sb, erofs_pseudo_mnt->mnt_sb, name); if (IS_ERR(ctx)) return ctx; =20 ctx->name =3D kstrdup(name, GFP_KERNEL); if (!ctx->name) { - err =3D -ENOMEM; - goto out; + erofs_fscache_relinquish_cookie(ctx); + return ERR_PTR(-ENOMEM); } =20 - inode =3D new_inode(erofs_pseudo_mnt->mnt_sb); - if (!inode) { - err =3D -ENOMEM; - goto out; - } + /* + * In share domain scenarios, the unified anonymous inode is not only + * used as the address_space of shared page cache, but also a sentinel + * in pseudo mount. The initial refcount is used for the former and + * will be killed when the cookie finally gets relinquished. For the + * latter, the refcount is increased every time the cookie in the domain + * gets referred to. + */ + igrab(ctx->inode); =20 ctx->domain =3D domain; - ctx->anon_inode =3D inode; - inode->i_private =3D ctx; refcount_inc(&domain->ref); return ctx; -out: - erofs_fscache_relinquish_cookie(ctx); - return ERR_PTR(err); } =20 static @@ -572,7 +560,7 @@ struct erofs_fscache *erofs_domain_register_cookie(stru= ct super_block *sb, return ctx; } spin_unlock(&psb->s_inode_list_lock); - ctx =3D erofs_fscache_domain_init_cookie(sb, name, flags); + ctx =3D erofs_fscache_domain_init_cookie(sb, name); mutex_unlock(&erofs_domain_cookies_lock); return ctx; } @@ -583,7 +571,7 @@ struct erofs_fscache *erofs_fscache_register_cookie(str= uct super_block *sb, { if (EROFS_SB(sb)->domain_id) return erofs_domain_register_cookie(sb, name, flags); - return erofs_fscache_acquire_cookie(sb, name, flags); + return erofs_fscache_acquire_cookie(sb, sb, name); } =20 void erofs_fscache_unregister_cookie(struct erofs_fscache *ctx) @@ -593,18 +581,20 @@ void erofs_fscache_unregister_cookie(struct erofs_fsc= ache *ctx) =20 if (!ctx) return; - domain =3D ctx->domain; - if (domain) { - mutex_lock(&erofs_domain_cookies_lock); - drop =3D atomic_read(&ctx->anon_inode->i_count) =3D=3D 1; - iput(ctx->anon_inode); - mutex_unlock(&erofs_domain_cookies_lock); - if (!drop) - return; - } =20 - erofs_fscache_relinquish_cookie(ctx); - erofs_fscache_domain_put(domain); + if (!ctx->domain) + return erofs_fscache_relinquish_cookie(ctx); + + domain =3D ctx->domain; + mutex_lock(&erofs_domain_cookies_lock); + /* drop the ref for the sentinel in pseudo mount */ + iput(ctx->inode); + drop =3D atomic_read(&ctx->inode->i_count) =3D=3D 1; + if (drop) + erofs_fscache_relinquish_cookie(ctx); + mutex_unlock(&erofs_domain_cookies_lock); + if (drop) + erofs_fscache_domain_put(domain); } =20 int erofs_fscache_register_fs(struct super_block *sb) @@ -612,7 +602,7 @@ int erofs_fscache_register_fs(struct super_block *sb) int ret; struct erofs_sb_info *sbi =3D EROFS_SB(sb); struct erofs_fscache *fscache; - unsigned int flags; + unsigned int flags =3D 0; =20 if (sbi->domain_id) ret =3D erofs_fscache_register_domain(sb); @@ -631,7 +621,6 @@ int erofs_fscache_register_fs(struct super_block *sb) * * Acquired domain/volume will be relinquished in kill_sb() on error. */ - flags =3D EROFS_REG_COOKIE_NEED_INODE; if (sbi->domain_id) flags |=3D EROFS_REG_COOKIE_NEED_NOEXIST; fscache =3D erofs_fscache_register_cookie(sb, sbi->fsid, flags); diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index bb8501c0ff5b..b3d04bc2d279 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -108,8 +108,7 @@ struct erofs_domain { =20 struct erofs_fscache { struct fscache_cookie *cookie; - struct inode *inode; - struct inode *anon_inode; + struct inode *inode; /* anonymous indoe for the blob */ struct erofs_domain *domain; char *name; }; @@ -604,8 +603,7 @@ static inline int z_erofs_load_lzma_config(struct super= _block *sb, #endif /* !CONFIG_EROFS_FS_ZIP */ =20 /* flags for erofs_fscache_register_cookie() */ -#define EROFS_REG_COOKIE_NEED_INODE 1 -#define EROFS_REG_COOKIE_NEED_NOEXIST 2 +#define EROFS_REG_COOKIE_NEED_NOEXIST 1 =20 /* fscache.c */ #ifdef CONFIG_EROFS_FS_ONDEMAND diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 626a615dafc2..835b69c9511b 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -969,6 +969,8 @@ static void erofs_put_super(struct super_block *sb) iput(sbi->packed_inode); sbi->packed_inode =3D NULL; #endif + erofs_free_dev_context(sbi->devs); + sbi->devs =3D NULL; erofs_fscache_unregister_fs(sb); } =20 --=20 2.19.1.6.gb485710b From nobody Tue Nov 5 09:31:45 2024 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 85E6EC636D4 for ; Fri, 3 Feb 2023 03:02:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232239AbjBCDCO (ORCPT ); Thu, 2 Feb 2023 22:02:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229602AbjBCDBv (ORCPT ); Thu, 2 Feb 2023 22:01:51 -0500 Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6064610A9D; Thu, 2 Feb 2023 19:01:50 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R951e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046059;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VamlQX8_1675393307; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VamlQX8_1675393307) by smtp.aliyun-inc.com; Fri, 03 Feb 2023 11:01:47 +0800 From: Jingbo Xu To: xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org Cc: huyue2@coolpad.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v3 4/9] erofs: allocate anonymous file of blob for page cache sharing Date: Fri, 3 Feb 2023 11:01:38 +0800 Message-Id: <20230203030143.73105-5-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230203030143.73105-1-jefflexu@linux.alibaba.com> References: <20230203030143.73105-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" In prep for the following support for page cache sharing based mmap, allocate an anonymous file of corresponding blob, so that we can link associated vma to the blob later. Signed-off-by: Jingbo Xu --- fs/erofs/fscache.c | 75 +++++++++++++++++++++++++++++++++++++++++++++ fs/erofs/internal.h | 1 + 2 files changed, 76 insertions(+) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 7f2e2d17e8e0..bed02b21978a 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -4,6 +4,8 @@ * Copyright (C) 2022, Bytedance Inc. All rights reserved. */ #include +#include +#include #include "internal.h" =20 static DEFINE_MUTEX(erofs_domain_list_lock); @@ -22,6 +24,11 @@ struct erofs_fscache_request { refcount_t ref; }; =20 +struct erofs_fscache_finfo { + erofs_off_t pa; + pgoff_t max_idx; +}; + static struct erofs_fscache_request *erofs_fscache_req_alloc(struct addres= s_space *mapping, loff_t start, size_t len) { @@ -341,6 +348,74 @@ const struct address_space_operations erofs_fscache_ac= cess_aops =3D { .readahead =3D erofs_fscache_readahead, }; =20 +static int erofs_fscache_share_meta_release(struct inode *inode, struct fi= le *filp) +{ + kfree(filp->private_data); + filp->private_data =3D NULL; + return 0; +} + +static const struct file_operations erofs_fscache_share_meta_fops =3D { + .release =3D erofs_fscache_share_meta_release, +}; + +static int erofs_fscache_share_file_release(struct inode *inode, struct fi= le *filp) +{ + fput(filp->private_data); + filp->private_data =3D NULL; + return 0; +} + +static int erofs_fscache_share_file_open(struct inode *inode, struct file = *filp) +{ + /* since page cache sharing is enabled only when i_size <=3D chunk_size */ + struct erofs_map_blocks map =3D {}; /* .m_la =3D 0 */ + struct erofs_map_dev mdev; + struct erofs_fscache_finfo *finfo; + struct inode *realinode; + struct file *realfile; + int ret; + + ret =3D erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW); + if (ret) + return ret; + + mdev =3D (struct erofs_map_dev) { + .m_deviceid =3D map.m_deviceid, + .m_pa =3D map.m_pa, + }; + ret =3D erofs_map_dev(inode->i_sb, &mdev); + if (ret) + return ret; + + finfo =3D kzalloc(sizeof(struct erofs_fscache_finfo), GFP_KERNEL); + if (!finfo) + return -ENOMEM; + finfo->pa =3D mdev.m_pa; + finfo->max_idx =3D DIV_ROUND_UP(mdev.m_pa + inode->i_size, PAGE_SIZE); + + realinode =3D mdev.m_fscache->inode; + ihold(realinode); + realfile =3D alloc_file_pseudo(realinode, filp->f_path.mnt, "[erofs]", + O_RDONLY, &erofs_fscache_share_meta_fops); + if (IS_ERR(realfile)) { + iput(realinode); + kfree(finfo); + return PTR_ERR(realfile); + } + + file_ra_state_init(&realfile->f_ra, filp->f_mapping); + realfile->private_data =3D finfo; + filp->private_data =3D realfile; + return 0; +} + +const struct file_operations erofs_fscache_share_file_fops =3D { + .llseek =3D generic_file_llseek, + .open =3D erofs_fscache_share_file_open, + .release =3D erofs_fscache_share_file_release, +}; + static void erofs_fscache_domain_put(struct erofs_domain *domain) { mutex_lock(&erofs_domain_list_lock); diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index b3d04bc2d279..7c6a7a2d9acf 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -616,6 +616,7 @@ struct erofs_fscache *erofs_fscache_register_cookie(str= uct super_block *sb, void erofs_fscache_unregister_cookie(struct erofs_fscache *fscache); =20 extern const struct address_space_operations erofs_fscache_access_aops; +extern const struct file_operations erofs_fscache_share_file_fops; #else static inline int erofs_fscache_register_fs(struct super_block *sb) { --=20 2.19.1.6.gb485710b From nobody Tue Nov 5 09:31:45 2024 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 6C513C61DA4 for ; Fri, 3 Feb 2023 03:02:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232358AbjBCDCV (ORCPT ); Thu, 2 Feb 2023 22:02:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232243AbjBCDBw (ORCPT ); Thu, 2 Feb 2023 22:01:52 -0500 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 427B38694; Thu, 2 Feb 2023 19:01:51 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R281e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046056;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VamyBZB_1675393308; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VamyBZB_1675393308) by smtp.aliyun-inc.com; Fri, 03 Feb 2023 11:01:48 +0800 From: Jingbo Xu To: xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org Cc: huyue2@coolpad.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v3 5/9] erofs: set accurate anony inode size for page cache sharing Date: Fri, 3 Feb 2023 11:01:39 +0800 Message-Id: <20230203030143.73105-6-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230203030143.73105-1-jefflexu@linux.alibaba.com> References: <20230203030143.73105-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" In prep for the following support for readahead for page cache sharing, we need accurate inode size of the anonymous inode, or the readahead algorithm may exceed EOF of blobs if the inode size is OFFSET_MAX magic. Signed-off-by: Jingbo Xu --- fs/erofs/fscache.c | 9 +++++++++ fs/erofs/internal.h | 1 + 2 files changed, 10 insertions(+) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index bed02b21978a..4fe7f23b022e 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -554,6 +554,15 @@ struct erofs_fscache *erofs_fscache_acquire_cookie(str= uct super_block *sb, mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS); inode->i_private =3D ctx; =20 + if (test_opt(&EROFS_SB(sb)->opt, SHARE_CACHE)) { + struct netfs_cache_resources cres; + ret =3D fscache_begin_read_operation(&cres, cookie); + if (ret) + goto err_cookie; + fscache_end_operation(&cres); + inode->i_size =3D cookie->object_size; + } + ctx->cookie =3D cookie; ctx->inode =3D inode; return ctx; diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 7c6a7a2d9acf..60d14561fb46 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -181,6 +181,7 @@ struct erofs_sb_info { #define EROFS_MOUNT_POSIX_ACL 0x00000020 #define EROFS_MOUNT_DAX_ALWAYS 0x00000040 #define EROFS_MOUNT_DAX_NEVER 0x00000080 +#define EROFS_MOUNT_SHARE_CACHE 0x00000100 =20 #define clear_opt(opt, option) ((opt)->mount_opt &=3D ~EROFS_MOUNT_##optio= n) #define set_opt(opt, option) ((opt)->mount_opt |=3D EROFS_MOUNT_##option) --=20 2.19.1.6.gb485710b From nobody Tue Nov 5 09:31:45 2024 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 33815C636D4 for ; Fri, 3 Feb 2023 03:02:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232369AbjBCDCW (ORCPT ); Thu, 2 Feb 2023 22:02:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232253AbjBCDBw (ORCPT ); Thu, 2 Feb 2023 22:01:52 -0500 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 CEE8819F32; Thu, 2 Feb 2023 19:01:51 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R441e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VamyBZQ_1675393309; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VamyBZQ_1675393309) by smtp.aliyun-inc.com; Fri, 03 Feb 2023 11:01:49 +0800 From: Jingbo Xu To: xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org Cc: huyue2@coolpad.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v3 6/9] erofs: implement .read_iter for page cache sharing Date: Fri, 3 Feb 2023 11:01:40 +0800 Message-Id: <20230203030143.73105-7-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230203030143.73105-1-jefflexu@linux.alibaba.com> References: <20230203030143.73105-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 page cache sharing enabled, page caches are managed in the address space of blobs rather than erofs inodes. All erofs inodes sharing one chunk will refer to and share the page cache in the blob's address space. Signed-off-by: Jingbo Xu --- fs/erofs/fscache.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 4fe7f23b022e..bdeb048b78b5 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -410,8 +410,31 @@ static int erofs_fscache_share_file_open(struct inode = *inode, struct file *filp) return 0; } =20 +static ssize_t erofs_fscache_share_file_read_iter(struct kiocb *iocb, + struct iov_iter *iter) +{ + struct file *realfile =3D iocb->ki_filp->private_data; + struct erofs_fscache_finfo *finfo =3D realfile->private_data; + ssize_t res; + + if (!iov_iter_count(iter)) + return 0; + + if (!is_sync_kiocb(iocb)) + return filemap_read(iocb, iter, 0); + + iov_iter_truncate(iter, file_inode(iocb->ki_filp)->i_size - iocb->ki_pos); + iocb->ki_filp =3D realfile; + iocb->ki_pos +=3D finfo->pa; + + res =3D filemap_read(iocb, iter, 0); + iocb->ki_pos -=3D finfo->pa; + return res; +} + const struct file_operations erofs_fscache_share_file_fops =3D { .llseek =3D generic_file_llseek, + .read_iter =3D erofs_fscache_share_file_read_iter, .open =3D erofs_fscache_share_file_open, .release =3D erofs_fscache_share_file_release, }; --=20 2.19.1.6.gb485710b From nobody Tue Nov 5 09:31:45 2024 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 A53BBC636D3 for ; Fri, 3 Feb 2023 03:02:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232424AbjBCDCc (ORCPT ); Thu, 2 Feb 2023 22:02:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232182AbjBCDCL (ORCPT ); Thu, 2 Feb 2023 22:02:11 -0500 Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C78083929E; Thu, 2 Feb 2023 19:01:52 -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=ay29a033018045192;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0Vamlo-T_1675393309; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0Vamlo-T_1675393309) by smtp.aliyun-inc.com; Fri, 03 Feb 2023 11:01:50 +0800 From: Jingbo Xu To: xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org Cc: huyue2@coolpad.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v3 7/9] erofs: implement .mmap for page cache sharing Date: Fri, 3 Feb 2023 11:01:41 +0800 Message-Id: <20230203030143.73105-8-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230203030143.73105-1-jefflexu@linux.alibaba.com> References: <20230203030143.73105-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" In mmap(2), replace vma->vm_file with the anonymous file associated with the blob, so that the vma will be linked to the address_space of the blob. One thing worth noting is that, we return error early in mmap(2) if users attempt to map beyond the file size. Normally filesystems won't restrict this in mmap(2). The checking is done in the fault handler, and SIGBUS will be signaled to users if they actually attempt to access the area beyond the end of the file. However since vma->vm_file has been changed to the anonymous file in mmap(2), we can no way derive the file size of the original file. As file size is immutable in ro filesystem, let's fail early in mmap(2) in this case. Signed-off-by: Jingbo Xu --- fs/erofs/fscache.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index bdeb048b78b5..af6ba52bbe8b 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -432,9 +432,36 @@ static ssize_t erofs_fscache_share_file_read_iter(stru= ct kiocb *iocb, return res; } =20 +vm_fault_t erofs_fscache_share_fault(struct vm_fault *vmf) +{ + struct erofs_fscache_finfo *finfo =3D vmf->vma->vm_file->private_data; + + if (unlikely(vmf->pgoff >=3D finfo->max_idx)) + return VM_FAULT_SIGBUS; + return filemap_fault(vmf); +} + +static const struct vm_operations_struct erofs_fscache_share_file_vm_ops = =3D { + .fault =3D erofs_fscache_share_fault, +}; + +static int erofs_fscache_share_file_mmap(struct file *file, + struct vm_area_struct *vma) +{ + struct file *realfile =3D file->private_data; + struct erofs_fscache_finfo *finfo =3D realfile->private_data; + + vma_set_file(vma, realfile); + vma->vm_pgoff =3D (finfo->pa >> PAGE_SHIFT) + vma->vm_pgoff; + vma->vm_ops =3D &erofs_fscache_share_file_vm_ops; + file_accessed(file); + return 0; +} + const struct file_operations erofs_fscache_share_file_fops =3D { .llseek =3D generic_file_llseek, .read_iter =3D erofs_fscache_share_file_read_iter, + .mmap =3D erofs_fscache_share_file_mmap, .open =3D erofs_fscache_share_file_open, .release =3D erofs_fscache_share_file_release, }; --=20 2.19.1.6.gb485710b From nobody Tue Nov 5 09:31:45 2024 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 BD681C61DA4 for ; Fri, 3 Feb 2023 03:02:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232413AbjBCDC2 (ORCPT ); Thu, 2 Feb 2023 22:02:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232297AbjBCDCL (ORCPT ); Thu, 2 Feb 2023 22:02:11 -0500 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D75DC4B1AA; Thu, 2 Feb 2023 19:01:53 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R101e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046050;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VamroM2_1675393310; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VamroM2_1675393310) by smtp.aliyun-inc.com; Fri, 03 Feb 2023 11:01:51 +0800 From: Jingbo Xu To: xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org Cc: huyue2@coolpad.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v3 8/9] erofs: add helper checking if page cache sharing shall be enabled Date: Fri, 3 Feb 2023 11:01:42 +0800 Message-Id: <20230203030143.73105-9-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230203030143.73105-1-jefflexu@linux.alibaba.com> References: <20230203030143.73105-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" Erofs supports chunk deduplication to reduce disk usage. Furthermore we can make inodes share page cache of these deduplicated chunks to reduce the memory usage. This shall be much usable in container scenarios as deduplication is requisite for container image. This can be achieved by managing page cache of deduplicated chunks in blob's address space. In this way, all inodes sharing the deduplicated chunk will refer to and share the page cache in the blob's address space. So far there are some restrictions for enabling this feature. The page cache sharing feature also supports .mmap(). The reverse mapping requires that one vma can not be shared among inodes and can be linked to only one inode. As the vma will be finally linked to the blob's address space when page cache sharing enabled, the restriction of the reverse mapping actually requires that the mapped file area can not be mapped to multiple blobs. Thus page cache sharing can only be enabled for those files mapped to one blob. The chunk based data layout guarantees that a chunk will not cross the device (blob) boundary. Thus in chunk based data layout, those files smaller than the chunk size shall be guaranteed to be mapped to one blob. As chunk size is tunable at a per-file basis, this restriction can be relaxed at image building phase. As long as we ensure that the file can not be deduplicated, the file's chunk size can be set to a reasonable value larger than the file size, so that the page cache sharing feature can be enabled on this file later. The second restriction is that EROFS_BLKSIZ mus be multiples of PAGE_SIZE to avoid data leakage. Otherwise unrelated data may be exposed at the end of the last page, since file's data is arranged in unit of EROFS_BLKSIZ in the image. Considering all these restrictions, add a helper checking if page cache sharing shall be enabled for specific file. Signed-off-by: Jingbo Xu --- fs/erofs/internal.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 60d14561fb46..6019b076c625 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -369,6 +369,29 @@ static inline unsigned int erofs_inode_datalayout(unsi= gned int value) EROFS_I_DATALAYOUT_BITS); } =20 +static inline bool erofs_can_share_page(struct inode *inode) +{ + struct erofs_inode *vi =3D EROFS_I(inode); + struct erofs_sb_info *sbi =3D EROFS_SB(inode->i_sb); + + /* enable page cache sharing only in share domain mode */ + if (!erofs_is_fscache_mode(inode->i_sb) || !sbi->domain_id) + return false; + + if (vi->datalayout !=3D EROFS_INODE_CHUNK_BASED) + return false; + + /* avoid crossing multi devicces/blobs */ + if (inode->i_size > 1UL << vi->chunkbits) + return false; + + /* avoid data leakage in mmap routine */ + if (EROFS_BLKSIZ % PAGE_SIZE) + return false; + + return true; +} + /* * Different from grab_cache_page_nowait(), reclaiming is never triggered * when allocating new pages. --=20 2.19.1.6.gb485710b From nobody Tue Nov 5 09:31:45 2024 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 8F169C636D3 for ; Fri, 3 Feb 2023 03:02:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232329AbjBCDCf (ORCPT ); Thu, 2 Feb 2023 22:02:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232301AbjBCDCL (ORCPT ); Thu, 2 Feb 2023 22:02:11 -0500 Received: from out30-101.freemail.mail.aliyun.com (out30-101.freemail.mail.aliyun.com [115.124.30.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C5213A879; Thu, 2 Feb 2023 19:01:54 -0800 (PST) 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=ay29a033018045170;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VamyBaS_1675393311; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VamyBaS_1675393311) by smtp.aliyun-inc.com; Fri, 03 Feb 2023 11:01:52 +0800 From: Jingbo Xu To: xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org Cc: huyue2@coolpad.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v3 9/9] erofs: introduce 'sharecache' mount option Date: Fri, 3 Feb 2023 11:01:43 +0800 Message-Id: <20230203030143.73105-10-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230203030143.73105-1-jefflexu@linux.alibaba.com> References: <20230203030143.73105-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" Introduce 'sharecache' mount option to enable page cache sharing in fscache mode. Signed-off-by: Jingbo Xu --- Documentation/filesystems/erofs.rst | 2 ++ fs/erofs/inode.c | 4 ++++ fs/erofs/internal.h | 3 +++ fs/erofs/super.c | 13 +++++++++++++ 4 files changed, 22 insertions(+) diff --git a/Documentation/filesystems/erofs.rst b/Documentation/filesystem= s/erofs.rst index a43aacf1494e..1478c4d168e2 100644 --- a/Documentation/filesystems/erofs.rst +++ b/Documentation/filesystems/erofs.rst @@ -122,6 +122,8 @@ device=3D%s Specify a path to an extra dev= ice to be used together. fsid=3D%s Specify a filesystem image ID for Fscache back-en= d. domain_id=3D%s Specify a domain ID in fscache mode so that diffe= rent images with the same blobs under a given domain ID can sha= re storage. +(no)sharecache Enable page cache sharing among different images in= the + same domain. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D =20 Sysfs Entries diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c index d3b8736fa124..31d3ab8443d1 100644 --- a/fs/erofs/inode.c +++ b/fs/erofs/inode.c @@ -262,6 +262,10 @@ static int erofs_fill_inode(struct inode *inode) inode->i_op =3D &erofs_generic_iops; if (erofs_inode_is_data_compressed(vi->datalayout)) inode->i_fop =3D &generic_ro_fops; +#ifdef CONFIG_EROFS_FS_ONDEMAND + else if (erofs_can_share_page(inode)) + inode->i_fop =3D &erofs_fscache_share_file_fops; +#endif else inode->i_fop =3D &erofs_file_fops; break; diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 6019b076c625..c3ac6d613eb1 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -374,6 +374,9 @@ static inline bool erofs_can_share_page(struct inode *i= node) struct erofs_inode *vi =3D EROFS_I(inode); struct erofs_sb_info *sbi =3D EROFS_SB(inode->i_sb); =20 + if (!test_opt(&sbi->opt, SHARE_CACHE)) + return false; + /* enable page cache sharing only in share domain mode */ if (!erofs_is_fscache_mode(inode->i_sb) || !sbi->domain_id) return false; diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 835b69c9511b..d05346d34ed8 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -456,6 +456,7 @@ enum { Opt_device, Opt_fsid, Opt_domain_id, + Opt_sharecache, Opt_err }; =20 @@ -482,6 +483,7 @@ static const struct fs_parameter_spec erofs_fs_paramete= rs[] =3D { fsparam_string("device", Opt_device), fsparam_string("fsid", Opt_fsid), fsparam_string("domain_id", Opt_domain_id), + fsparam_flag_no("sharecache", Opt_sharecache), {} }; =20 @@ -590,9 +592,16 @@ static int erofs_fc_parse_param(struct fs_context *fc, if (!ctx->domain_id) return -ENOMEM; break; + case Opt_sharecache: + if (result.boolean) + set_opt(&ctx->opt, SHARE_CACHE); + else + clear_opt(&ctx->opt, SHARE_CACHE); + break; #else case Opt_fsid: case Opt_domain_id: + case Opt_sharecache: errorfc(fc, "%s option not supported", erofs_fs_parameters[opt].name); break; #endif @@ -1108,6 +1117,10 @@ static int erofs_show_options(struct seq_file *seq, = struct dentry *root) seq_printf(seq, ",fsid=3D%s", sbi->fsid); if (sbi->domain_id) seq_printf(seq, ",domain_id=3D%s", sbi->domain_id); + if (test_opt(opt, SHARE_CACHE)) + seq_puts(seq, ",sharecache"); + else + seq_puts(seq, ",nosharecache"); #endif return 0; } --=20 2.19.1.6.gb485710b