From nobody Sat Nov 23 15:57:45 2024 Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sg2apc01on2086.outbound.protection.outlook.com [40.107.215.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 362901CD1EE for ; Tue, 12 Nov 2024 11:24:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.215.86 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731410656; cv=fail; b=UIyrqjjl8WJ3bV4LU0Yd1dLUEsK385pZoFVSySFHSsi5n2WGILDgAZuYFWERpKBNB3m7XJcE0VumII/3GgCmTvnvbZUM6pvOGoKM1fg9QAkAwjH72bMx8eKTGYkgwFyw8ZJrhR1g3aqsx66fKDB85E9GKU8lLaBj65mAX/2Gr78= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731410656; c=relaxed/simple; bh=LkQi/TAMvBpgpLUbh+HyHlmfIWAsGP6xlzas6Y2eVXw=; h=From:To:Cc:Subject:Date:Message-Id:Content-Type:MIME-Version; b=HLzLsWtQ+e/Di5IfysjiErkCJDeHlZq0NYa9O2m8JbJK/LXkxqqoUtSLOX07tWZ4JfdvuYwATZd+dJyp8p9ASi1N1yBlPaDDNw+QPFMjJQnHioxjHEe2ZiH2Iy6TLaKWIeuxNkkNsdHivt6hR4P3CBUljCjBgIIXA/hLy/tm5U8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=vivo.com; spf=pass smtp.mailfrom=vivo.com; dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com header.b=hO7wlBau; arc=fail smtp.client-ip=40.107.215.86 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=vivo.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=vivo.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com header.b="hO7wlBau" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XGvaebhFllnpLVUTNxyQKzhBtxAQOj2hkQhkSZbPiDN2STIboy0HOphDvQyENZasa2G261SOk4OUcVYgbQPK4qO7O3vkpmBKH2gICFWUNc+RIgTjDxE+uijx4UOxWaMVzlvgRn8rOUrfE+JLhrVyNb9qKvISlPqXhmotBPWPKlX+MfKi9z8gy+BnY5rVgJWhKklO/jTGHiDUYv6l6ymWkhxOdehLkkP1SkAnKxqyOdAul9UJyCvREiL83tDK+jvFH+ZIxKED+Wayp+B0ZzPD6HtRdYqyQ8DoBnth+RkkNCvzBQO/Pialj4RdIGn02IYZrPGmVJpbsfzOm1Z0xNeBjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=E/1/UxBloOLNJMsMuCZVi5UF3yiF3HPmHn1WM2SYY5c=; b=DO09jtMsqR1Xl5QmcFRZNRJKpl6atvPHZYv2cVkk3PlNyCqoo3xe3BxnlyJIC9P06LMmT3Ra8IF/1vNA7VhDSAZcrgK4IZEYjSapaUzsxXZO3uyojVR0gxjrO1EsRHF/cFeQ2mGs0nH1V44Jq0IwEK+8AR/CBeQOW5IVJr4UQFfAxqJEIQhZFRvf6FaZIWwfjQtNgrVCa1qUpJMu6u/LQzK1ugwswgpmH6ObGEnKRV9ZylxFuibDF7Yia0dXDFUhVVK6hdlOC+ujonOPq1UTcgLs7SmVR4QK1Mvy/vKiGh+AfO8TFzzdkyd7xvnparbOUtzfgmr36DNLfdT5cIRcEw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=E/1/UxBloOLNJMsMuCZVi5UF3yiF3HPmHn1WM2SYY5c=; b=hO7wlBauLTzYDMt0l/betyPfoNxmMFfmqJhA11PmKaIoKM5R/a/5DkkTpNZFsnFwyALeiZJUNaluQluKw9cXLOxLQgh/wjWxw9o/azpdqr0qGjI9LSPLIBI2dVDlFs2tXx3smyDc5X36D+MOqmjCXSzk/GnpnDnYr/WuJIm5Rwc2cb1rTmb0Dxcn8hRl44QbG58LKH3mGcFAo5iwf4sTYmtxvRKqKgcKBbtU+D3JceGZ9fiKhOMWyR4CIoC5fx6+mLWhbI2RXYtp4gi7Kb28r/7DBR7Lj40vF5TUnkfRIWxbgQhQ4Ezp1RuqitpazOVRZ4aa3232OHewoqc7Y6QG1g== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from TYZPR06MB7096.apcprd06.prod.outlook.com (2603:1096:405:b5::13) by SEYPR06MB6613.apcprd06.prod.outlook.com (2603:1096:101:169::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.16; Tue, 12 Nov 2024 11:24:10 +0000 Received: from TYZPR06MB7096.apcprd06.prod.outlook.com ([fe80::6c3a:9f76:c4a5:c2b]) by TYZPR06MB7096.apcprd06.prod.outlook.com ([fe80::6c3a:9f76:c4a5:c2b%6]) with mapi id 15.20.8158.011; Tue, 12 Nov 2024 11:24:10 +0000 From: Chunhai Guo To: xiang@kernel.org Cc: chao@kernel.org, huyue2@coolpad.com, jefflexu@linux.alibaba.com, dhavale@google.com, linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org, Chunhai Guo Subject: [PATCH v2] erofs: add sysfs node to drop internal caches Date: Tue, 12 Nov 2024 04:40:34 -0700 Message-Id: <20241112114034.618402-1-guochunhai@vivo.com> X-Mailer: git-send-email 2.34.1 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SI2PR04CA0014.apcprd04.prod.outlook.com (2603:1096:4:197::18) To TYZPR06MB7096.apcprd06.prod.outlook.com (2603:1096:405:b5::13) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYZPR06MB7096:EE_|SEYPR06MB6613:EE_ X-MS-Office365-Filtering-Correlation-Id: 9b7ec70b-9820-4d51-443e-08dd030c8722 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|376014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?SNwdJ3Mqo8kfX2DRWz1KfVsKRus5CBB+ZPiEB6BwQzSFzbE9v2e3Casn9jLv?= =?us-ascii?Q?ExVIXUbg4J79ZG7O1UjS9PQkF1/XisGDraEZ2YKHbIeY0/PBCJn144utlgRY?= =?us-ascii?Q?atec17zpLx59Tzg+g+Bq5TOksQLppvvjmR+48qmi6+rkDkgi4bq31WPoaUwW?= =?us-ascii?Q?1MukpUoTVLkrsc3zF77woOhylxe7dCYKlXNHsaT7jBs5EAHfTiwhZOoqqOTP?= =?us-ascii?Q?i46ByWl9RVKo6QyueHgUU8aqsQQa9+yqYGOb+SYGKPlPe+lhRAFX1x1Q9Nvj?= =?us-ascii?Q?/PRb6bYIKkwyy4G8RJ9rU8HK+JZ5ydZYO1yA+vga+7p3g4EeBrHZof+MmjTp?= =?us-ascii?Q?UOuBhKmDvNA1wrzZAg+KOhDK2rM+dpNpZEVhkKVjuVKQS3+gxMCrCXvYRtK6?= =?us-ascii?Q?ZzRHDHypYM9TPgABOVY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= =?us-ascii?Q?Tqros3MjIGMbvuWJPtxHLTaNR1MLkqIiArpQkcrGwEpf5NJSUZAJMbSqMFEZ?= =?us-ascii?Q?u/p2ADk=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:TYZPR06MB7096.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(52116014)(376014)(1800799024)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?HbJZDJoDFq2uD3fGruxNEYL6xVCFxWlgz99rqJIuLVf7wb9NJRTwyVXuzdfS?= =?us-ascii?Q?pSWLnf6Quwxbo71JYHV0ICnpmaRvs8VWm4gDI7bmtsK3NNwPdNEzE3z2bO/t?= =?us-ascii?Q?kSKMrPPBGUuV+MLSqTyKu2QP9jMbr8KHsMGD6I73B4tOtpLFm71QckGTnWE1?= =?us-ascii?Q?CKwjNegG7okQBDgATIU9y7DbjPo2hEvGv97BLp2Onvonhn0pqYNRj+uaQ28r?= =?us-ascii?Q?K8DQEf7ApI7/SnQs5tynafV9cBXGmnj/hbLBTRhu23JA/c0CR0TrrSkCZVnF?= =?us-ascii?Q?VVVApKJ3JP3XyytmcdXiR7QwhA9pgbcDxSsbyQ023r9gMMHg1oRmnJcd9Nw+?= =?us-ascii?Q?Tl91DIHxzrqF39oE8shqYleOqhZL87zp2p5bBJ35x2qbK4D5WhvQNtqmbmrI?= =?us-ascii?Q?kD06DB5ji0nxsKxSOjA95JKInDNKPTDpxUNKZk+6hs7mrxwuJVIpSCa5s2rG?= =?us-ascii?Q?3MgsYWPdEQurBs46besZBaeKkb2EPw5YOYUGTb1hODSG0YCA/JkCl5PZbm7B?= =?us-ascii?Q?Xrn06DQDECoE3bHiiurdw3dpDgONGeJS72ZdhjYzI/I/sc0q+zAUxLt8JY/j?= =?us-ascii?Q?1k/g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VgOKzMsC0r7JUhw4qLnpwqRE?= =?us-ascii?Q?X1bpJ/K9KdaX7B9q/6zM8f1kbqzbf6cikhrFO5hypfrX+65BqVa0m5huEdVw?= =?us-ascii?Q?pe6h62EY+zPtHqDtHRaGy3UvC79vq9SeAQ61rUkg?= X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9b7ec70b-9820-4d51-443e-08dd030c8722 X-MS-Exchange-CrossTenant-AuthSource: TYZPR06MB7096.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Nov 2024 11:24:09.9533 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: IHMWIDkhNEju+MAYPmcuYMKYjmtes55S4HI8O+e1YJQjAurBSElVSGC5RJhg2lhoDmuwmoHMPlfbSVR9xEQ0jQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEYPR06MB6613 Content-Type: text/plain; charset="utf-8" Add a sysfs node to drop compression-related caches, currently used to drop in-memory pclusters and compressed folios. Signed-off-by: Chunhai Guo --- v1: https://lore.kernel.org/linux-erofs/fabdfe9f-9293-45c2-8cf2-3d86c248ab4= c@linux.alibaba.com change since v1: - Change subject as suggested by Gao Xiang. - Use different bits to indicate different meanings in the sysfs node. --- Documentation/ABI/testing/sysfs-fs-erofs | 11 +++++++++++ fs/erofs/internal.h | 2 ++ fs/erofs/sysfs.c | 15 +++++++++++++++ fs/erofs/zdata.c | 1 - 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Documentation/ABI/testing/sysfs-fs-erofs b/Documentation/ABI/t= esting/sysfs-fs-erofs index 284224d1b56f..44d863cd07b5 100644 --- a/Documentation/ABI/testing/sysfs-fs-erofs +++ b/Documentation/ABI/testing/sysfs-fs-erofs @@ -16,3 +16,14 @@ Description: Control strategy of sync decompression: readahead on atomic contexts only. - 1 (force on): enable for readpage and readahead. - 2 (force off): disable for all situations. + +What: /sys/fs/erofs//drop_caches +Date: November 2024 +Contact: "Guo Chunhai" +Description: Writing to this will drop compression-related caches, + currently used to drop in-memory pclusters and + compressed folios: + + - 1 : drop in-memory compressed folios + - 2 : drop in-memory pclusters + - 3 : drop in-memory pclusters and compressed folios diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 3905d991c49b..0328e6b98c1b 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -450,6 +450,8 @@ static inline void erofs_pagepool_add(struct page **pag= epool, struct page *page) void erofs_release_pages(struct page **pagepool); =20 #ifdef CONFIG_EROFS_FS_ZIP +#define MNGD_MAPPING(sbi) ((sbi)->managed_cache->i_mapping) + extern atomic_long_t erofs_global_shrink_cnt; void erofs_shrinker_register(struct super_block *sb); void erofs_shrinker_unregister(struct super_block *sb); diff --git a/fs/erofs/sysfs.c b/fs/erofs/sysfs.c index 63cffd0fd261..01d509e43827 100644 --- a/fs/erofs/sysfs.c +++ b/fs/erofs/sysfs.c @@ -10,6 +10,7 @@ =20 enum { attr_feature, + attr_drop_caches, attr_pointer_ui, attr_pointer_bool, }; @@ -57,11 +58,13 @@ static struct erofs_attr erofs_attr_##_name =3D { \ =20 #ifdef CONFIG_EROFS_FS_ZIP EROFS_ATTR_RW_UI(sync_decompress, erofs_mount_opts); +EROFS_ATTR_FUNC(drop_caches, 0200); #endif =20 static struct attribute *erofs_attrs[] =3D { #ifdef CONFIG_EROFS_FS_ZIP ATTR_LIST(sync_decompress), + ATTR_LIST(drop_caches), #endif NULL, }; @@ -163,6 +166,18 @@ static ssize_t erofs_attr_store(struct kobject *kobj, = struct attribute *attr, return -EINVAL; *(bool *)ptr =3D !!t; return len; + case attr_drop_caches: + ret =3D kstrtoul(skip_spaces(buf), 0, &t); + if (ret) + return ret; + if (t < 1 || t > 3) + return -EINVAL; + + if (t & 1) + invalidate_mapping_pages(MNGD_MAPPING(sbi), 0, -1); + if (t & 2) + z_erofs_shrink_scan(sbi, ~0UL); + return len; } return 0; } diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index 877bce7709d5..01f147505487 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -119,7 +119,6 @@ static inline unsigned int z_erofs_pclusterpages(struct= z_erofs_pcluster *pcl) return PAGE_ALIGN(pcl->pclustersize) >> PAGE_SHIFT; } =20 -#define MNGD_MAPPING(sbi) ((sbi)->managed_cache->i_mapping) static bool erofs_folio_is_managed(struct erofs_sb_info *sbi, struct folio= *fo) { return fo->mapping =3D=3D MNGD_MAPPING(sbi); --=20 2.34.1