From nobody Mon Apr 13 13:10:47 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E4EAC25B0D for ; Tue, 16 Aug 2022 04:24:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229580AbiHPEYN (ORCPT ); Tue, 16 Aug 2022 00:24:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229731AbiHPEX6 (ORCPT ); Tue, 16 Aug 2022 00:23:58 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E026637D97B for ; Mon, 15 Aug 2022 18:00:57 -0700 (PDT) Received: from canpemm500006.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4M6CRh4cQfz1M8N7; Tue, 16 Aug 2022 08:57:36 +0800 (CST) Received: from use12-sp2.huawei.com (10.67.189.174) by canpemm500006.china.huawei.com (7.192.105.130) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 16 Aug 2022 09:00:55 +0800 From: Xiaoming Ni To: , CC: , , , , , Subject: [PATCH v2 2/2] squashfs: Allows users to configure the number of decompression threads. Date: Tue, 16 Aug 2022 09:00:52 +0800 Message-ID: <20220816010052.15764-3-nixiaoming@huawei.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220816010052.15764-1-nixiaoming@huawei.com> References: <20220815031100.75243-1-nixiaoming@huawei.com> <20220816010052.15764-1-nixiaoming@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.67.189.174] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To canpemm500006.china.huawei.com (7.192.105.130) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Xiaoming Ni --- fs/squashfs/Kconfig | 4 +++- fs/squashfs/decompressor_multi.c | 4 ++-- fs/squashfs/squashfs_fs_sb.h | 1 + fs/squashfs/super.c | 45 ++++++++++++++++++++++++++++--------= ---- 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/fs/squashfs/Kconfig b/fs/squashfs/Kconfig index af9f8c41f2de..3f42b4099dc7 100644 --- a/fs/squashfs/Kconfig +++ b/fs/squashfs/Kconfig @@ -99,7 +99,9 @@ config SQUASHFS_DECOMP_MULTI =20 This decompressor implementation uses up to two parallel decompressors per core. It dynamically allocates decompressors - on a demand basis. + on a demand basis. You can also set the number of threads by setting t= hreads=3D of + the mount parameter. + =20 config SQUASHFS_DECOMP_MULTI_PERCPU bool "Use percpu multiple decompressors for parallel I/O" diff --git a/fs/squashfs/decompressor_multi.c b/fs/squashfs/decompressor_mu= lti.c index 7b2723b77e75..6d1cea325cca 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 s= quashfs_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 >=3D MAX_DECOMPRESSOR) + if (stream->avail_decomp >=3D msblk->max_thread_num) goto wait; =20 /* Let's allocate new decomp */ @@ -160,7 +160,7 @@ static struct decomp_stream *get_decomp_stream(struct s= quashfs_sb_info *msblk, } =20 stream->avail_decomp++; - WARN_ON(stream->avail_decomp > MAX_DECOMPRESSOR); + WARN_ON(stream->avail_decomp > msblk->max_thread_num); =20 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 6fd44683a84b..f3533e20d0b7 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; }; =20 static const struct constant_table squashfs_param_errors[] =3D { @@ -69,6 +70,8 @@ static const struct fs_parameter_spec squashfs_fs_paramet= ers[] =3D { =20 static int squashfs_parse_param_threads(const char *str, struct squashfs_m= ount_opts *opts) { + unsigned long num; + int ret; #ifdef CONFIG_SQUASHFS_DECOMP_SINGLE if (strcmp(str, "single") =3D=3D 0) { opts->thread_ops =3D &squashfs_decompressor_single; @@ -87,7 +90,24 @@ static int squashfs_parse_param_threads(const char *str,= struct squashfs_mount_o return 0; } #endif + ret =3D kstrtoul(str, 0, &num); + if (ret !=3D 0 || num =3D=3D 0) + return -EINVAL; +#ifdef CONFIG_SQUASHFS_DECOMP_SINGLE + if (num =3D=3D 1) { + opts->thread_ops =3D &squashfs_decompressor_single; + return 0; + } +#endif +#ifdef CONFIG_SQUASHFS_DECOMP_MULTI + opts->thread_ops =3D &squashfs_decompressor_multi; + if (num > opts->thread_ops->max_decompressors()) + num =3D opts->thread_ops->max_decompressors(); + opts->thread_num =3D (int)num; + return 0; +#else return -EINVAL; +#endif } =20 static int squashfs_parse_param(struct fs_context *fc, struct fs_parameter= *param) @@ -198,6 +218,11 @@ static int squashfs_fill_super(struct super_block *sb,= struct fs_context *fc) goto failed_mount; } msblk->thread_ops =3D opts->thread_ops; + if (opts->thread_num =3D=3D 0) { + msblk->max_thread_num =3D opts->thread_ops->max_decompressors(); + } else { + msblk->max_thread_num =3D opts->thread_num; + } =20 /* Check the MAJOR & MINOR versions and lookup compression type */ msblk->decompressor =3D supported_squashfs_filesystem( @@ -283,7 +308,7 @@ static int squashfs_fill_super(struct super_block *sb, = struct fs_context *fc) =20 /* Allocate read_page block */ msblk->read_page =3D squashfs_cache_init("data", - msblk->thread_ops->max_decompressors(), msblk->block_size); + msblk->max_thread_num, msblk->block_size); if (msblk->read_page =3D=3D NULL) { errorf(fc, "Failed to allocate read_page block"); goto failed_mount; @@ -466,24 +491,17 @@ static int squashfs_show_options(struct seq_file *s, = struct dentry *root) else seq_puts(s, ",errors=3Dcontinue"); =20 -#ifdef CONFIG_SQUASHFS_DECOMP_SINGLE - if (msblk->thread_ops =3D=3D &squashfs_decompressor_single) { - seq_puts(s, ",threads=3Dsingle"); - return 0; - } -#endif -#ifdef CONFIG_SQUASHFS_DECOMP_MULTI - if (msblk->thread_ops =3D=3D &squashfs_decompressor_multi) { - seq_puts(s, ",threads=3Dmulti"); - return 0; - } -#endif #ifdef CONFIG_SQUASHFS_DECOMP_MULTI_PERCPU + /* + * thread=3Dpercpu and thread=3D have different configuration eff= ects. + * the parameters need to be treated differently when they are displayed. + */ if (msblk->thread_ops =3D=3D &squashfs_decompressor_percpu) { seq_puts(s, ",threads=3Dpercpu"); return 0; } #endif + seq_printf(s, ",threads=3D%u", msblk->max_thread_num); return 0; } =20 @@ -502,6 +520,7 @@ static int squashfs_init_fs_context(struct fs_context *= fc) #elif defined(CONFIG_SQUASHFS_DECOMP_DEFAULT_PERCPU) opts->thread_ops =3D &squashfs_decompressor_percpu; #endif + opts->thread_num =3D 0; fc->fs_private =3D opts; fc->ops =3D &squashfs_context_ops; return 0; --=20 2.12.3