Skip to content

Commit db80b98

Browse files
Chunhai Guohsiangkao
authored andcommitted
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 cached compressed folios. Signed-off-by: Chunhai Guo <[email protected]> Reviewed-by: Gao Xiang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Gao Xiang <[email protected]>
1 parent f5ad9f9 commit db80b98

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

Documentation/ABI/testing/sysfs-fs-erofs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,14 @@ Description: Control strategy of sync decompression:
1616
readahead on atomic contexts only.
1717
- 1 (force on): enable for readpage and readahead.
1818
- 2 (force off): disable for all situations.
19+
20+
What: /sys/fs/erofs/<disk>/drop_caches
21+
Date: November 2024
22+
Contact: "Guo Chunhai" <[email protected]>
23+
Description: Writing to this will drop compression-related caches,
24+
currently used to drop in-memory pclusters and cached
25+
compressed folios:
26+
27+
- 1 : invalidate cached compressed folios
28+
- 2 : drop in-memory pclusters
29+
- 3 : drop in-memory pclusters and cached compressed folios

fs/erofs/internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,8 @@ static inline void erofs_pagepool_add(struct page **pagepool, struct page *page)
450450
void erofs_release_pages(struct page **pagepool);
451451

452452
#ifdef CONFIG_EROFS_FS_ZIP
453+
#define MNGD_MAPPING(sbi) ((sbi)->managed_cache->i_mapping)
454+
453455
extern atomic_long_t erofs_global_shrink_cnt;
454456
void erofs_shrinker_register(struct super_block *sb);
455457
void erofs_shrinker_unregister(struct super_block *sb);

fs/erofs/sysfs.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
enum {
1212
attr_feature,
13+
attr_drop_caches,
1314
attr_pointer_ui,
1415
attr_pointer_bool,
1516
};
@@ -57,11 +58,13 @@ static struct erofs_attr erofs_attr_##_name = { \
5758

5859
#ifdef CONFIG_EROFS_FS_ZIP
5960
EROFS_ATTR_RW_UI(sync_decompress, erofs_mount_opts);
61+
EROFS_ATTR_FUNC(drop_caches, 0200);
6062
#endif
6163

6264
static struct attribute *erofs_attrs[] = {
6365
#ifdef CONFIG_EROFS_FS_ZIP
6466
ATTR_LIST(sync_decompress),
67+
ATTR_LIST(drop_caches),
6568
#endif
6669
NULL,
6770
};
@@ -163,6 +166,20 @@ static ssize_t erofs_attr_store(struct kobject *kobj, struct attribute *attr,
163166
return -EINVAL;
164167
*(bool *)ptr = !!t;
165168
return len;
169+
#ifdef CONFIG_EROFS_FS_ZIP
170+
case attr_drop_caches:
171+
ret = kstrtoul(skip_spaces(buf), 0, &t);
172+
if (ret)
173+
return ret;
174+
if (t < 1 || t > 3)
175+
return -EINVAL;
176+
177+
if (t & 2)
178+
z_erofs_shrink_scan(sbi, ~0UL);
179+
if (t & 1)
180+
invalidate_mapping_pages(MNGD_MAPPING(sbi), 0, -1);
181+
return len;
182+
#endif
166183
}
167184
return 0;
168185
}

fs/erofs/zdata.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ static inline unsigned int z_erofs_pclusterpages(struct z_erofs_pcluster *pcl)
119119
return PAGE_ALIGN(pcl->pclustersize) >> PAGE_SHIFT;
120120
}
121121

122-
#define MNGD_MAPPING(sbi) ((sbi)->managed_cache->i_mapping)
123122
static bool erofs_folio_is_managed(struct erofs_sb_info *sbi, struct folio *fo)
124123
{
125124
return fo->mapping == MNGD_MAPPING(sbi);

0 commit comments

Comments
 (0)