fs/squashfs/Kconfig | 51 ++++++++++++++++-- fs/squashfs/block.c | 2 +- fs/squashfs/decompressor.c | 2 +- fs/squashfs/decompressor_multi.c | 20 ++++--- fs/squashfs/decompressor_multi_percpu.c | 23 +++++--- fs/squashfs/decompressor_single.c | 15 ++++-- fs/squashfs/squashfs.h | 23 ++++++-- fs/squashfs/squashfs_fs_sb.h | 4 +- fs/squashfs/super.c | 93 +++++++++++++++++++++++++++++++-- 9 files changed, 199 insertions(+), 34 deletions(-)
Currently, Squashfs supports multiple decompressor parallel modes. However, this
mode can be configured only during kernel building and does not support flexible
selection during runtime.
In the current patch set, the mount parameter "threads=" is added to allow users
to select the parallel decompressor mode and configure the number of decompressors
when mounting a file system.
"threads=<single|multi|percpu|1|2|3|...>"
The upper limit is num_online_cpus() * 2.
v5: fix a low-level mistake in patching:
fs/squashfs/super.c:492:7: warning: "CONFIG_SQUASHFS_DECOMP_MULTI" is
not defined, evaluates to 0 [-Wundef]
v4: https://lore.kernel.org/lkml/20220916083604.33408-1-nixiaoming@huawei.com/
Based on Philip Lougher's suggestion, make the following updates:
1. Use static modifiers to avoid changing symbol names.
2. Fixed some formatting issues
v3: https://lore.kernel.org/lkml/20220902094855.22666-1-nixiaoming@huawei.com/
Based on Philip Lougher's suggestion, make the following updates:
1. The default configuration is the same as that before the patch installation.
2. Compile the three decompression modes when the new configuration is enabled.
3. "threads=1" supports only the SQUASHFS_DECOMP_SINGLE mode.
v2: https://lore.kernel.org/lkml/20220816010052.15764-1-nixiaoming@huawei.com/
fix warning: sparse: incorrect type in initializer (different address spaces)
Reported-by: kernel test robot <lkp@intel.com>
v1: https://lore.kernel.org/lkml/20220815031100.75243-1-nixiaoming@huawei.com/
Xiaoming Ni (2):
squashfs: add the mount parameter theads=<single|multi|percpu>
squashfs: Allows users to configure the number of decompression
threads
fs/squashfs/Kconfig | 51 ++++++++++++++++--
fs/squashfs/block.c | 2 +-
fs/squashfs/decompressor.c | 2 +-
fs/squashfs/decompressor_multi.c | 20 ++++---
fs/squashfs/decompressor_multi_percpu.c | 23 +++++---
fs/squashfs/decompressor_single.c | 15 ++++--
fs/squashfs/squashfs.h | 23 ++++++--
fs/squashfs/squashfs_fs_sb.h | 4 +-
fs/squashfs/super.c | 93 +++++++++++++++++++++++++++++++--
9 files changed, 199 insertions(+), 34 deletions(-)
--
2.12.3
Currently, Squashfs supports multiple decompressor parallel modes. However, this
mode can be configured only during kernel building and does not support flexible
selection during runtime.
In the current patch set, the mount parameter "threads=" is added to allow users
to select the parallel decompressor mode and configure the number of decompressors
when mounting a file system.
"threads=<single|multi|percpu|1|2|3|...>"
The upper limit is num_online_cpus() * 2.
v6: fix opt->thread_ops unassigned if CONFIG_SQUASHFS_CHOICE_DECOMP_BY_MOUNT is not set.
v5: https://lore.kernel.org/lkml/20220930091406.50869-1-nixiaoming@huawei.com/
fix a low-level mistake in patching:
fs/squashfs/super.c:492:7: warning: "CONFIG_SQUASHFS_DECOMP_MULTI" is
not defined, evaluates to 0 [-Wundef]
v4: https://lore.kernel.org/lkml/20220916083604.33408-1-nixiaoming@huawei.com/
Based on Philip Lougher's suggestion, make the following updates:
1. Use static modifiers to avoid changing symbol names.
2. Fixed some formatting issues
v3: https://lore.kernel.org/lkml/20220902094855.22666-1-nixiaoming@huawei.com/
Based on Philip Lougher's suggestion, make the following updates:
1. The default configuration is the same as that before the patch installation.
2. Compile the three decompression modes when the new configuration is enabled.
3. "threads=1" supports only the SQUASHFS_DECOMP_SINGLE mode.
v2: https://lore.kernel.org/lkml/20220816010052.15764-1-nixiaoming@huawei.com/
fix warning: sparse: incorrect type in initializer (different address spaces)
Reported-by: kernel test robot <lkp@intel.com>
v1: https://lore.kernel.org/lkml/20220815031100.75243-1-nixiaoming@huawei.com/
*** BLURB HERE ***
Xiaoming Ni (2):
squashfs: add the mount parameter theads=<single|multi|percpu>
squashfs: Allows users to configure the number of decompression
threads
fs/squashfs/Kconfig | 51 +++++++++++--
fs/squashfs/block.c | 2 +-
fs/squashfs/decompressor.c | 2 +-
fs/squashfs/decompressor_multi.c | 20 +++--
fs/squashfs/decompressor_multi_percpu.c | 23 ++++--
fs/squashfs/decompressor_single.c | 15 +++-
fs/squashfs/squashfs.h | 23 ++++--
fs/squashfs/squashfs_fs_sb.h | 4 +-
fs/squashfs/super.c | 97 ++++++++++++++++++++++++-
9 files changed, 203 insertions(+), 34 deletions(-)
--
2.27.0
On 19/10/2022 04:09, Xiaoming Ni wrote: > Currently, Squashfs supports multiple decompressor parallel modes. However, this > mode can be configured only during kernel building and does not support flexible > selection during runtime. > > In the current patch set, the mount parameter "threads=" is added to allow users > to select the parallel decompressor mode and configure the number of decompressors > when mounting a file system. > > "threads=<single|multi|percpu|1|2|3|...>" > The upper limit is num_online_cpus() * 2. > > v6: fix opt->thread_ops unassigned if CONFIG_SQUASHFS_CHOICE_DECOMP_BY_MOUNT is not set. > This version looks good to me. Thanks. Reviewed-by: Phillip Lougher <phillip@squashfs.org.uk> > v5: https://lore.kernel.org/lkml/20220930091406.50869-1-nixiaoming@huawei.com/ > fix a low-level mistake in patching: > fs/squashfs/super.c:492:7: warning: "CONFIG_SQUASHFS_DECOMP_MULTI" is > not defined, evaluates to 0 [-Wundef] > > v4: https://lore.kernel.org/lkml/20220916083604.33408-1-nixiaoming@huawei.com/ > Based on Philip Lougher's suggestion, make the following updates: > 1. Use static modifiers to avoid changing symbol names. > 2. Fixed some formatting issues > > v3: https://lore.kernel.org/lkml/20220902094855.22666-1-nixiaoming@huawei.com/ > Based on Philip Lougher's suggestion, make the following updates: > 1. The default configuration is the same as that before the patch installation. > 2. Compile the three decompression modes when the new configuration is enabled. > 3. "threads=1" supports only the SQUASHFS_DECOMP_SINGLE mode. > > v2: https://lore.kernel.org/lkml/20220816010052.15764-1-nixiaoming@huawei.com/ > fix warning: sparse: incorrect type in initializer (different address spaces) > Reported-by: kernel test robot <lkp@intel.com> > > v1: https://lore.kernel.org/lkml/20220815031100.75243-1-nixiaoming@huawei.com/ > *** BLURB HERE *** > > Xiaoming Ni (2): > squashfs: add the mount parameter theads=<single|multi|percpu> > squashfs: Allows users to configure the number of decompression > threads > > fs/squashfs/Kconfig | 51 +++++++++++-- > fs/squashfs/block.c | 2 +- > fs/squashfs/decompressor.c | 2 +- > fs/squashfs/decompressor_multi.c | 20 +++-- > fs/squashfs/decompressor_multi_percpu.c | 23 ++++-- > fs/squashfs/decompressor_single.c | 15 +++- > fs/squashfs/squashfs.h | 23 ++++-- > fs/squashfs/squashfs_fs_sb.h | 4 +- > fs/squashfs/super.c | 97 ++++++++++++++++++++++++- > 9 files changed, 203 insertions(+), 34 deletions(-) >
Squashfs supports three decompression concurrency modes:
Single-thread mode: concurrent reads are blocked and the memory
overhead is small.
Multi-thread mode/percpu mode: reduces concurrent read blocking but
increases memory overhead.
The corresponding schema must be fixed at compile time. During mounting,
the concurrent decompression mode cannot be adjusted based on file read
blocking.
The mount parameter theads=<single|multi|percpu> is added to select
the concurrent decompression mode of a single SquashFS file system
image.
Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
---
fs/squashfs/Kconfig | 39 ++++++++++++++---
fs/squashfs/block.c | 2 +-
fs/squashfs/decompressor.c | 2 +-
fs/squashfs/decompressor_multi.c | 16 ++++---
fs/squashfs/decompressor_multi_percpu.c | 23 ++++++----
fs/squashfs/decompressor_single.c | 15 +++++--
fs/squashfs/squashfs.h | 23 +++++++---
fs/squashfs/squashfs_fs_sb.h | 3 +-
fs/squashfs/super.c | 56 +++++++++++++++++++++++--
9 files changed, 147 insertions(+), 32 deletions(-)
diff --git a/fs/squashfs/Kconfig b/fs/squashfs/Kconfig
index 916e78fabcaa..218bacdd4298 100644
--- a/fs/squashfs/Kconfig
+++ b/fs/squashfs/Kconfig
@@ -54,9 +54,36 @@ config SQUASHFS_FILE_DIRECT
endchoice
+config SQUASHFS_DECOMP_SINGLE
+ depends on SQUASHFS
+ def_bool n
+
+config SQUASHFS_DECOMP_MULTI
+ depends on SQUASHFS
+ def_bool n
+
+config SQUASHFS_DECOMP_MULTI_PERCPU
+ depends on SQUASHFS
+ def_bool n
+
+config SQUASHFS_CHOICE_DECOMP_BY_MOUNT
+ bool "Select the parallel decompression mode during mount"
+ depends on SQUASHFS
+ default n
+ select SQUASHFS_DECOMP_SINGLE
+ select SQUASHFS_DECOMP_MULTI
+ select SQUASHFS_DECOMP_MULTI_PERCPU
+ help
+ Compile all parallel decompression modes and specify the
+ decompression mode by setting "threads=" during mount.
+ threads=<single|multi|percpu>
+
+ default Decompressor parallelisation is SQUASHFS_DECOMP_SINGLE
+
choice
- prompt "Decompressor parallelisation options"
+ prompt "Select decompression parallel mode at compile time"
depends on SQUASHFS
+ depends on !SQUASHFS_CHOICE_DECOMP_BY_MOUNT
help
Squashfs now supports three parallelisation options for
decompression. Each one exhibits various trade-offs between
@@ -64,15 +91,17 @@ choice
If in doubt, select "Single threaded compression"
-config SQUASHFS_DECOMP_SINGLE
+config SQUASHFS_COMPILE_DECOMP_SINGLE
bool "Single threaded compression"
+ select SQUASHFS_DECOMP_SINGLE
help
Traditionally Squashfs has used single-threaded decompression.
Only one block (data or metadata) can be decompressed at any
one time. This limits CPU and memory usage to a minimum.
-config SQUASHFS_DECOMP_MULTI
+config SQUASHFS_COMPILE_DECOMP_MULTI
bool "Use multiple decompressors for parallel I/O"
+ select SQUASHFS_DECOMP_MULTI
help
By default Squashfs uses a single decompressor but it gives
poor performance on parallel I/O workloads when using multiple CPU
@@ -85,8 +114,9 @@ config SQUASHFS_DECOMP_MULTI
decompressors per core. It dynamically allocates decompressors
on a demand basis.
-config SQUASHFS_DECOMP_MULTI_PERCPU
+config SQUASHFS_COMPILE_DECOMP_MULTI_PERCPU
bool "Use percpu multiple decompressors for parallel I/O"
+ select SQUASHFS_DECOMP_MULTI_PERCPU
help
By default Squashfs uses a single decompressor but it gives
poor performance on parallel I/O workloads when using multiple CPU
@@ -95,7 +125,6 @@ config SQUASHFS_DECOMP_MULTI_PERCPU
This decompressor implementation uses a maximum of one
decompressor per core. It uses percpu variables to ensure
decompression is load-balanced across the cores.
-
endchoice
config SQUASHFS_XATTR
diff --git a/fs/squashfs/block.c b/fs/squashfs/block.c
index 833aca92301f..bed3bb8b27fa 100644
--- a/fs/squashfs/block.c
+++ b/fs/squashfs/block.c
@@ -216,7 +216,7 @@ int squashfs_read_data(struct super_block *sb, u64 index, int length,
res = -EIO;
goto out_free_bio;
}
- res = squashfs_decompress(msblk, bio, offset, length, output);
+ res = msblk->thread_ops->decompress(msblk, bio, offset, length, output);
} else {
res = copy_bio_to_actor(bio, output, offset, length);
}
diff --git a/fs/squashfs/decompressor.c b/fs/squashfs/decompressor.c
index d57bef91ab08..8893cb9b4198 100644
--- a/fs/squashfs/decompressor.c
+++ b/fs/squashfs/decompressor.c
@@ -134,7 +134,7 @@ void *squashfs_decompressor_setup(struct super_block *sb, unsigned short flags)
if (IS_ERR(comp_opts))
return comp_opts;
- stream = squashfs_decompressor_create(msblk, comp_opts);
+ stream = msblk->thread_ops->create(msblk, comp_opts);
if (IS_ERR(stream))
kfree(comp_opts);
diff --git a/fs/squashfs/decompressor_multi.c b/fs/squashfs/decompressor_multi.c
index db9f12a3ea05..eb25432bd149 100644
--- a/fs/squashfs/decompressor_multi.c
+++ b/fs/squashfs/decompressor_multi.c
@@ -29,12 +29,11 @@
#define MAX_DECOMPRESSOR (num_online_cpus() * 2)
-int squashfs_max_decompressors(void)
+static int squashfs_max_decompressors(void)
{
return MAX_DECOMPRESSOR;
}
-
struct squashfs_stream {
void *comp_opts;
struct list_head strm_list;
@@ -59,7 +58,7 @@ static void put_decomp_stream(struct decomp_stream *decomp_strm,
wake_up(&stream->wait);
}
-void *squashfs_decompressor_create(struct squashfs_sb_info *msblk,
+static void *squashfs_decompressor_create(struct squashfs_sb_info *msblk,
void *comp_opts)
{
struct squashfs_stream *stream;
@@ -103,7 +102,7 @@ void *squashfs_decompressor_create(struct squashfs_sb_info *msblk,
}
-void squashfs_decompressor_destroy(struct squashfs_sb_info *msblk)
+static void squashfs_decompressor_destroy(struct squashfs_sb_info *msblk)
{
struct squashfs_stream *stream = msblk->stream;
if (stream) {
@@ -180,7 +179,7 @@ static struct decomp_stream *get_decomp_stream(struct squashfs_sb_info *msblk,
}
-int squashfs_decompress(struct squashfs_sb_info *msblk, struct bio *bio,
+static int squashfs_decompress(struct squashfs_sb_info *msblk, struct bio *bio,
int offset, int length,
struct squashfs_page_actor *output)
{
@@ -195,3 +194,10 @@ int squashfs_decompress(struct squashfs_sb_info *msblk, struct bio *bio,
msblk->decompressor->name);
return res;
}
+
+const struct squashfs_decompressor_thread_ops squashfs_decompressor_multi = {
+ .create = squashfs_decompressor_create,
+ .destroy = squashfs_decompressor_destroy,
+ .decompress = squashfs_decompress,
+ .max_decompressors = squashfs_max_decompressors,
+};
diff --git a/fs/squashfs/decompressor_multi_percpu.c b/fs/squashfs/decompressor_multi_percpu.c
index b881b9283b7f..1dfadf76ed9a 100644
--- a/fs/squashfs/decompressor_multi_percpu.c
+++ b/fs/squashfs/decompressor_multi_percpu.c
@@ -25,7 +25,7 @@ struct squashfs_stream {
local_lock_t lock;
};
-void *squashfs_decompressor_create(struct squashfs_sb_info *msblk,
+static void *squashfs_decompressor_create(struct squashfs_sb_info *msblk,
void *comp_opts)
{
struct squashfs_stream *stream;
@@ -59,7 +59,7 @@ void *squashfs_decompressor_create(struct squashfs_sb_info *msblk,
return ERR_PTR(err);
}
-void squashfs_decompressor_destroy(struct squashfs_sb_info *msblk)
+static void squashfs_decompressor_destroy(struct squashfs_sb_info *msblk)
{
struct squashfs_stream __percpu *percpu =
(struct squashfs_stream __percpu *) msblk->stream;
@@ -75,19 +75,21 @@ void squashfs_decompressor_destroy(struct squashfs_sb_info *msblk)
}
}
-int squashfs_decompress(struct squashfs_sb_info *msblk, struct bio *bio,
+static int squashfs_decompress(struct squashfs_sb_info *msblk, struct bio *bio,
int offset, int length, struct squashfs_page_actor *output)
{
struct squashfs_stream *stream;
+ struct squashfs_stream __percpu *percpu =
+ (struct squashfs_stream __percpu *) msblk->stream;
int res;
- local_lock(&msblk->stream->lock);
- stream = this_cpu_ptr(msblk->stream);
+ local_lock(&percpu->lock);
+ stream = this_cpu_ptr(percpu);
res = msblk->decompressor->decompress(msblk, stream->stream, bio,
offset, length, output);
- local_unlock(&msblk->stream->lock);
+ local_unlock(&percpu->lock);
if (res < 0)
ERROR("%s decompression failed, data probably corrupt\n",
@@ -96,7 +98,14 @@ int squashfs_decompress(struct squashfs_sb_info *msblk, struct bio *bio,
return res;
}
-int squashfs_max_decompressors(void)
+static int squashfs_max_decompressors(void)
{
return num_possible_cpus();
}
+
+const struct squashfs_decompressor_thread_ops squashfs_decompressor_percpu = {
+ .create = squashfs_decompressor_create,
+ .destroy = squashfs_decompressor_destroy,
+ .decompress = squashfs_decompress,
+ .max_decompressors = squashfs_max_decompressors,
+};
diff --git a/fs/squashfs/decompressor_single.c b/fs/squashfs/decompressor_single.c
index 4eb3d083d45e..6f161887710b 100644
--- a/fs/squashfs/decompressor_single.c
+++ b/fs/squashfs/decompressor_single.c
@@ -24,7 +24,7 @@ struct squashfs_stream {
struct mutex mutex;
};
-void *squashfs_decompressor_create(struct squashfs_sb_info *msblk,
+static void *squashfs_decompressor_create(struct squashfs_sb_info *msblk,
void *comp_opts)
{
struct squashfs_stream *stream;
@@ -49,7 +49,7 @@ void *squashfs_decompressor_create(struct squashfs_sb_info *msblk,
return ERR_PTR(err);
}
-void squashfs_decompressor_destroy(struct squashfs_sb_info *msblk)
+static void squashfs_decompressor_destroy(struct squashfs_sb_info *msblk)
{
struct squashfs_stream *stream = msblk->stream;
@@ -59,7 +59,7 @@ void squashfs_decompressor_destroy(struct squashfs_sb_info *msblk)
}
}
-int squashfs_decompress(struct squashfs_sb_info *msblk, struct bio *bio,
+static int squashfs_decompress(struct squashfs_sb_info *msblk, struct bio *bio,
int offset, int length,
struct squashfs_page_actor *output)
{
@@ -78,7 +78,14 @@ int squashfs_decompress(struct squashfs_sb_info *msblk, struct bio *bio,
return res;
}
-int squashfs_max_decompressors(void)
+static int squashfs_max_decompressors(void)
{
return 1;
}
+
+const struct squashfs_decompressor_thread_ops squashfs_decompressor_single = {
+ .create = squashfs_decompressor_create,
+ .destroy = squashfs_decompressor_destroy,
+ .decompress = squashfs_decompress,
+ .max_decompressors = squashfs_max_decompressors,
+};
diff --git a/fs/squashfs/squashfs.h b/fs/squashfs/squashfs.h
index 9783e01c8100..a6164fdf9435 100644
--- a/fs/squashfs/squashfs.h
+++ b/fs/squashfs/squashfs.h
@@ -38,11 +38,24 @@ extern const struct squashfs_decompressor *squashfs_lookup_decompressor(int);
extern void *squashfs_decompressor_setup(struct super_block *, unsigned short);
/* decompressor_xxx.c */
-extern void *squashfs_decompressor_create(struct squashfs_sb_info *, void *);
-extern void squashfs_decompressor_destroy(struct squashfs_sb_info *);
-extern int squashfs_decompress(struct squashfs_sb_info *, struct bio *,
- int, int, struct squashfs_page_actor *);
-extern int squashfs_max_decompressors(void);
+
+struct squashfs_decompressor_thread_ops {
+ void * (*create)(struct squashfs_sb_info *msblk, void *comp_opts);
+ void (*destroy)(struct squashfs_sb_info *msblk);
+ int (*decompress)(struct squashfs_sb_info *msblk, struct bio *bio,
+ int offset, int length, struct squashfs_page_actor *output);
+ int (*max_decompressors)(void);
+};
+
+#ifdef CONFIG_SQUASHFS_DECOMP_SINGLE
+extern const struct squashfs_decompressor_thread_ops squashfs_decompressor_single;
+#endif
+#ifdef CONFIG_SQUASHFS_DECOMP_MULTI
+extern const struct squashfs_decompressor_thread_ops squashfs_decompressor_multi;
+#endif
+#ifdef CONFIG_SQUASHFS_DECOMP_MULTI_PERCPU
+extern const struct squashfs_decompressor_thread_ops squashfs_decompressor_percpu;
+#endif
/* export.c */
extern __le64 *squashfs_read_inode_lookup_table(struct super_block *, u64, u64,
diff --git a/fs/squashfs/squashfs_fs_sb.h b/fs/squashfs/squashfs_fs_sb.h
index 1e90c2575f9b..f1e5dad8ae0a 100644
--- a/fs/squashfs/squashfs_fs_sb.h
+++ b/fs/squashfs/squashfs_fs_sb.h
@@ -53,7 +53,7 @@ struct squashfs_sb_info {
__le64 *xattr_id_table;
struct mutex meta_index_mutex;
struct meta_index *meta_index;
- struct squashfs_stream *stream;
+ void *stream;
__le64 *inode_lookup_table;
u64 inode_table;
u64 directory_table;
@@ -66,5 +66,6 @@ struct squashfs_sb_info {
int xattr_ids;
unsigned int ids;
bool panic_on_errors;
+ const struct squashfs_decompressor_thread_ops *thread_ops;
};
#endif
diff --git a/fs/squashfs/super.c b/fs/squashfs/super.c
index 32565dafa7f3..aac3ea72a9ba 100644
--- a/fs/squashfs/super.c
+++ b/fs/squashfs/super.c
@@ -47,10 +47,12 @@ enum Opt_errors {
enum squashfs_param {
Opt_errors,
+ Opt_threads,
};
struct squashfs_mount_opts {
enum Opt_errors errors;
+ const struct squashfs_decompressor_thread_ops *thread_ops;
};
static const struct constant_table squashfs_param_errors[] = {
@@ -61,9 +63,29 @@ static const struct constant_table squashfs_param_errors[] = {
static const struct fs_parameter_spec squashfs_fs_parameters[] = {
fsparam_enum("errors", Opt_errors, squashfs_param_errors),
+ fsparam_string("threads", Opt_threads),
{}
};
+static int squashfs_parse_param_threads(const char *str, struct squashfs_mount_opts *opts)
+{
+#ifdef CONFIG_SQUASHFS_CHOICE_DECOMP_BY_MOUNT
+ if (strcmp(str, "single") == 0) {
+ opts->thread_ops = &squashfs_decompressor_single;
+ return 0;
+ }
+ if (strcmp(str, "multi") == 0) {
+ opts->thread_ops = &squashfs_decompressor_multi;
+ return 0;
+ }
+ if (strcmp(str, "percpu") == 0) {
+ opts->thread_ops = &squashfs_decompressor_percpu;
+ return 0;
+ }
+#endif
+ return -EINVAL;
+}
+
static int squashfs_parse_param(struct fs_context *fc, struct fs_parameter *param)
{
struct squashfs_mount_opts *opts = fc->fs_private;
@@ -78,6 +100,10 @@ static int squashfs_parse_param(struct fs_context *fc, struct fs_parameter *para
case Opt_errors:
opts->errors = result.uint_32;
break;
+ case Opt_threads:
+ if (squashfs_parse_param_threads(param->string, opts) != 0)
+ return -EINVAL;
+ break;
default:
return -EINVAL;
}
@@ -167,6 +193,7 @@ static int squashfs_fill_super(struct super_block *sb, struct fs_context *fc)
sb->s_bdev);
goto failed_mount;
}
+ msblk->thread_ops = opts->thread_ops;
/* Check the MAJOR & MINOR versions and lookup compression type */
msblk->decompressor = supported_squashfs_filesystem(
@@ -252,7 +279,7 @@ static int squashfs_fill_super(struct super_block *sb, struct fs_context *fc)
/* Allocate read_page block */
msblk->read_page = squashfs_cache_init("data",
- squashfs_max_decompressors(), msblk->block_size);
+ msblk->thread_ops->max_decompressors(), msblk->block_size);
if (msblk->read_page == NULL) {
errorf(fc, "Failed to allocate read_page block");
goto failed_mount;
@@ -383,7 +410,7 @@ static int squashfs_fill_super(struct super_block *sb, struct fs_context *fc)
squashfs_cache_delete(msblk->block_cache);
squashfs_cache_delete(msblk->fragment_cache);
squashfs_cache_delete(msblk->read_page);
- squashfs_decompressor_destroy(msblk);
+ msblk->thread_ops->destroy(msblk);
kfree(msblk->inode_lookup_table);
kfree(msblk->fragment_index);
kfree(msblk->id_table);
@@ -435,6 +462,20 @@ static int squashfs_show_options(struct seq_file *s, struct dentry *root)
else
seq_puts(s, ",errors=continue");
+#ifdef CONFIG_SQUASHFS_CHOICE_DECOMP_BY_MOUNT
+ if (msblk->thread_ops == &squashfs_decompressor_single) {
+ seq_puts(s, ",threads=single");
+ return 0;
+ }
+ if (msblk->thread_ops == &squashfs_decompressor_multi) {
+ seq_puts(s, ",threads=multi");
+ return 0;
+ }
+ if (msblk->thread_ops == &squashfs_decompressor_percpu) {
+ seq_puts(s, ",threads=percpu");
+ return 0;
+ }
+#endif
return 0;
}
@@ -446,6 +487,15 @@ static int squashfs_init_fs_context(struct fs_context *fc)
if (!opts)
return -ENOMEM;
+#ifdef CONFIG_SQUASHFS_DECOMP_SINGLE
+ opts->thread_ops = &squashfs_decompressor_single;
+#elif defined(CONFIG_SQUASHFS_DECOMP_MULTI)
+ opts->thread_ops = &squashfs_decompressor_multi;
+#elif defined(CONFIG_SQUASHFS_DECOMP_MULTI_PERCPU)
+ opts->thread_ops = &squashfs_decompressor_percpu;
+#else
+#error "fail: unknown squashfs decompression thread mode?"
+#endif
fc->fs_private = opts;
fc->ops = &squashfs_context_ops;
return 0;
@@ -478,7 +528,7 @@ static void squashfs_put_super(struct super_block *sb)
squashfs_cache_delete(sbi->block_cache);
squashfs_cache_delete(sbi->fragment_cache);
squashfs_cache_delete(sbi->read_page);
- squashfs_decompressor_destroy(sbi);
+ sbi->thread_ops->destroy(sbi);
kfree(sbi->id_table);
kfree(sbi->fragment_index);
kfree(sbi->meta_index);
--
2.27.0
The maximum number of threads in the decompressor_multi.c file is fixed
and cannot be adjusted according to user needs.
Therefore, the mount parameter needs to be added to allow users to
configure the number of threads as required. The upper limit is
num_online_cpus() * 2.
Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
---
fs/squashfs/Kconfig | 16 ++++++++--
fs/squashfs/decompressor_multi.c | 4 +--
fs/squashfs/squashfs_fs_sb.h | 1 +
fs/squashfs/super.c | 55 ++++++++++++++++++++++++++++----
4 files changed, 66 insertions(+), 10 deletions(-)
diff --git a/fs/squashfs/Kconfig b/fs/squashfs/Kconfig
index 218bacdd4298..60fc98bdf421 100644
--- a/fs/squashfs/Kconfig
+++ b/fs/squashfs/Kconfig
@@ -73,11 +73,10 @@ config SQUASHFS_CHOICE_DECOMP_BY_MOUNT
select SQUASHFS_DECOMP_SINGLE
select SQUASHFS_DECOMP_MULTI
select SQUASHFS_DECOMP_MULTI_PERCPU
+ select SQUASHFS_MOUNT_DECOMP_THREADS
help
Compile all parallel decompression modes and specify the
decompression mode by setting "threads=" during mount.
- threads=<single|multi|percpu>
-
default Decompressor parallelisation is SQUASHFS_DECOMP_SINGLE
choice
@@ -127,6 +126,19 @@ config SQUASHFS_COMPILE_DECOMP_MULTI_PERCPU
decompression is load-balanced across the cores.
endchoice
+config SQUASHFS_MOUNT_DECOMP_THREADS
+ bool "Add the mount parameter 'threads=' for squashfs"
+ depends on SQUASHFS
+ depends on SQUASHFS_DECOMP_MULTI
+ default n
+ help
+ Use threads= to set the decompression parallel mode and the number of threads.
+ If SQUASHFS_CHOICE_DECOMP_BY_MOUNT=y
+ threads=<single|multi|percpu|1|2|3|...>
+ else
+ threads=<2|3|...>
+ The upper limit is num_online_cpus() * 2.
+
config SQUASHFS_XATTR
bool "Squashfs XATTR support"
depends on SQUASHFS
diff --git a/fs/squashfs/decompressor_multi.c b/fs/squashfs/decompressor_multi.c
index eb25432bd149..416c53eedbd1 100644
--- a/fs/squashfs/decompressor_multi.c
+++ b/fs/squashfs/decompressor_multi.c
@@ -144,7 +144,7 @@ static struct decomp_stream *get_decomp_stream(struct squashfs_sb_info *msblk,
* If there is no available decomp and already full,
* let's wait for releasing decomp from other users.
*/
- if (stream->avail_decomp >= MAX_DECOMPRESSOR)
+ if (stream->avail_decomp >= msblk->max_thread_num)
goto wait;
/* Let's allocate new decomp */
@@ -160,7 +160,7 @@ static struct decomp_stream *get_decomp_stream(struct squashfs_sb_info *msblk,
}
stream->avail_decomp++;
- WARN_ON(stream->avail_decomp > MAX_DECOMPRESSOR);
+ WARN_ON(stream->avail_decomp > msblk->max_thread_num);
mutex_unlock(&stream->mutex);
break;
diff --git a/fs/squashfs/squashfs_fs_sb.h b/fs/squashfs/squashfs_fs_sb.h
index f1e5dad8ae0a..659082e9e51d 100644
--- a/fs/squashfs/squashfs_fs_sb.h
+++ b/fs/squashfs/squashfs_fs_sb.h
@@ -67,5 +67,6 @@ struct squashfs_sb_info {
unsigned int ids;
bool panic_on_errors;
const struct squashfs_decompressor_thread_ops *thread_ops;
+ int max_thread_num;
};
#endif
diff --git a/fs/squashfs/super.c b/fs/squashfs/super.c
index aac3ea72a9ba..1e428ca9414e 100644
--- a/fs/squashfs/super.c
+++ b/fs/squashfs/super.c
@@ -53,6 +53,7 @@ enum squashfs_param {
struct squashfs_mount_opts {
enum Opt_errors errors;
const struct squashfs_decompressor_thread_ops *thread_ops;
+ int thread_num;
};
static const struct constant_table squashfs_param_errors[] = {
@@ -67,7 +68,8 @@ static const struct fs_parameter_spec squashfs_fs_parameters[] = {
{}
};
-static int squashfs_parse_param_threads(const char *str, struct squashfs_mount_opts *opts)
+
+static int squashfs_parse_param_threads_str(const char *str, struct squashfs_mount_opts *opts)
{
#ifdef CONFIG_SQUASHFS_CHOICE_DECOMP_BY_MOUNT
if (strcmp(str, "single") == 0) {
@@ -86,6 +88,42 @@ static int squashfs_parse_param_threads(const char *str, struct squashfs_mount_o
return -EINVAL;
}
+static int squashfs_parse_param_threads_num(const char *str, struct squashfs_mount_opts *opts)
+{
+#ifdef CONFIG_SQUASHFS_MOUNT_DECOMP_THREADS
+ int ret;
+ unsigned long num;
+
+ ret = kstrtoul(str, 0, &num);
+ if (ret != 0)
+ return -EINVAL;
+ if (num > 1) {
+ opts->thread_ops = &squashfs_decompressor_multi;
+ if (num > opts->thread_ops->max_decompressors())
+ return -EINVAL;
+ opts->thread_num = (int)num;
+ return 0;
+ }
+#ifdef CONFIG_SQUASHFS_DECOMP_SINGLE
+ if (num == 1) {
+ opts->thread_ops = &squashfs_decompressor_single;
+ opts->thread_num = 1;
+ return 0;
+ }
+#endif
+#endif /* !CONFIG_SQUASHFS_MOUNT_DECOMP_THREADS */
+ return -EINVAL;
+}
+
+static int squashfs_parse_param_threads(const char *str, struct squashfs_mount_opts *opts)
+{
+ int ret = squashfs_parse_param_threads_str(str, opts);
+
+ if (ret == 0)
+ return ret;
+ return squashfs_parse_param_threads_num(str, opts);
+}
+
static int squashfs_parse_param(struct fs_context *fc, struct fs_parameter *param)
{
struct squashfs_mount_opts *opts = fc->fs_private;
@@ -194,6 +232,11 @@ static int squashfs_fill_super(struct super_block *sb, struct fs_context *fc)
goto failed_mount;
}
msblk->thread_ops = opts->thread_ops;
+ if (opts->thread_num == 0) {
+ msblk->max_thread_num = msblk->thread_ops->max_decompressors();
+ } else {
+ msblk->max_thread_num = opts->thread_num;
+ }
/* Check the MAJOR & MINOR versions and lookup compression type */
msblk->decompressor = supported_squashfs_filesystem(
@@ -279,7 +322,7 @@ static int squashfs_fill_super(struct super_block *sb, struct fs_context *fc)
/* Allocate read_page block */
msblk->read_page = squashfs_cache_init("data",
- msblk->thread_ops->max_decompressors(), msblk->block_size);
+ msblk->max_thread_num, msblk->block_size);
if (msblk->read_page == NULL) {
errorf(fc, "Failed to allocate read_page block");
goto failed_mount;
@@ -467,14 +510,13 @@ static int squashfs_show_options(struct seq_file *s, struct dentry *root)
seq_puts(s, ",threads=single");
return 0;
}
- if (msblk->thread_ops == &squashfs_decompressor_multi) {
- seq_puts(s, ",threads=multi");
- return 0;
- }
if (msblk->thread_ops == &squashfs_decompressor_percpu) {
seq_puts(s, ",threads=percpu");
return 0;
}
+#endif
+#ifdef CONFIG_SQUASHFS_MOUNT_DECOMP_THREADS
+ seq_printf(s, ",threads=%d", msblk->max_thread_num);
#endif
return 0;
}
@@ -496,6 +538,7 @@ static int squashfs_init_fs_context(struct fs_context *fc)
#else
#error "fail: unknown squashfs decompression thread mode?"
#endif
+ opts->thread_num = 0;
fc->fs_private = opts;
fc->ops = &squashfs_context_ops;
return 0;
--
2.27.0
ping On 2022/9/30 17:14, Xiaoming Ni wrote: > Currently, Squashfs supports multiple decompressor parallel modes. However, this > mode can be configured only during kernel building and does not support flexible > selection during runtime. > > In the current patch set, the mount parameter "threads=" is added to allow users > to select the parallel decompressor mode and configure the number of decompressors > when mounting a file system. > > "threads=<single|multi|percpu|1|2|3|...>" > The upper limit is num_online_cpus() * 2. > > v5: fix a low-level mistake in patching: > fs/squashfs/super.c:492:7: warning: "CONFIG_SQUASHFS_DECOMP_MULTI" is > not defined, evaluates to 0 [-Wundef] > > v4: https://lore.kernel.org/lkml/20220916083604.33408-1-nixiaoming@huawei.com/ > Based on Philip Lougher's suggestion, make the following updates: > 1. Use static modifiers to avoid changing symbol names. > 2. Fixed some formatting issues > > v3: https://lore.kernel.org/lkml/20220902094855.22666-1-nixiaoming@huawei.com/ > Based on Philip Lougher's suggestion, make the following updates: > 1. The default configuration is the same as that before the patch installation. > 2. Compile the three decompression modes when the new configuration is enabled. > 3. "threads=1" supports only the SQUASHFS_DECOMP_SINGLE mode. > > v2: https://lore.kernel.org/lkml/20220816010052.15764-1-nixiaoming@huawei.com/ > fix warning: sparse: incorrect type in initializer (different address spaces) > Reported-by: kernel test robot <lkp@intel.com> > > v1: https://lore.kernel.org/lkml/20220815031100.75243-1-nixiaoming@huawei.com/ > > Xiaoming Ni (2): > squashfs: add the mount parameter theads=<single|multi|percpu> > squashfs: Allows users to configure the number of decompression > threads > > fs/squashfs/Kconfig | 51 ++++++++++++++++-- > fs/squashfs/block.c | 2 +- > fs/squashfs/decompressor.c | 2 +- > fs/squashfs/decompressor_multi.c | 20 ++++--- > fs/squashfs/decompressor_multi_percpu.c | 23 +++++--- > fs/squashfs/decompressor_single.c | 15 ++++-- > fs/squashfs/squashfs.h | 23 ++++++-- > fs/squashfs/squashfs_fs_sb.h | 4 +- > fs/squashfs/super.c | 93 +++++++++++++++++++++++++++++++-- > 9 files changed, 199 insertions(+), 34 deletions(-) >
On Mon, Oct 17, 2022 at 2:11 AM Xiaoming Ni <nixiaoming@huawei.com> wrote: > > ping I was hoping you'd notice the obvious mistake you made in the patch set, and send an updated version, which would avoid me having to point out such mistakes again. I have replied to patch [1/2] Phillip > > On 2022/9/30 17:14, Xiaoming Ni wrote: > > Currently, Squashfs supports multiple decompressor parallel modes. However, this > > mode can be configured only during kernel building and does not support flexible > > selection during runtime. > > > > In the current patch set, the mount parameter "threads=" is added to allow users > > to select the parallel decompressor mode and configure the number of decompressors > > when mounting a file system. > > > > "threads=<single|multi|percpu|1|2|3|...>" > > The upper limit is num_online_cpus() * 2. > > > > v5: fix a low-level mistake in patching: > > fs/squashfs/super.c:492:7: warning: "CONFIG_SQUASHFS_DECOMP_MULTI" is > > not defined, evaluates to 0 [-Wundef] > > > > v4: https://lore.kernel.org/lkml/20220916083604.33408-1-nixiaoming@huawei.com/ > > Based on Philip Lougher's suggestion, make the following updates: > > 1. Use static modifiers to avoid changing symbol names. > > 2. Fixed some formatting issues > > > > v3: https://lore.kernel.org/lkml/20220902094855.22666-1-nixiaoming@huawei.com/ > > Based on Philip Lougher's suggestion, make the following updates: > > 1. The default configuration is the same as that before the patch installation. > > 2. Compile the three decompression modes when the new configuration is enabled. > > 3. "threads=1" supports only the SQUASHFS_DECOMP_SINGLE mode. > > > > v2: https://lore.kernel.org/lkml/20220816010052.15764-1-nixiaoming@huawei.com/ > > fix warning: sparse: incorrect type in initializer (different address spaces) > > Reported-by: kernel test robot <lkp@intel.com> > > > > v1: https://lore.kernel.org/lkml/20220815031100.75243-1-nixiaoming@huawei.com/ > > > > Xiaoming Ni (2): > > squashfs: add the mount parameter theads=<single|multi|percpu> > > squashfs: Allows users to configure the number of decompression > > threads > > > > fs/squashfs/Kconfig | 51 ++++++++++++++++-- > > fs/squashfs/block.c | 2 +- > > fs/squashfs/decompressor.c | 2 +- > > fs/squashfs/decompressor_multi.c | 20 ++++--- > > fs/squashfs/decompressor_multi_percpu.c | 23 +++++--- > > fs/squashfs/decompressor_single.c | 15 ++++-- > > fs/squashfs/squashfs.h | 23 ++++++-- > > fs/squashfs/squashfs_fs_sb.h | 4 +- > > fs/squashfs/super.c | 93 +++++++++++++++++++++++++++++++-- > > 9 files changed, 199 insertions(+), 34 deletions(-) > > >
On 2022/10/18 6:59, Phillip Lougher wrote: > On Mon, Oct 17, 2022 at 2:11 AM Xiaoming Ni <nixiaoming@huawei.com> wrote: >> >> ping > > I was hoping you'd notice the obvious mistake you made in the patch set, > and send an updated version, which would avoid me having to point out > such mistakes again. > > I have replied to patch [1/2] > > Phillip > I'm so sorry. I'm very ashamed of my serial mistakes. I'll fix it again later and resend it, I'm sorry I need to take up your valuable time to help review it again. Thanks Xiaoming Ni
© 2016 - 2026 Red Hat, Inc.