Documentation/ABI/testing/sysfs-fs-erofs | 7 +++++++ fs/erofs/sysfs.c | 11 +++++++++++ 2 files changed, 18 insertions(+)
Add a sysfs node to drop all compression-related caches, including
pclusters and attached compressed pages.
Signed-off-by: Chunhai Guo <guochunhai@vivo.com>
---
Documentation/ABI/testing/sysfs-fs-erofs | 7 +++++++
fs/erofs/sysfs.c | 11 +++++++++++
2 files changed, 18 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-fs-erofs b/Documentation/ABI/testing/sysfs-fs-erofs
index 284224d1b56f..b66a3f6d3fdf 100644
--- a/Documentation/ABI/testing/sysfs-fs-erofs
+++ b/Documentation/ABI/testing/sysfs-fs-erofs
@@ -16,3 +16,10 @@ 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/<disk>/drop_caches
+Date: November 2024
+Contact: "Guo Chunhai" <guochunhai@vivo.com>
+Description: Writing 1 to this will cause the erofs to drop all
+ compression-related caches, including pclusters and attached
+ compressed pages. Any other value is invalid.
diff --git a/fs/erofs/sysfs.c b/fs/erofs/sysfs.c
index 63cffd0fd261..f068f01437d5 100644
--- a/fs/erofs/sysfs.c
+++ b/fs/erofs/sysfs.c
@@ -10,6 +10,7 @@
enum {
attr_feature,
+ attr_drop_caches,
attr_pointer_ui,
attr_pointer_bool,
};
@@ -57,11 +58,13 @@ static struct erofs_attr erofs_attr_##_name = { \
#ifdef CONFIG_EROFS_FS_ZIP
EROFS_ATTR_RW_UI(sync_decompress, erofs_mount_opts);
+EROFS_ATTR_FUNC(drop_caches, 0200);
#endif
static struct attribute *erofs_attrs[] = {
#ifdef CONFIG_EROFS_FS_ZIP
ATTR_LIST(sync_decompress),
+ ATTR_LIST(drop_caches),
#endif
NULL,
};
@@ -163,6 +166,14 @@ static ssize_t erofs_attr_store(struct kobject *kobj, struct attribute *attr,
return -EINVAL;
*(bool *)ptr = !!t;
return len;
+ case attr_drop_caches:
+ ret = kstrtoul(skip_spaces(buf), 0, &t);
+ if (ret)
+ return ret;
+ if (t != 1)
+ return -EINVAL;
+ z_erofs_shrink_scan(sbi, ~0UL);
+ return len;
}
return 0;
}
--
2.34.1
Hi Chunhai,
kernel test robot noticed the following build errors:
[auto build test ERROR on xiang-erofs/dev-test]
[also build test ERROR on xiang-erofs/dev xiang-erofs/fixes linus/master v6.12-rc7 next-20241112]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Chunhai-Guo/erofs-add-sysfs-node-to-drop-all-compression-related-caches/20241112-170412
base: https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git dev-test
patch link: https://lore.kernel.org/r/20241112091403.586545-1-guochunhai%40vivo.com
patch subject: [PATCH] erofs: add sysfs node to drop all compression-related caches
config: i386-randconfig-003-20241112 (https://download.01.org/0day-ci/archive/20241113/202411130033.ZP2Akhk8-lkp@intel.com/config)
compiler: clang version 19.1.3 (https://github.com/llvm/llvm-project ab51eccf88f5321e7c60591c5546b254b6afab99)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241113/202411130033.ZP2Akhk8-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202411130033.ZP2Akhk8-lkp@intel.com/
All errors (new ones prefixed by >>):
In file included from fs/erofs/sysfs.c:9:
In file included from fs/erofs/internal.h:11:
In file included from include/linux/dax.h:6:
In file included from include/linux/mm.h:2213:
include/linux/vmstat.h:518:36: warning: arithmetic between different enumeration types ('enum node_stat_item' and 'enum lru_list') [-Wenum-enum-conversion]
518 | return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
| ~~~~~~~~~~~ ^ ~~~
>> fs/erofs/sysfs.c:175:3: error: call to undeclared function 'z_erofs_shrink_scan'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
175 | z_erofs_shrink_scan(sbi, ~0UL);
| ^
1 warning and 1 error generated.
vim +/z_erofs_shrink_scan +175 fs/erofs/sysfs.c
132
133 static ssize_t erofs_attr_store(struct kobject *kobj, struct attribute *attr,
134 const char *buf, size_t len)
135 {
136 struct erofs_sb_info *sbi = container_of(kobj, struct erofs_sb_info,
137 s_kobj);
138 struct erofs_attr *a = container_of(attr, struct erofs_attr, attr);
139 unsigned char *ptr = __struct_ptr(sbi, a->struct_type, a->offset);
140 unsigned long t;
141 int ret;
142
143 switch (a->attr_id) {
144 case attr_pointer_ui:
145 if (!ptr)
146 return 0;
147 ret = kstrtoul(skip_spaces(buf), 0, &t);
148 if (ret)
149 return ret;
150 if (t != (unsigned int)t)
151 return -ERANGE;
152 #ifdef CONFIG_EROFS_FS_ZIP
153 if (!strcmp(a->attr.name, "sync_decompress") &&
154 (t > EROFS_SYNC_DECOMPRESS_FORCE_OFF))
155 return -EINVAL;
156 #endif
157 *(unsigned int *)ptr = t;
158 return len;
159 case attr_pointer_bool:
160 if (!ptr)
161 return 0;
162 ret = kstrtoul(skip_spaces(buf), 0, &t);
163 if (ret)
164 return ret;
165 if (t != 0 && t != 1)
166 return -EINVAL;
167 *(bool *)ptr = !!t;
168 return len;
169 case attr_drop_caches:
170 ret = kstrtoul(skip_spaces(buf), 0, &t);
171 if (ret)
172 return ret;
173 if (t != 1)
174 return -EINVAL;
> 175 z_erofs_shrink_scan(sbi, ~0UL);
176 return len;
177 }
178 return 0;
179 }
180
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Hi Chunhai,
kernel test robot noticed the following build errors:
[auto build test ERROR on xiang-erofs/dev-test]
[also build test ERROR on xiang-erofs/dev xiang-erofs/fixes linus/master v6.12-rc7 next-20241112]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Chunhai-Guo/erofs-add-sysfs-node-to-drop-all-compression-related-caches/20241112-170412
base: https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git dev-test
patch link: https://lore.kernel.org/r/20241112091403.586545-1-guochunhai%40vivo.com
patch subject: [PATCH] erofs: add sysfs node to drop all compression-related caches
config: x86_64-randconfig-161-20241112 (https://download.01.org/0day-ci/archive/20241112/202411122209.OQ3CcFg1-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241112/202411122209.OQ3CcFg1-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202411122209.OQ3CcFg1-lkp@intel.com/
All errors (new ones prefixed by >>):
fs/erofs/sysfs.c: In function 'erofs_attr_store':
>> fs/erofs/sysfs.c:175:17: error: implicit declaration of function 'z_erofs_shrink_scan' [-Werror=implicit-function-declaration]
175 | z_erofs_shrink_scan(sbi, ~0UL);
| ^~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
vim +/z_erofs_shrink_scan +175 fs/erofs/sysfs.c
132
133 static ssize_t erofs_attr_store(struct kobject *kobj, struct attribute *attr,
134 const char *buf, size_t len)
135 {
136 struct erofs_sb_info *sbi = container_of(kobj, struct erofs_sb_info,
137 s_kobj);
138 struct erofs_attr *a = container_of(attr, struct erofs_attr, attr);
139 unsigned char *ptr = __struct_ptr(sbi, a->struct_type, a->offset);
140 unsigned long t;
141 int ret;
142
143 switch (a->attr_id) {
144 case attr_pointer_ui:
145 if (!ptr)
146 return 0;
147 ret = kstrtoul(skip_spaces(buf), 0, &t);
148 if (ret)
149 return ret;
150 if (t != (unsigned int)t)
151 return -ERANGE;
152 #ifdef CONFIG_EROFS_FS_ZIP
153 if (!strcmp(a->attr.name, "sync_decompress") &&
154 (t > EROFS_SYNC_DECOMPRESS_FORCE_OFF))
155 return -EINVAL;
156 #endif
157 *(unsigned int *)ptr = t;
158 return len;
159 case attr_pointer_bool:
160 if (!ptr)
161 return 0;
162 ret = kstrtoul(skip_spaces(buf), 0, &t);
163 if (ret)
164 return ret;
165 if (t != 0 && t != 1)
166 return -EINVAL;
167 *(bool *)ptr = !!t;
168 return len;
169 case attr_drop_caches:
170 ret = kstrtoul(skip_spaces(buf), 0, &t);
171 if (ret)
172 return ret;
173 if (t != 1)
174 return -EINVAL;
> 175 z_erofs_shrink_scan(sbi, ~0UL);
176 return len;
177 }
178 return 0;
179 }
180
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Hi Chunhai,
On 2024/11/12 17:14, Chunhai Guo wrote:
> Add a sysfs node to drop all compression-related caches, including
> pclusters and attached compressed pages.
subject: erofs: add sysfs node to drop internal caches
Add a sysfs node to drop compression-related caches, currently
used to drop in-memory pclusters and compressed folios.
I don't think it really drops `compressed folios`, also see
my comment below:
>
> Signed-off-by: Chunhai Guo <guochunhai@vivo.com>
> ---
> Documentation/ABI/testing/sysfs-fs-erofs | 7 +++++++
> fs/erofs/sysfs.c | 11 +++++++++++
> 2 files changed, 18 insertions(+)
>
> diff --git a/Documentation/ABI/testing/sysfs-fs-erofs b/Documentation/ABI/testing/sysfs-fs-erofs
> index 284224d1b56f..b66a3f6d3fdf 100644
> --- a/Documentation/ABI/testing/sysfs-fs-erofs
> +++ b/Documentation/ABI/testing/sysfs-fs-erofs
> @@ -16,3 +16,10 @@ 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/<disk>/drop_caches
> +Date: November 2024
> +Contact: "Guo Chunhai" <guochunhai@vivo.com>
> +Description: Writing 1 to this will cause the erofs to drop all
> + compression-related caches, including pclusters and attached
> + compressed pages. Any other value is invalid.
> diff --git a/fs/erofs/sysfs.c b/fs/erofs/sysfs.c
> index 63cffd0fd261..f068f01437d5 100644
> --- a/fs/erofs/sysfs.c
> +++ b/fs/erofs/sysfs.c
> @@ -10,6 +10,7 @@
>
> enum {
> attr_feature,
> + attr_drop_caches,
> attr_pointer_ui,
> attr_pointer_bool,
> };
> @@ -57,11 +58,13 @@ static struct erofs_attr erofs_attr_##_name = { \
>
> #ifdef CONFIG_EROFS_FS_ZIP
> EROFS_ATTR_RW_UI(sync_decompress, erofs_mount_opts);
> +EROFS_ATTR_FUNC(drop_caches, 0200);
> #endif
>
> static struct attribute *erofs_attrs[] = {
> #ifdef CONFIG_EROFS_FS_ZIP
> ATTR_LIST(sync_decompress),
> + ATTR_LIST(drop_caches),
> #endif
> NULL,
> };
> @@ -163,6 +166,14 @@ static ssize_t erofs_attr_store(struct kobject *kobj, struct attribute *attr,
> return -EINVAL;
> *(bool *)ptr = !!t;
> return len;
> + case attr_drop_caches:
> + ret = kstrtoul(skip_spaces(buf), 0, &t);
> + if (ret)
> + return ret;
> + if (t != 1)
> + return -EINVAL;
if (t & 2)
z_erofs_shrink_scan(sbi, ~0UL);
if (t & 1)
invalidate_mapping_pages(EROFS_I_SB(inode)->managed_cache->i_mapping, 0, -1);
or you could export MNGD_MAPPING macros again.
Thanks,
Gao Xiang
© 2016 - 2026 Red Hat, Inc.