From patchwork Wed Jan 11 08:31:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 41819 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3200378wrt; Wed, 11 Jan 2023 00:40:12 -0800 (PST) X-Google-Smtp-Source: AMrXdXvbgCAgrvhE6Yytek4YAOnGFs3RkEjFH/5dgRlUNb02XIj1/2cMufZIMYjd4coW6p59ii5d X-Received: by 2002:a17:906:27c5:b0:7c0:c220:a33d with SMTP id k5-20020a17090627c500b007c0c220a33dmr70931233ejc.9.1673426411992; Wed, 11 Jan 2023 00:40:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673426411; cv=none; d=google.com; s=arc-20160816; b=Dz2DStS0sYPXChmi/wypOAj5TbE68e2EPNH9WogxepjabGajr6WHbJGcep+aRQq1rs TDP6H43LCR0oIOPylF/BcZeE8SkBOiSL6vB7akZlNzBpvOCkG/AtZnNmYTwPFzzSJEc0 rd7muO3mTe2Wa45wi0fRxH6B+VL7pGf6MHHdukHBJNP6EzZYoCS3o+klH2RpdsO4uxAE QXvIHVOl+Y4NfujHGJdsDzqkFNXVewdgR9+sFM++PJfsJS9Yb9tFzl/1kfcwLl9AldBY +aD/gvadco7OI4vG55n9n/ghxYtbFLPZHGbNUeFotPJemP+dvB9fkVDYff4VkEMka0rR MAYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=EhdxxlpYwtjX8jwA7cAhNWmBzIgaulcEQjTbzizakHA=; b=HhNEWOjBSLMEXhpWBOFfUE7Tq9kbrxAcE1RK53hhkDXmfHt4MhKKNtKCQPx5W34nSe Jxgqbuu5r0g+Ep1EIKVt4nHGe4DBEnd6zDKEFCF1Zjc9it3hwAdEr01n6nfPSaCzdhyT goTANX5epwDeq8GJ4Wk0wsZ3RFTEM2/Gz5GfREgLLLIZpwFAvTxiHvGBhgQJn365YvMG Wd3LSvlvP7Vabqxy0ktoBcJlI9R9ZQ9rFB+cOl9p8XnzoVgaFhm186sotRlzWs/ZHY8Z TvzLkJBec7jffFM2tHlCdWEsdIJmHGokz+bTMk0lM6SwvW+OQ+h4LqPocP4kjDc5m7t/ 4WCw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id di15-20020a170906730f00b007ae4ed48290si15373575ejc.279.2023.01.11.00.39.47; Wed, 11 Jan 2023 00:40:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235666AbjAKIcQ (ORCPT + 99 others); Wed, 11 Jan 2023 03:32:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235731AbjAKIcJ (ORCPT ); Wed, 11 Jan 2023 03:32:09 -0500 Received: from out30-6.freemail.mail.aliyun.com (out30-6.freemail.mail.aliyun.com [115.124.30.6]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 028EFA188; Wed, 11 Jan 2023 00:32:05 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R231e4;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_---0VZMeLov_1673425919; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VZMeLov_1673425919) by smtp.aliyun-inc.com; Wed, 11 Jan 2023 16:32:00 +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 v2 1/7] erofs: remove unused device mapping in the meta routine Date: Wed, 11 Jan 2023 16:31:52 +0800 Message-Id: <20230111083158.23462-2-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230111083158.23462-1-jefflexu@linux.alibaba.com> References: <20230111083158.23462-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754714773213436613?= X-GMAIL-MSGID: =?utf-8?q?1754714773213436613?= 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 014e20962376..03de4dc99302 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -164,18 +164,8 @@ static int erofs_fscache_read_folios_async(struct fscache_cookie *cookie, static int erofs_fscache_meta_read_folio(struct file *data, struct folio *folio) { int ret; - struct super_block *sb = folio_mapping(folio)->host->i_sb; + struct erofs_fscache *ctx = folio_mapping(folio)->host->i_private; struct erofs_fscache_request *req; - struct erofs_map_dev mdev = { - .m_deviceid = 0, - .m_pa = folio_pos(folio), - }; - - ret = erofs_map_dev(sb, &mdev); - if (ret) { - folio_unlock(folio); - return ret; - } req = 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 *data, struct folio *folio) return PTR_ERR(req); } - ret = erofs_fscache_read_folios_async(mdev.m_fscache->cookie, - req, mdev.m_pa, folio_size(folio)); + ret = erofs_fscache_read_folios_async(ctx->cookie, req, + folio_pos(folio), folio_size(folio)); if (ret) req->error = ret; @@ -469,6 +459,7 @@ struct erofs_fscache *erofs_fscache_acquire_cookie(struct super_block *sb, inode->i_size = OFFSET_MAX; inode->i_mapping->a_ops = &erofs_fscache_meta_aops; mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS); + inode->i_private = ctx; ctx->inode = inode; } From patchwork Wed Jan 11 08:31:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 41822 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3201101wrt; Wed, 11 Jan 2023 00:42:47 -0800 (PST) X-Google-Smtp-Source: AMrXdXsAZe7S33SPn0ILjh8AtMU8B/euCVquMAlscRstYDu8QLncwcEsZM7kX/syzq22TyDode79 X-Received: by 2002:a17:90a:3c8c:b0:226:8206:91d9 with SMTP id g12-20020a17090a3c8c00b00226820691d9mr33631314pjc.20.1673426566704; Wed, 11 Jan 2023 00:42:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673426566; cv=none; d=google.com; s=arc-20160816; b=P0PHvblh/Xa5HE6jP7G9YxiaWFnHqcOJxHXHP6IuqwtoZQ20JfCRsSj4WpKaylqwKP KnWthd3HcQICU9v82uaNb+eZ+9IkyQsObbA509DNHOJyA/HtcGFAHpdKvqlQduOIayWu fGODhYnp3YwB14gfdBAZd0ybuVK2QQ2f/4gkVDNsxkfGHx+dI2KCIGg7pdkWyA4GLMXf EnpxUJuAiRqzXoDyZ04b4oz6vT6tQrHjux/HtLtS0hzckEu9EKi216fpneyZPu+QMj0H /0JPamFEGrEgbhq99dROfMHIx1jRyVmG5U79/ggkG9s4oYLgdyd1dclOa9m0RVgxAbCG b0Ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=CUDw9KSCSEvpL7Y3TLE22zlsYJ8SQAJPo3lKmOZ0LQE=; b=FFYANiFVf1tMfVWGz2VUSdqlrP4xu4D3z07tUBzkgpwtOGsj0juyfixNCLdlRofsxU Fj7V9rBxTf9j3ZNZI9A5q5iA+6v2xMilYAWEM9vc3I7Vtft+AsPF8nW6CgJ7MNS/RBnN 6k3y659t0g3aR+mWBrpi2yI4EvlkEH5EH+KUDIjQiCjinqsBxd5d8AEVZoAZQJvAvQam NxS972Bp2EpWeKd4JuNQgbW8YmCHEBPZKodcxkJB439Ua/imHiZyYQymahltY2ObH86f VLyabJvWVV0451KF/ynQjgmJjqbyAnbJE/q9qCBF6FujYPhXHoSUxrifWbTjpRP6CG/H Qr8w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w8-20020a63f508000000b0046fcbcb1015si14944724pgh.331.2023.01.11.00.42.34; Wed, 11 Jan 2023 00:42:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232010AbjAKIcO (ORCPT + 99 others); Wed, 11 Jan 2023 03:32:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235829AbjAKIcH (ORCPT ); Wed, 11 Jan 2023 03:32:07 -0500 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 8507AC77E; Wed, 11 Jan 2023 00:32:04 -0800 (PST) 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=ay29a033018046049;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VZMeLpU_1673425920; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VZMeLpU_1673425920) by smtp.aliyun-inc.com; Wed, 11 Jan 2023 16:32:01 +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 v2 2/7] erofs: unify anonymous inodes for blob Date: Wed, 11 Jan 2023 16:31:53 +0800 Message-Id: <20230111083158.23462-3-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230111083158.23462-1-jefflexu@linux.alibaba.com> References: <20230111083158.23462-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754714935924995958?= X-GMAIL-MSGID: =?utf-8?q?1754714935924995958?= 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 | 103 ++++++++++++++++++++------------------------ fs/erofs/internal.h | 6 +-- fs/erofs/super.c | 2 + 3 files changed, 51 insertions(+), 60 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 03de4dc99302..81f96c910277 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -318,8 +318,6 @@ const struct address_space_operations erofs_fscache_access_aops = { 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); @@ -423,12 +421,13 @@ static int erofs_fscache_register_domain(struct super_block *sb) static struct erofs_fscache *erofs_fscache_acquire_cookie(struct super_block *sb, - char *name, - unsigned int flags) + char *name) { struct fscache_volume *volume = EROFS_SB(sb)->volume; struct erofs_fscache *ctx; struct fscache_cookie *cookie; + struct super_block *psb; + struct inode *inode; int ret; ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); @@ -442,33 +441,28 @@ struct erofs_fscache *erofs_fscache_acquire_cookie(struct super_block *sb, ret = -EINVAL; goto err; } - fscache_use_cookie(cookie, false); - ctx->cookie = cookie; - - if (flags & EROFS_REG_COOKIE_NEED_INODE) { - struct inode *const inode = new_inode(sb); - - if (!inode) { - erofs_err(sb, "failed to get anon inode for %s", name); - ret = -ENOMEM; - goto err_cookie; - } - - set_nlink(inode, 1); - inode->i_size = OFFSET_MAX; - inode->i_mapping->a_ops = &erofs_fscache_meta_aops; - mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS); - inode->i_private = ctx; - ctx->inode = inode; + psb = EROFS_SB(sb)->domain_id ? erofs_pseudo_mnt->mnt_sb : sb; + inode = new_inode(psb); + if (!inode) { + erofs_err(sb, "failed to get anon inode for %s", name); + ret = -ENOMEM; + goto err_cookie; } + inode->i_size = OFFSET_MAX; + inode->i_mapping->a_ops = &erofs_fscache_meta_aops; + mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS); + inode->i_private = ctx; + + ctx->cookie = cookie; + ctx->inode = inode; return ctx; 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); @@ -485,38 +479,34 @@ static void erofs_fscache_relinquish_cookie(struct erofs_fscache *ctx) 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 = EROFS_SB(sb)->domain; - ctx = erofs_fscache_acquire_cookie(sb, name, flags); + ctx = erofs_fscache_acquire_cookie(sb, name); if (IS_ERR(ctx)) return ctx; ctx->name = kstrdup(name, GFP_KERNEL); if (!ctx->name) { - err = -ENOMEM; - goto out; + erofs_fscache_relinquish_cookie(ctx); + return ERR_PTR(-ENOMEM); } - inode = new_inode(erofs_pseudo_mnt->mnt_sb); - if (!inode) { - err = -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); ctx->domain = domain; - ctx->anon_inode = inode; - inode->i_private = ctx; refcount_inc(&domain->ref); return ctx; -out: - erofs_fscache_relinquish_cookie(ctx); - return ERR_PTR(err); } static @@ -547,7 +537,7 @@ struct erofs_fscache *erofs_domain_register_cookie(struct super_block *sb, return ctx; } spin_unlock(&psb->s_inode_list_lock); - ctx = erofs_fscache_domain_init_cookie(sb, name, flags); + ctx = erofs_fscache_domain_init_cookie(sb, name); mutex_unlock(&erofs_domain_cookies_lock); return ctx; } @@ -558,7 +548,7 @@ struct erofs_fscache *erofs_fscache_register_cookie(struct 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, name); } void erofs_fscache_unregister_cookie(struct erofs_fscache *ctx) @@ -568,18 +558,20 @@ void erofs_fscache_unregister_cookie(struct erofs_fscache *ctx) if (!ctx) return; - domain = ctx->domain; - if (domain) { - mutex_lock(&erofs_domain_cookies_lock); - drop = atomic_read(&ctx->anon_inode->i_count) == 1; - iput(ctx->anon_inode); - mutex_unlock(&erofs_domain_cookies_lock); - if (!drop) - return; - } - erofs_fscache_relinquish_cookie(ctx); - erofs_fscache_domain_put(domain); + if (!ctx->domain) + return erofs_fscache_relinquish_cookie(ctx); + + domain = ctx->domain; + mutex_lock(&erofs_domain_cookies_lock); + /* drop the ref for the sentinel in pseudo mount */ + iput(ctx->inode); + drop = atomic_read(&ctx->inode->i_count) == 1; + if (drop) + erofs_fscache_relinquish_cookie(ctx); + mutex_unlock(&erofs_domain_cookies_lock); + if (drop) + erofs_fscache_domain_put(domain); } int erofs_fscache_register_fs(struct super_block *sb) @@ -587,7 +579,7 @@ int erofs_fscache_register_fs(struct super_block *sb) int ret; struct erofs_sb_info *sbi = EROFS_SB(sb); struct erofs_fscache *fscache; - unsigned int flags; + unsigned int flags = 0; if (sbi->domain_id) ret = erofs_fscache_register_domain(sb); @@ -606,7 +598,6 @@ int erofs_fscache_register_fs(struct super_block *sb) * * Acquired domain/volume will be relinquished in kill_sb() on error. */ - flags = EROFS_REG_COOKIE_NEED_INODE; if (sbi->domain_id) flags |= EROFS_REG_COOKIE_NEED_NOEXIST; fscache = 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 { 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 */ /* 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 /* 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 = NULL; #endif + erofs_free_dev_context(sbi->devs); + sbi->devs = NULL; erofs_fscache_unregister_fs(sb); } From patchwork Wed Jan 11 08:31:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 41818 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3199631wrt; Wed, 11 Jan 2023 00:37:42 -0800 (PST) X-Google-Smtp-Source: AMrXdXvz1OG6/MnERvyAk1CAAe1I9vD8rfeNmVeQKWwARqGskdjjrNuQ3FQZcHPukEun5AGfZ9hO X-Received: by 2002:a17:906:9f0a:b0:7ad:88f8:7663 with SMTP id fy10-20020a1709069f0a00b007ad88f87663mr81285879ejc.43.1673426262282; Wed, 11 Jan 2023 00:37:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673426262; cv=none; d=google.com; s=arc-20160816; b=MLCH1HhndLYoY/IsOu3Uv8n0wBmjQJ5b1lUTM7m37DqbOILAU46DhON/voIiuOiqye u4DTiTv0p1f0hZ2QvvmEeowE3N2rr5QxzM1iJrSVDEs5T2DhB+hz6+0f25/ARYpJ1WY4 KKQ/FjDr/DLF7ojm6G04AJvDDnyjLmIeRX7BXcF/LOlpdFVnA0K8lrZ90GzvadrXMkgs tanLk9oPQeaeKDPuAEp2BimpGugmu0L+XhqsMoV8Xs1j+9Fin+8oLTleg02fPTdq+lLU 3e/YW3PXKAoZu1VFqyXmDWSY5a7gJOuxG5hntaexYArJ1hXIM4CpPoskQajo4G9Cy0Fb x/dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=6Br042J/5SLo0hEWwKmSDXl75HY8YEBMhqVusIiK4VY=; b=uS+DauCBXlx1Gpzi/3bvPOrCfzpE5bnQK98s0WICtjQJb0LwJvc1Z3SLu4F3yAiKcp 47l1A6nu99R0fIkmCRyd8aGPmrbkcc6OH0+Kby1mjXxWQomfC5GpMq7WD648jBH7gaDm N/qkJvpma+vjtztbEWTXurmS6g6l05CXGA4sCgwFt/hA2PZJabhSaR+nL3QP55NeAxSy uraL5ddWvImVobMNtip3I7KdR/CkfHWpnS4PlYRxhweTn+W0/T7M4TMiBmjtjvKOWRrq y+p4Re8bWZqO52j4fZEf27fKUNAF3omJfQSqmNC0DzX2guf3XlqT3nT9pmsox33J55tY ejBQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qf31-20020a1709077f1f00b00859fb13b1fdsi3926727ejc.736.2023.01.11.00.37.19; Wed, 11 Jan 2023 00:37:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236083AbjAKIcY (ORCPT + 99 others); Wed, 11 Jan 2023 03:32:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235868AbjAKIcL (ORCPT ); Wed, 11 Jan 2023 03:32:11 -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 AE248A1A7; Wed, 11 Jan 2023 00:32:07 -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=ay29a033018045168;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VZMQWl9_1673425921; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VZMQWl9_1673425921) by smtp.aliyun-inc.com; Wed, 11 Jan 2023 16:32:02 +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 v2 3/7] erofs: allocate anonymous file of blob for page cache sharing Date: Wed, 11 Jan 2023 16:31:54 +0800 Message-Id: <20230111083158.23462-4-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230111083158.23462-1-jefflexu@linux.alibaba.com> References: <20230111083158.23462-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754714616283544616?= X-GMAIL-MSGID: =?utf-8?q?1754714616283544616?= 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 | 74 +++++++++++++++++++++++++++++++++++++++++++++ fs/erofs/internal.h | 1 + 2 files changed, 75 insertions(+) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 81f96c910277..f715b3efcc77 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" static DEFINE_MUTEX(erofs_domain_list_lock); @@ -22,6 +24,11 @@ struct erofs_fscache_request { refcount_t ref; }; +struct erofs_fscache_share_file_info { + erofs_off_t pa; + pgoff_t max_idx; +}; + static struct erofs_fscache_request *erofs_fscache_req_alloc(struct address_space *mapping, loff_t start, size_t len) { @@ -316,6 +323,73 @@ const struct address_space_operations erofs_fscache_access_aops = { .readahead = erofs_fscache_readahead, }; +static int erofs_fscache_share_meta_release(struct inode *inode, struct file *filp) +{ + kfree(filp->private_data); + filp->private_data = NULL; + return 0; +} + +static const struct file_operations erofs_fscache_share_meta_fops = { + .release = erofs_fscache_share_meta_release, +}; + +static int erofs_fscache_share_file_release(struct inode *inode, struct file *filp) +{ + fput(filp->private_data); + filp->private_data = 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 <= chunk_size */ + struct erofs_map_blocks map = {}; /* .m_la = 0 */ + struct erofs_map_dev mdev; + struct inode *realinode; + struct file *realfile; + struct erofs_fscache_share_file_info *finfo; + int ret; + + ret = erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW); + if (ret) + return ret; + + mdev = (struct erofs_map_dev) { + .m_deviceid = map.m_deviceid, + .m_pa = map.m_pa, + }; + ret = erofs_map_dev(inode->i_sb, &mdev); + if (ret) + return ret; + + finfo = kzalloc(sizeof(struct erofs_fscache_share_file_info), GFP_KERNEL); + if (!finfo) + return -ENOMEM; + finfo->pa = mdev.m_pa; + finfo->max_idx = DIV_ROUND_UP(mdev.m_pa + inode->i_size, PAGE_SIZE); + + realinode = mdev.m_fscache->inode; + ihold(realinode); + realfile = 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); + } + + realfile->private_data = finfo; + filp->private_data = realfile; + return 0; +} + +const struct file_operations erofs_fscache_share_file_fops = { + .llseek = generic_file_llseek, + .open = erofs_fscache_share_file_open, + .release = 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(struct super_block *sb, void erofs_fscache_unregister_cookie(struct erofs_fscache *fscache); 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) { From patchwork Wed Jan 11 08:31:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 41820 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3200424wrt; Wed, 11 Jan 2023 00:40:25 -0800 (PST) X-Google-Smtp-Source: AMrXdXuPlX6jcLH6uRh2UJ1FacRATHAVJNJAJgc1P4mXaGkeaknc75X6PwmkiqpD4HS/lUz6GlKc X-Received: by 2002:a17:907:6e15:b0:7c0:fb3d:11a6 with SMTP id sd21-20020a1709076e1500b007c0fb3d11a6mr77434986ejc.38.1673426425175; Wed, 11 Jan 2023 00:40:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673426425; cv=none; d=google.com; s=arc-20160816; b=fOA/LtkFTXj8azIFyH+pryBLghgjL6W1kYnYhuoCyTlyjbRfQHJnGe9nUDM3/bvBlu 4BtCW40W5Zi5vUO+i8cPu7a76zggX1i+JqLB8eG5e8s5krLrnjkzHAZLe0Rx2++DYHwQ P7d2eLHFIm74yCQv5IA+p/oPAtscHMmqed9IfvjqthZHG0UPPbluFVmZyY0EUDtV9iPh CaFwy5V2zDlBGzVFUH3HzcaaU8D2G7jnFXUzYhu9Ew2s8UHrfINNJiWtRf5g5KaQ282/ Vw11M29tbATIFTxC2RVxKCfnHe8m3M05wHfVMe/Y76F+z4JT6MfvzBtkx5wQmNKaqiIN kUwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Z1eTUhEz+MC1IQIDfws/AqsaGNc+I0/TZrPRNTkpBjM=; b=Oo+OrceH75LdFmSYXuqbCHDY+CPVFZw/0gVYK8+PHtKpdjMxNXyRRm+rVZaqIjvS3V M+tvWV9ebrkaeNAzbroMUvU77pTsBKUxB8FMP4Ds3Q756L08NBfE5c7vTYatFkdmqi7m 8RMWX+8/zxkpghkIhVR6tm75bleNNhe1n0uFrqqY7be6kpyl95jHNDVjKQFmy4vUFiVt JI3BYyzH5AGVdD0GqcXxbqZE0oHHhJNGyx+pe6EigvQQLv74pg3AGolY4Om/pgP7yeaf p1KxbKs3HIjCmufNSWdbRRMUhTvvKHg7yQ2L85QxICPq0moqitZwHz9ovL0KQ1DjNHR/ ao/w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ae10-20020a17090725ca00b0084c4a806258si13288174ejc.645.2023.01.11.00.40.02; Wed, 11 Jan 2023 00:40:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236180AbjAKIcm (ORCPT + 99 others); Wed, 11 Jan 2023 03:32:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230074AbjAKIcP (ORCPT ); Wed, 11 Jan 2023 03:32:15 -0500 Received: from out30-7.freemail.mail.aliyun.com (out30-7.freemail.mail.aliyun.com [115.124.30.7]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E804EBC9F; Wed, 11 Jan 2023 00:32:07 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R721e4;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_---0VZMek6i_1673425922; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VZMek6i_1673425922) by smtp.aliyun-inc.com; Wed, 11 Jan 2023 16:32:03 +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 v2 4/7] erofs: implement .read_iter for page cache sharing Date: Wed, 11 Jan 2023 16:31:55 +0800 Message-Id: <20230111083158.23462-5-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230111083158.23462-1-jefflexu@linux.alibaba.com> References: <20230111083158.23462-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754714786893902689?= X-GMAIL-MSGID: =?utf-8?q?1754714786893902689?= 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 | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index f715b3efcc77..4075d9519a7d 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -384,8 +384,56 @@ static int erofs_fscache_share_file_open(struct inode *inode, struct file *filp) return 0; } +static ssize_t erofs_fscache_share_file_read_iter(struct kiocb *iocb, + struct iov_iter *to) +{ + struct file *filp = iocb->ki_filp; + struct inode *inode = file_inode(filp); + struct file *realfile = filp->private_data; + struct inode *realinode = file_inode(realfile); + struct erofs_fscache_share_file_info *finfo = realfile->private_data; + ssize_t already_read = 0; + int ret = 0; + + /* no need taking (shared) inode lock since it's a ro filesystem */ + if (!iov_iter_count(to)) + return 0; + + if (IS_DAX(inode) || iocb->ki_flags & IOCB_DIRECT) + return -EOPNOTSUPP; + + do { + struct folio *folio; + size_t bytes, copied, offset, fsize; + pgoff_t index = (finfo->pa + iocb->ki_pos) >> PAGE_SHIFT; + + folio = read_cache_folio(realinode->i_mapping, index, NULL, NULL); + if (IS_ERR(folio)) { + ret = PTR_ERR(folio); + break; + } + + fsize = folio_size(folio); + offset = iocb->ki_pos & (fsize - 1); + bytes = min_t(size_t, inode->i_size - iocb->ki_pos, iov_iter_count(to)); + bytes = min_t(size_t, bytes, fsize - offset); + copied = copy_folio_to_iter(folio, offset, bytes, to); + folio_put(folio); + iocb->ki_pos += copied; + already_read += copied; + if (copied < bytes) { + ret = -EFAULT; + break; + } + } while (iov_iter_count(to) && iocb->ki_pos < inode->i_size); + + file_accessed(filp); + return already_read ? already_read : ret; +} + const struct file_operations erofs_fscache_share_file_fops = { .llseek = generic_file_llseek, + .read_iter = erofs_fscache_share_file_read_iter, .open = erofs_fscache_share_file_open, .release = erofs_fscache_share_file_release, }; From patchwork Wed Jan 11 08:31:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 41823 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3201230wrt; Wed, 11 Jan 2023 00:43:14 -0800 (PST) X-Google-Smtp-Source: AMrXdXuS2Yh3NyoZ5xIuTbMK90T5VSaz/x25vVad50pDvn7O54R3t8OL3ikOQ1Z4rmsdxlAUb9jt X-Received: by 2002:a05:6a21:1518:b0:af:e4c5:28e2 with SMTP id nq24-20020a056a21151800b000afe4c528e2mr85816266pzb.17.1673426593779; Wed, 11 Jan 2023 00:43:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673426593; cv=none; d=google.com; s=arc-20160816; b=z4UJaJU2TgqSP0T61kJw61mJ6gDZLlUjJ8GsXzsKkSO8dsannyRnnSn+tVGF0qXXV8 glkk0mYyIl6lgKHq31KBcOHYKhJYBfN4k653qwstYrSeyM/314KHhry9l9fxxzAFGmBL m/ufo7ycUvYwblXuHi+TzfFWOyAnrCb1QMXt5FJWE3ziKGrT3yKtDFxeWvDOQWMEXOSx oFt4cMJ3CY8QwW043PQMFmmXuDiE/Gbuo08KFJ/b6wTBRPo3hENczN64WdJee2t9jB3j o565DrlqfeVVOSBrNYinEZ9YrIaeq5h2aGA7NnbG/HI/bOnnjiGxaQyVAAsqU/+/be3o ze0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=4i8xNwCnt8JSLxAti17Ts6eJiDNGscxRZT7cx7D4KBY=; b=C3O1ekmW1VY7n9x46XVue98Hpd8MIs1kh4tKhrMiNiJWoVbIH4V8zMoAJ2YMomX5Tl xUzzAu572KZPx5uFI8m2r3R+BbgUdJNjjQzoNFuPRTjcFP/11H0j51jjIXJmPTd6aTTp 4ocMyV0ekWs6Yabtt+9M1SW6QB7IL+VYchKuI9zQBPAYyT3Mk+hoznM0Rie8rLfaADc6 Y8F5L3xI2O5oQyYOfqjcIg2zBoIr3OmKoWkUiN7cZI9w0E/G4zYzF+fVvtfUDzrgJJMG gTzIZlZbS2sVLKu5FzfNHTETjpXcFdHzHui8LplKGUTWaDuPbKLuC7lXLN5GC46AOy/2 EtXw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y17-20020a056a00191100b0057731e4f614si14425566pfi.85.2023.01.11.00.43.01; Wed, 11 Jan 2023 00:43:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236052AbjAKIcu (ORCPT + 99 others); Wed, 11 Jan 2023 03:32:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236015AbjAKIcP (ORCPT ); Wed, 11 Jan 2023 03:32:15 -0500 Received: from out30-7.freemail.mail.aliyun.com (out30-7.freemail.mail.aliyun.com [115.124.30.7]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33C353897; Wed, 11 Jan 2023 00:32:08 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R811e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046056;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VZMek7P_1673425923; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VZMek7P_1673425923) by smtp.aliyun-inc.com; Wed, 11 Jan 2023 16:32:04 +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 v2 5/7] erofs: implement .mmap for page cache sharing Date: Wed, 11 Jan 2023 16:31:56 +0800 Message-Id: <20230111083158.23462-6-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230111083158.23462-1-jefflexu@linux.alibaba.com> References: <20230111083158.23462-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754714963994660175?= X-GMAIL-MSGID: =?utf-8?q?1754714963994660175?= 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 | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 4075d9519a7d..e3a65041c9b8 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -431,9 +431,40 @@ static ssize_t erofs_fscache_share_file_read_iter(struct kiocb *iocb, return already_read ? already_read : ret; } +vm_fault_t erofs_fscache_share_fault(struct vm_fault *vmf) +{ + struct file *realfile = vmf->vma->vm_file; + struct erofs_fscache_share_file_info *finfo = realfile->private_data; + pgoff_t index = vmf->pgoff; + + if (unlikely(index >= finfo->max_idx)) + return VM_FAULT_SIGBUS; + + return filemap_fault(vmf); +} + +static const struct vm_operations_struct erofs_fscache_share_file_vm_ops = { + .fault = erofs_fscache_share_fault, +}; + +static int erofs_fscache_share_file_mmap(struct file *file, + struct vm_area_struct *vma) +{ + struct file *realfile = file->private_data; + struct erofs_fscache_share_file_info *finfo = realfile->private_data; + + vma_set_file(vma, realfile); + vma->vm_pgoff = (finfo->pa >> PAGE_SHIFT) + vma->vm_pgoff; + vma->vm_ops = &erofs_fscache_share_file_vm_ops; + + file_accessed(file); + return 0; +} + const struct file_operations erofs_fscache_share_file_fops = { .llseek = generic_file_llseek, .read_iter = erofs_fscache_share_file_read_iter, + .mmap = erofs_fscache_share_file_mmap, .open = erofs_fscache_share_file_open, .release = erofs_fscache_share_file_release, }; From patchwork Wed Jan 11 08:31:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 41821 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3201018wrt; Wed, 11 Jan 2023 00:42:29 -0800 (PST) X-Google-Smtp-Source: AMrXdXsLprk5wWeFJ/1dBcMdrduV4wOCtd8QgcjOKUG/eiOQVe0m6CoJGK/7vpJDJ91p0QXz5YdW X-Received: by 2002:a17:907:d004:b0:83f:1e04:b776 with SMTP id va4-20020a170907d00400b0083f1e04b776mr58634541ejc.40.1673426548863; Wed, 11 Jan 2023 00:42:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673426548; cv=none; d=google.com; s=arc-20160816; b=FEhow9GzpHNBK84cddCfutwcpeb0nu8FYuWJdGl6N/qRuLu6E61av2T2UAGL+tmGJe eRDSNv5dZNxXO5SVDgkSSkmCkbALu1NWYjPNe8YwfzHcMVlPD6exmMS299XqwMG1s8X7 OIhsq3Nkz6Y20yX6DzD+y8bfs71uYPf/BaULS5BAPa4sQ6xlnp81yLtRYXPMWLGCIRx2 snmsBYfQcerT3VfzO4AtYy9eOpay03c2+Fs0zHngFBf8/Tpldq2nYQ7mzU405nv8gYuf fvrzQaYu4pY/tURY2Dl6l+V+usPe7yATn2kRZCcXdRqtQDIjj4GKl4yBsoD08iGw6+Z7 gcDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=eQgHSC0v+wR1qBSLoLf71Q+a7BtxI5yJasONstZoqws=; b=mwIQK3Mo9hpBn5B+y2yXNRoHt8EedHXSeluD2CfkCrkYr7i7cGBZB1sWS/iMmVoSNv A20i2klCW5RTPp090E/g7eodFiul4LYS9XfbunL+ENekbV/xhjbqb696CTrGoE84qlU3 Hahr8LdLB92pF4Yo1XHCf8Lh+LzCgZrfgpAFwVTKwlGSdUBALN4kIP5n7B7Ow56IEbmi evAJdo2xS80SHQ4EcNq1I1n4sZSukiwG7WmRmLs67hEmI+SourbhqehVenAAhUWbuDci /eDdfGqgB+rP8mc3HwkT5fRzgtwrh8L4JGbGiUNSjKShU9C3qCOHC6C/wsN8GktaqOFy O+XA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id wy7-20020a170906fe0700b007c0eb33879asi13371849ejb.667.2023.01.11.00.42.05; Wed, 11 Jan 2023 00:42:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236087AbjAKIc2 (ORCPT + 99 others); Wed, 11 Jan 2023 03:32:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235982AbjAKIcO (ORCPT ); Wed, 11 Jan 2023 03:32:14 -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 69443AE66; Wed, 11 Jan 2023 00:32:08 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R111e4;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_---0VZMSm9k_1673425924; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VZMSm9k_1673425924) by smtp.aliyun-inc.com; Wed, 11 Jan 2023 16:32:05 +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 v2 6/7] erofs: add helper checking if page cache sharing shall be enabled Date: Wed, 11 Jan 2023 16:31:57 +0800 Message-Id: <20230111083158.23462-7-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230111083158.23462-1-jefflexu@linux.alibaba.com> References: <20230111083158.23462-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754714917171954548?= X-GMAIL-MSGID: =?utf-8?q?1754714917171954548?= 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 7c6a7a2d9acf..adf6be08b47c 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -368,6 +368,29 @@ static inline unsigned int erofs_inode_datalayout(unsigned int value) EROFS_I_DATALAYOUT_BITS); } +static inline bool erofs_can_share_page(struct inode *inode) +{ + struct erofs_inode *vi = EROFS_I(inode); + struct erofs_sb_info *sbi = 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 != 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. From patchwork Wed Jan 11 08:31:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jingbo Xu X-Patchwork-Id: 41816 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp3199374wrt; Wed, 11 Jan 2023 00:36:42 -0800 (PST) X-Google-Smtp-Source: AMrXdXvAy+ns/GoCMGBpFsft3+QYW2kZ61AA/YhwCSsftvrNdw4Md4qj+8xM0MUHXhkyl8DH6k74 X-Received: by 2002:a17:902:e949:b0:192:8ec5:fd58 with SMTP id b9-20020a170902e94900b001928ec5fd58mr2004643pll.6.1673426202558; Wed, 11 Jan 2023 00:36:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673426202; cv=none; d=google.com; s=arc-20160816; b=ovT0Bnn2kJP3n36ixKhPcwCZNdCdaCOJGW7oYsYfXSKehEiMr2mPdhHHJx18X4sI9d N5/MNa4Gisb0EcKnnN1D1xzfiv3yLq0h2kB6oqPJpO6aAIPPNYwJjucrBKp/VFvpCBsD 4e4+AQfIvf0Zk35oqelFym6QNV6Yy2hvXkqDZpf+SRLv0pdF+oB7zux/0wPHTK0n8833 Y6XXB63z/lHvrYANrJvIzvWaUE+fzDBSC+rl/g0snA/TU0OBxQUTyBGW1h2Jt7wLg+cU hpX53QtU7k1Otfe2Plp1hvs/0qu1IO1VjDatt/WP0W8xOeQIet7a0AwMCxpMLQbbow7O JOQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Ywj0Z9wK3OfF+4ctvsKglW4bfMpZT3BGG2+W9HhkMAk=; b=yJIPESP6ohBDbdHIG2VasvLBVnQDTUTUJmhx++IjTVJ7FdgJFJtpOvn1eeWr/v3ZQD KWT0sDaVreyDfT1366T64L5Dxqzt0yL6c/i3X3D4p5gW5WMt5C5wgeG0fLdYMUEtmzsH okjv04ookgN+8rq8xzWMbzyVgDYjpAgpCooNSudGn2c+4LJUuyOpa1pMBdLM3togL4O9 AfdNl8FyUq3n2h4rlQsM+i/NVBZ+Tz53gqTV7QtAMwdvu1fYkMLob/mbOH29xILN0lrV GLXJQxegsWHxyWJ2sNqoAPfc06AYlfA5le2ywYrH15EutmImUGBQoTCnB/e4qqhpGWzF vyZg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z5-20020a170903018500b00189d0fa14d6si15284697plg.13.2023.01.11.00.36.30; Wed, 11 Jan 2023 00:36:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231332AbjAKIdu (ORCPT + 99 others); Wed, 11 Jan 2023 03:33:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231889AbjAKIdJ (ORCPT ); Wed, 11 Jan 2023 03:33:09 -0500 Received: from out30-6.freemail.mail.aliyun.com (out30-6.freemail.mail.aliyun.com [115.124.30.6]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6FCCD109; Wed, 11 Jan 2023 00:32:14 -0800 (PST) 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=ay29a033018046049;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VZMeLr-_1673425925; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VZMeLr-_1673425925) by smtp.aliyun-inc.com; Wed, 11 Jan 2023 16:32:06 +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 v2 7/7] erofs: introduce 'sharecache' mount option Date: Wed, 11 Jan 2023 16:31:58 +0800 Message-Id: <20230111083158.23462-8-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230111083158.23462-1-jefflexu@linux.alibaba.com> References: <20230111083158.23462-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754714553698034035?= X-GMAIL-MSGID: =?utf-8?q?1754714553698034035?= 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 | 4 ++++ fs/erofs/super.c | 13 +++++++++++++ 4 files changed, 23 insertions(+) diff --git a/Documentation/filesystems/erofs.rst b/Documentation/filesystems/erofs.rst index 958cad2c4997..1fe38323a1bb 100644 --- a/Documentation/filesystems/erofs.rst +++ b/Documentation/filesystems/erofs.rst @@ -123,6 +123,8 @@ fsid=%s Specify a filesystem image ID for Fscache back-end. domain_id=%s Specify a domain ID for Fscache back-end. The blob images are shared among filesystem instances in the same domain. +(no)sharecache Enable page cache sharing among filesystem instances in + the same domain. =================== ========================================================= 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 = &erofs_generic_iops; if (erofs_inode_is_data_compressed(vi->datalayout)) inode->i_fop = &generic_ro_fops; +#ifdef CONFIG_EROFS_FS_ONDEMAND + else if (erofs_can_share_page(inode)) + inode->i_fop = &erofs_fscache_share_file_fops; +#endif else inode->i_fop = &erofs_file_fops; break; diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index adf6be08b47c..c3ac6d613eb1 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 #define clear_opt(opt, option) ((opt)->mount_opt &= ~EROFS_MOUNT_##option) #define set_opt(opt, option) ((opt)->mount_opt |= EROFS_MOUNT_##option) @@ -373,6 +374,9 @@ static inline bool erofs_can_share_page(struct inode *inode) struct erofs_inode *vi = EROFS_I(inode); struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb); + 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 }; @@ -482,6 +483,7 @@ static const struct fs_parameter_spec erofs_fs_parameters[] = { fsparam_string("device", Opt_device), fsparam_string("fsid", Opt_fsid), fsparam_string("domain_id", Opt_domain_id), + fsparam_flag_no("sharecache", Opt_sharecache), {} }; @@ -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=%s", sbi->fsid); if (sbi->domain_id) seq_printf(seq, ",domain_id=%s", sbi->domain_id); + if (test_opt(opt, SHARE_CACHE)) + seq_puts(seq, ",sharecache"); + else + seq_puts(seq, ",nosharecache"); #endif return 0; }