Skip to content

Commit f36f301

Browse files
Chunhai Guohsiangkao
authored andcommitted
erofs: rename per-CPU buffers to global buffer pool and make it configurable
It will cost more time if compressed buffers are allocated on demand for low-latency algorithms (like lz4) so EROFS uses per-CPU buffers to keep compressed data if in-place decompression is unfulfilled. While it is kind of wasteful of memory for a device with hundreds of CPUs, and only a small number of CPUs concurrently decompress most of the time. This patch renames it as 'global buffer pool' and makes it configurable. This allows two or more CPUs to share a common buffer to reduce memory occupation. Suggested-by: Gao Xiang <[email protected]> Reviewed-by: Gao Xiang <[email protected]> Signed-off-by: Chunhai Guo <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sandeep Dhavale <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Gao Xiang <[email protected]>
1 parent cacd5b0 commit f36f301

File tree

6 files changed

+166
-161
lines changed

6 files changed

+166
-161
lines changed

fs/erofs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
obj-$(CONFIG_EROFS_FS) += erofs.o
44
erofs-objs := super.o inode.o data.o namei.o dir.o sysfs.o
55
erofs-$(CONFIG_EROFS_FS_XATTR) += xattr.o
6-
erofs-$(CONFIG_EROFS_FS_ZIP) += decompressor.o zmap.o zdata.o pcpubuf.o zutil.o
6+
erofs-$(CONFIG_EROFS_FS_ZIP) += decompressor.o zmap.o zdata.o zutil.o
77
erofs-$(CONFIG_EROFS_FS_ZIP_LZMA) += decompressor_lzma.o
88
erofs-$(CONFIG_EROFS_FS_ZIP_DEFLATE) += decompressor_deflate.o
99
erofs-$(CONFIG_EROFS_FS_ONDEMAND) += fscache.o

fs/erofs/decompressor.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static int z_erofs_load_lz4_config(struct super_block *sb,
5454
sbi->lz4.max_distance_pages = distance ?
5555
DIV_ROUND_UP(distance, PAGE_SIZE) + 1 :
5656
LZ4_MAX_DISTANCE_PAGES;
57-
return erofs_pcpubuf_growsize(sbi->lz4.max_pclusterblks);
57+
return z_erofs_gbuf_growsize(sbi->lz4.max_pclusterblks);
5858
}
5959

6060
/*
@@ -159,7 +159,7 @@ static void *z_erofs_lz4_handle_overlap(struct z_erofs_lz4_decompress_ctx *ctx,
159159
docopy:
160160
/* Or copy compressed data which can be overlapped to per-CPU buffer */
161161
in = rq->in;
162-
src = erofs_get_pcpubuf(ctx->inpages);
162+
src = z_erofs_get_gbuf(ctx->inpages);
163163
if (!src) {
164164
DBG_BUGON(1);
165165
kunmap_local(inpage);
@@ -260,7 +260,7 @@ static int z_erofs_lz4_decompress_mem(struct z_erofs_lz4_decompress_ctx *ctx,
260260
} else if (maptype == 1) {
261261
vm_unmap_ram(src, ctx->inpages);
262262
} else if (maptype == 2) {
263-
erofs_put_pcpubuf(src);
263+
z_erofs_put_gbuf(src);
264264
} else if (maptype != 3) {
265265
DBG_BUGON(1);
266266
return -EFAULT;

fs/erofs/internal.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -463,11 +463,11 @@ int erofs_try_to_free_all_cached_folios(struct erofs_sb_info *sbi,
463463
struct erofs_workgroup *egrp);
464464
int z_erofs_map_blocks_iter(struct inode *inode, struct erofs_map_blocks *map,
465465
int flags);
466-
void *erofs_get_pcpubuf(unsigned int requiredpages);
467-
void erofs_put_pcpubuf(void *ptr);
468-
int erofs_pcpubuf_growsize(unsigned int nrpages);
469-
void __init erofs_pcpubuf_init(void);
470-
void erofs_pcpubuf_exit(void);
466+
void *z_erofs_get_gbuf(unsigned int requiredpages);
467+
void z_erofs_put_gbuf(void *ptr);
468+
int z_erofs_gbuf_growsize(unsigned int nrpages);
469+
int __init z_erofs_gbuf_init(void);
470+
void z_erofs_gbuf_exit(void);
471471
int erofs_init_managed_cache(struct super_block *sb);
472472
int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb);
473473
#else
@@ -477,8 +477,8 @@ static inline int erofs_init_shrinker(void) { return 0; }
477477
static inline void erofs_exit_shrinker(void) {}
478478
static inline int z_erofs_init_zip_subsystem(void) { return 0; }
479479
static inline void z_erofs_exit_zip_subsystem(void) {}
480-
static inline void erofs_pcpubuf_init(void) {}
481-
static inline void erofs_pcpubuf_exit(void) {}
480+
static inline int z_erofs_gbuf_init(void) { return 0; }
481+
static inline void z_erofs_gbuf_exit(void) {}
482482
static inline int erofs_init_managed_cache(struct super_block *sb) { return 0; }
483483
#endif /* !CONFIG_EROFS_FS_ZIP */
484484

fs/erofs/pcpubuf.c

Lines changed: 0 additions & 148 deletions
This file was deleted.

fs/erofs/super.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,10 @@ static int __init erofs_module_init(void)
859859
if (err)
860860
goto deflate_err;
861861

862-
erofs_pcpubuf_init();
862+
err = z_erofs_gbuf_init();
863+
if (err)
864+
goto gbuf_err;
865+
863866
err = z_erofs_init_zip_subsystem();
864867
if (err)
865868
goto zip_err;
@@ -879,6 +882,8 @@ static int __init erofs_module_init(void)
879882
sysfs_err:
880883
z_erofs_exit_zip_subsystem();
881884
zip_err:
885+
z_erofs_gbuf_exit();
886+
gbuf_err:
882887
z_erofs_deflate_exit();
883888
deflate_err:
884889
z_erofs_lzma_exit();
@@ -902,7 +907,7 @@ static void __exit erofs_module_exit(void)
902907
z_erofs_lzma_exit();
903908
erofs_exit_shrinker();
904909
kmem_cache_destroy(erofs_inode_cachep);
905-
erofs_pcpubuf_exit();
910+
z_erofs_gbuf_exit();
906911
}
907912

908913
static int erofs_statfs(struct dentry *dentry, struct kstatfs *buf)

0 commit comments

Comments
 (0)