From nobody Sat Nov 23 12:33:44 2024 Received: from HK2PR02CU002.outbound.protection.outlook.com (mail-eastasiaazon11010039.outbound.protection.outlook.com [52.101.128.39]) (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 67ACE70819 for ; Wed, 13 Nov 2024 03:55:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.128.39 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731470144; cv=fail; b=qaF0PHkzn+6X/ob/G8pPSe4bAyrUgI+Ri3uUCNvSb9gxMODKHF/w1kTPpJOivAztINrqZ5OwDf6iVFweUbTnoqIZ4TjRC7nsBZEmv8CAr018PAj/qQ4nzLcwFFs13+i0ae16Bvc4nTS9MrYY5LGOdEoaSP7FfHlRBr98ovClw2A= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731470144; c=relaxed/simple; bh=+5FAkRGblN30ncL4xXrETGLzAOlJ7m8laKgdp97URs8=; h=From:To:Cc:Subject:Date:Message-Id:Content-Type:MIME-Version; b=Ok05RXYPNUGBN2epGGn80mEVZcSJDk7FmXyMgqpGmvvK3CGd8hB1LRInKuheWLeiKwlwlwkkId8MVd64GtkFMeWv4b1VGh+wF2/POPpoLqGK+9eVCQtoNBfmROa1DQ63891sbmRQD05RkStlZUdXNKpAHblG4E9dnm3EQtEJugk= 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=afbjvbbm; arc=fail smtp.client-ip=52.101.128.39 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="afbjvbbm" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WdZV189kjEbcTo5EYIui/iIVxNCE6PieX/Z9ife26LTDkoNLC1SE66MtdqxHAOcnibOfAvOxEIGEwhr8Dvj7QHoSV7pmueEfybWwl3hm9TUORBW8hcdM7g6oviUN3wUHtIm+5GpS4VjryTpMLDyksUCo/sXrwtRdRW8bXmYwXos5S+SAEWhHeOPICT6LbwrhJbJZgKOlDRkU0Il9UNlrk2kX47XpvGpred5DeuWJBuvsC7JDO4wyIVbHq8cB1YHHFTHHnrJJSSnZjt/+seYsy0ybhcDS/okVv2eslcgvaAsSAbC537akSSsqYuoRVLtlrODll/5wOLCDJ+jwZJHtJg== 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=uDjBDGM9sl7HR7f182CjRzeEADxB6c8tQaOxxCyTI8I=; b=g36juR4Iju9fS/9u0ENBdpsN0vgd5K1ZVpg29keLSrJ3TDmngbQ/mXMBaPIDeLpaoITF2Bg4XNzHNGPipOD4xLbxqqedWaU968Ahvb/KedAeRgIvqi77Ib7v9O5XAV8POU6Tu57E/Pw/S7NJ2zFw0fFgqMLJO7DCBK5SAU1Lg00I9Q+O3SxWShlB7rSDXTdhkKgTYMWuHbO9e0ABs8TW0+mH6tKFPmP18UA5v1PiGLdZj4oSFAepeRAgqsfyIsyOEHz4FbOfUz8KIH4Gi0qDU+DDaNR6I+3D/k8W9aHnyAF4tBNH3JNzIPpRfjz4rJIXbGxsifoHNkjA7P9w34HFgQ== 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=uDjBDGM9sl7HR7f182CjRzeEADxB6c8tQaOxxCyTI8I=; b=afbjvbbmRBBfI7xGRwOEsZi2Wp4fc9lMb+MOoDN3Q1kYbwrQW1i3VlB1Uc9mD+vbzyqdM9QKVDkUzf4Y4ScQVGnox6LGuG/jiB6GllWi7gmIlYNBEVwn5EFae20htT2bM6EiJh8qNrqumRqu8WNW1ew/u2ThmKFyby9Nxt6/45RYzo1GIJw7Q/pURhotQZhmjtewgFnHea9V8+mlRo1P9Ivk842f+XSI4UP0IQuTAnE8V6HIZmEHZkeVFHsWR/gqnKXgzR2PjnRkJzAinmpgSKNP7MfDjJUmxHDIDCK3QJvHUje0fFZWQW+t4tlaRgxnlqI1d/QeDOmXIbT6SeYTzg== 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 KL1PR06MB6735.apcprd06.prod.outlook.com (2603:1096:820:fb::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.15; Wed, 13 Nov 2024 03:55:37 +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; Wed, 13 Nov 2024 03:55:37 +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 v3] erofs: add sysfs node to drop internal caches Date: Tue, 12 Nov 2024 21:11:48 -0700 Message-Id: <20241113041148.749129-1-guochunhai@vivo.com> X-Mailer: git-send-email 2.34.1 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SG2PR03CA0088.apcprd03.prod.outlook.com (2603:1096:4:7c::16) 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_|KL1PR06MB6735:EE_ X-MS-Office365-Filtering-Correlation-Id: 332b4ef8-e957-4c7d-bd42-08dd03970859 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?+JCNc0hYYmJ3fmSZRx1GtF+1hHa+rtnP1Tdx0uUCAHyRw/rFxcO9xuU6i7oC?= =?us-ascii?Q?+ZpFWWn1f1z2SqFwoWvjWUuMoVjs4vlFI8xcbXxIGtDQbzoLIp3qjzVJ4r5P?= =?us-ascii?Q?YNY2b2pK8hRJlLsOapNfVg1ymA1cuPhb6A/RTqTrr1ct8rgy9YaLrhtSPn9q?= =?us-ascii?Q?x9v6iK4GmvhEdABBJD3TQDWD2zaM7zzt4Yi41WAwG3FX30vnJlP3/H1bjDyr?= =?us-ascii?Q?z7S+Au9uHQ919UfG6++a+HYa9k7PDSSGPNYN/Wytt4r2CRt7MPRtuuCOpReu?= =?us-ascii?Q?MRGA2tbNjAEs3DK97jPxs5oGsNajOj9h0SNdu/p83wil8pXwK8yJbJfguiFH?= =?us-ascii?Q?PVbLWg2LlYpXWlWwUYL/L3x/OckUpcUWvO0yLRS+6b6B2R7/4hBJcVNgJBe4?= =?us-ascii?Q?Z3f00GWTyqsizegpFsmZGaHqEgfH8cPnBaV3/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diG0EoiAtyGLewCypuWu3TDOAyGrrLar7paOqkNEgu2ppx?= =?us-ascii?Q?w/Ts8xw=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?zLoiU7faCOhcvms3M9FhPIXZzoN6QpytegjpTcMY5tJKL3Jiht/G76W2xOdN?= =?us-ascii?Q?HjyoepYoIDjcsbMD5zjRzeFBloOKrTGelA0kvypvUyOA/HAMdU9iKkcdXc5q?= =?us-ascii?Q?W4wYZtcJOeRKiXDtjf6EPKslQ0gt3Bw+EwASHsj7RiOtJWezcnMpgMj8rTff?= =?us-ascii?Q?jTBtsQXlfqRDbcEUU7YkCtYdzIZxAYF5t9AzEMkteqJaWzuYOnL2hRyCYDho?= =?us-ascii?Q?biTbN2SrXplYMaOd4UZFANWOL6ajQ6Ucqx4l5J61orCdJzX/ANmvS5aF1bMN?= =?us-ascii?Q?prsy9SQBQSFLiOvh9Lc6qbZnTCPS26mYgPlaj0XO83NNBxdQmNKZCfkgA0rx?= =?us-ascii?Q?u0Caq28srkmwNZzM0GwJdLvfXieTHL2hF3yHp9Xvc1QsBv1eQ2PywislVzBG?= =?us-ascii?Q?SECry5aIOnvGjgZa94s5I+Cl4TsTtsGqDx3YnfAerentpVaNY1V2kximqww2?= =?us-ascii?Q?7HXeHPuROmhQodEdYCRH4/EdOtBz7YCThi7ju+hMP/PDwFP2Dfd/wpqgH+8r?= =?us-ascii?Q?UfV+FrGEuhzF/lSgkMMH5TG6bDgEIQsYIdEqMuFbQ62wQk6WZAksIcO30iMM?= =?us-ascii?Q?QAQQ53r6k7D0BcXxeWXokV/Nbcqlm0JwEUS7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UZ32HZuzqVdBPjNhu5YlFqGaHWcrRfMpFpU79dQqsv1vNiTDJ6PHpn1tFOKh?= =?us-ascii?Q?YozAaUvVTS6R6dmolhH8G63AkcJQ+L+6U+rJItQJ?= X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 332b4ef8-e957-4c7d-bd42-08dd03970859 X-MS-Exchange-CrossTenant-AuthSource: TYZPR06MB7096.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Nov 2024 03:55:37.3146 (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: Yv9jQd5LckDT1Um3Y6lKR9zFDo/nguw/u2pHId1ApJzwXUdwDHyZ3ZdThXXW6RfEMpfAzBs5lHQdsqn2hYDweQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR06MB6735 Content-Type: text/plain; charset="utf-8" Add a sysfs node to drop compression-related caches, currently used to drop in-memory pclusters and cached compressed folios. Signed-off-by: Chunhai Guo Reviewed-by: Gao Xiang --- v2->v3: - All cached folios should be disconnected before invalidating. - Only add sysfs node when CONFIG_EROFS_FS_ZIP is enabled. v1: https://lore.kernel.org/linux-erofs/fabdfe9f-9293-45c2-8cf2-3d86c248ab4= c@linux.alibaba.com v1->v2: - 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 | 18 ++++++++++++++++++ fs/erofs/zdata.c | 1 - 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Documentation/ABI/testing/sysfs-fs-erofs b/Documentation/ABI/t= esting/sysfs-fs-erofs index 284224d1b56f..b134146d735b 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 cached + compressed folios: + + - 1 : invalidate cached compressed folios + - 2 : drop in-memory pclusters + - 3 : drop in-memory pclusters and cached 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..4145b732d30f 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,21 @@ static ssize_t erofs_attr_store(struct kobject *kobj, = struct attribute *attr, return -EINVAL; *(bool *)ptr =3D !!t; return len; +#ifdef CONFIG_EROFS_FS_ZIP + 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 & 2) + z_erofs_shrink_scan(sbi, ~0UL); + + if (t & 1) + invalidate_mapping_pages(MNGD_MAPPING(sbi), 0, -1); + return len; +#endif } 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