linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] PM: hibernate: make compression threads configurable via kernel parameter
@ 2025-08-26  9:19 Xueqin Luo
  2025-08-26 11:43 ` Rafael J. Wysocki
  0 siblings, 1 reply; 3+ messages in thread
From: Xueqin Luo @ 2025-08-26  9:19 UTC (permalink / raw)
  To: rafael, pavel, lenb, linux-pm, linux-kernel; +Cc: Xueqin Luo

A new kernel parameter 'cmp_threads=' is introduced to
allow tuning the number of compression/decompression threads at boot.

Signed-off-by: Xueqin Luo <luoxueqin@kylinos.cn>
---
 kernel/power/swap.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index ad13c461b657..43280e08a4ad 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -520,7 +520,8 @@ static int swap_writer_finish(struct swap_map_handle *handle,
 #define CMP_SIZE	(CMP_PAGES * PAGE_SIZE)
 
 /* Maximum number of threads for compression/decompression. */
-#define CMP_THREADS	3
+#define CMP_MAX_THREADS	12
+static int cmp_threads = 3
 
 /* Minimum/maximum number of pages for read buffering. */
 #define CMP_MIN_RD_PAGES	1024
@@ -585,8 +586,8 @@ struct crc_data {
 	wait_queue_head_t go;                     /* start crc update */
 	wait_queue_head_t done;                   /* crc update done */
 	u32 *crc32;                               /* points to handle's crc32 */
-	size_t *unc_len[CMP_THREADS];             /* uncompressed lengths */
-	unsigned char *unc[CMP_THREADS];          /* uncompressed data */
+	size_t *unc_len[CMP_MAX_THREADS];             /* uncompressed lengths */
+	unsigned char *unc[CMP_MAX_THREADS];          /* uncompressed data */
 };
 
 /*
@@ -703,7 +704,7 @@ static int save_compressed_image(struct swap_map_handle *handle,
 	 * footprint.
 	 */
 	nr_threads = num_online_cpus() - 1;
-	nr_threads = clamp_val(nr_threads, 1, CMP_THREADS);
+	nr_threads = clamp_val(nr_threads, 1, cmp_threads);
 
 	page = (void *)__get_free_page(GFP_NOIO | __GFP_HIGH);
 	if (!page) {
@@ -1223,7 +1224,7 @@ static int load_compressed_image(struct swap_map_handle *handle,
 	 * footprint.
 	 */
 	nr_threads = num_online_cpus() - 1;
-	nr_threads = clamp_val(nr_threads, 1, CMP_THREADS);
+	nr_threads = clamp_val(nr_threads, 1, cmp_threads);
 
 	page = vmalloc(array_size(CMP_MAX_RD_PAGES, sizeof(*page)));
 	if (!page) {
@@ -1667,3 +1668,14 @@ static int __init swsusp_header_init(void)
 }
 
 core_initcall(swsusp_header_init);
+
+static int __init cmp_threads_setup(char *str)
+{
+       int rc = kstrtouint(str, 0, &cmp_threads);
+       if (rc)
+               return rc;
+       return 1;
+
+}
+
+__setup("cmp_threads=", cmp_threads_setup);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] PM: hibernate: make compression threads configurable via kernel parameter
  2025-08-26  9:19 [PATCH] PM: hibernate: make compression threads configurable via kernel parameter Xueqin Luo
@ 2025-08-26 11:43 ` Rafael J. Wysocki
  2025-08-28  3:29   ` luoxueqin
  0 siblings, 1 reply; 3+ messages in thread
From: Rafael J. Wysocki @ 2025-08-26 11:43 UTC (permalink / raw)
  To: Xueqin Luo; +Cc: rafael, pavel, lenb, linux-pm, linux-kernel

On Tue, Aug 26, 2025 at 11:19 AM Xueqin Luo <luoxueqin@kylinos.cn> wrote:
>
> A new kernel parameter 'cmp_threads=' is introduced to
> allow tuning the number of compression/decompression threads at boot.

And why is it useful/needed?

> Signed-off-by: Xueqin Luo <luoxueqin@kylinos.cn>
> ---
>  kernel/power/swap.c | 22 +++++++++++++++++-----
>  1 file changed, 17 insertions(+), 5 deletions(-)
>
> diff --git a/kernel/power/swap.c b/kernel/power/swap.c
> index ad13c461b657..43280e08a4ad 100644
> --- a/kernel/power/swap.c
> +++ b/kernel/power/swap.c
> @@ -520,7 +520,8 @@ static int swap_writer_finish(struct swap_map_handle *handle,
>  #define CMP_SIZE       (CMP_PAGES * PAGE_SIZE)
>
>  /* Maximum number of threads for compression/decompression. */
> -#define CMP_THREADS    3
> +#define CMP_MAX_THREADS        12
> +static int cmp_threads = 3
>
>  /* Minimum/maximum number of pages for read buffering. */
>  #define CMP_MIN_RD_PAGES       1024
> @@ -585,8 +586,8 @@ struct crc_data {
>         wait_queue_head_t go;                     /* start crc update */
>         wait_queue_head_t done;                   /* crc update done */
>         u32 *crc32;                               /* points to handle's crc32 */
> -       size_t *unc_len[CMP_THREADS];             /* uncompressed lengths */
> -       unsigned char *unc[CMP_THREADS];          /* uncompressed data */
> +       size_t *unc_len[CMP_MAX_THREADS];             /* uncompressed lengths */
> +       unsigned char *unc[CMP_MAX_THREADS];          /* uncompressed data */
>  };
>
>  /*
> @@ -703,7 +704,7 @@ static int save_compressed_image(struct swap_map_handle *handle,
>          * footprint.
>          */
>         nr_threads = num_online_cpus() - 1;
> -       nr_threads = clamp_val(nr_threads, 1, CMP_THREADS);
> +       nr_threads = clamp_val(nr_threads, 1, cmp_threads);
>
>         page = (void *)__get_free_page(GFP_NOIO | __GFP_HIGH);
>         if (!page) {
> @@ -1223,7 +1224,7 @@ static int load_compressed_image(struct swap_map_handle *handle,
>          * footprint.
>          */
>         nr_threads = num_online_cpus() - 1;
> -       nr_threads = clamp_val(nr_threads, 1, CMP_THREADS);
> +       nr_threads = clamp_val(nr_threads, 1, cmp_threads);
>
>         page = vmalloc(array_size(CMP_MAX_RD_PAGES, sizeof(*page)));
>         if (!page) {
> @@ -1667,3 +1668,14 @@ static int __init swsusp_header_init(void)
>  }
>
>  core_initcall(swsusp_header_init);
> +
> +static int __init cmp_threads_setup(char *str)
> +{
> +       int rc = kstrtouint(str, 0, &cmp_threads);
> +       if (rc)
> +               return rc;
> +       return 1;
> +
> +}
> +
> +__setup("cmp_threads=", cmp_threads_setup);
> --
> 2.43.0
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] PM: hibernate: make compression threads configurable via kernel parameter
  2025-08-26 11:43 ` Rafael J. Wysocki
@ 2025-08-28  3:29   ` luoxueqin
  0 siblings, 0 replies; 3+ messages in thread
From: luoxueqin @ 2025-08-28  3:29 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: pavel, lenb, linux-pm, linux-kernel


在 2025/8/26 19:43, Rafael J. Wysocki 写道:
> On Tue, Aug 26, 2025 at 11:19 AM Xueqin Luo <luoxueqin@kylinos.cn> wrote:
>> A new kernel parameter 'cmp_threads=' is introduced to
>> allow tuning the number of compression/decompression threads at boot.
> And why is it useful/needed?
The number of compression/decompression threads directly impacts 
hibernate and resume time.
In our tests(averaged over 10 runs):
     cmp_threads   hibernate(s)   resume(s)
             3                           12.14          18.86
             4                           12.28          17.48
             5                           11.09          16.77
             6                           11.08          16.44
With 5–6 threads, resume latency improves by ~12% compared to 3 threads. 
But on low-core systems,
more threads may cause contention. Making it configurable allows 
integrators to balance performance
  and CPU usage across different hardware without recompiling the kernel.
>> Signed-off-by: Xueqin Luo <luoxueqin@kylinos.cn>
>> ---
>>   kernel/power/swap.c | 22 +++++++++++++++++-----
>>   1 file changed, 17 insertions(+), 5 deletions(-)
>>
>> diff --git a/kernel/power/swap.c b/kernel/power/swap.c
>> index ad13c461b657..43280e08a4ad 100644
>> --- a/kernel/power/swap.c
>> +++ b/kernel/power/swap.c
>> @@ -520,7 +520,8 @@ static int swap_writer_finish(struct swap_map_handle *handle,
>>   #define CMP_SIZE       (CMP_PAGES * PAGE_SIZE)
>>
>>   /* Maximum number of threads for compression/decompression. */
>> -#define CMP_THREADS    3
>> +#define CMP_MAX_THREADS        12
>> +static int cmp_threads = 3
>>
>>   /* Minimum/maximum number of pages for read buffering. */
>>   #define CMP_MIN_RD_PAGES       1024
>> @@ -585,8 +586,8 @@ struct crc_data {
>>          wait_queue_head_t go;                     /* start crc update */
>>          wait_queue_head_t done;                   /* crc update done */
>>          u32 *crc32;                               /* points to handle's crc32 */
>> -       size_t *unc_len[CMP_THREADS];             /* uncompressed lengths */
>> -       unsigned char *unc[CMP_THREADS];          /* uncompressed data */
>> +       size_t *unc_len[CMP_MAX_THREADS];             /* uncompressed lengths */
>> +       unsigned char *unc[CMP_MAX_THREADS];          /* uncompressed data */
>>   };
>>
>>   /*
>> @@ -703,7 +704,7 @@ static int save_compressed_image(struct swap_map_handle *handle,
>>           * footprint.
>>           */
>>          nr_threads = num_online_cpus() - 1;
>> -       nr_threads = clamp_val(nr_threads, 1, CMP_THREADS);
>> +       nr_threads = clamp_val(nr_threads, 1, cmp_threads);
>>
>>          page = (void *)__get_free_page(GFP_NOIO | __GFP_HIGH);
>>          if (!page) {
>> @@ -1223,7 +1224,7 @@ static int load_compressed_image(struct swap_map_handle *handle,
>>           * footprint.
>>           */
>>          nr_threads = num_online_cpus() - 1;
>> -       nr_threads = clamp_val(nr_threads, 1, CMP_THREADS);
>> +       nr_threads = clamp_val(nr_threads, 1, cmp_threads);
>>
>>          page = vmalloc(array_size(CMP_MAX_RD_PAGES, sizeof(*page)));
>>          if (!page) {
>> @@ -1667,3 +1668,14 @@ static int __init swsusp_header_init(void)
>>   }
>>
>>   core_initcall(swsusp_header_init);
>> +
>> +static int __init cmp_threads_setup(char *str)
>> +{
>> +       int rc = kstrtouint(str, 0, &cmp_threads);
>> +       if (rc)
>> +               return rc;
>> +       return 1;
>> +
>> +}
>> +
>> +__setup("cmp_threads=", cmp_threads_setup);
>> --
>> 2.43.0
>>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-08-28  3:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-26  9:19 [PATCH] PM: hibernate: make compression threads configurable via kernel parameter Xueqin Luo
2025-08-26 11:43 ` Rafael J. Wysocki
2025-08-28  3:29   ` luoxueqin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).