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; }