]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
PM: hibernate: make compression threads configurable
authorXueqin Luo <luoxueqin@kylinos.cn>
Tue, 21 Oct 2025 11:37:27 +0000 (19:37 +0800)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Thu, 30 Oct 2025 19:07:00 +0000 (20:07 +0100)
The number of compression/decompression threads has a direct impact on
hibernate image generation and resume latency. Using more threads can
reduce overall resume time, but on systems with fewer CPU cores it may
also introduce contention and reduce efficiency.

Performance was evaluated on an 8-core ARM system, averaged over 10 runs:

    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 approximately 12% compared
to the default 3-thread configuration, with negligible impact on
hibernate time.

Introduce a new kernel parameter `hibernate_compression_threads=` that
allows users and integrators to tune the number of
compression/decompression threads at boot. This provides a way to
balance performance and CPU utilization across a wide range of hardware
without recompiling the kernel.

Signed-off-by: Xueqin Luo <luoxueqin@kylinos.cn>
Link: https://patch.msgid.link/f24b3ca6416e230a515a154ed4c121d72a7e05a6.1761046167.git.luoxueqin@kylinos.cn
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Documentation/admin-guide/kernel-parameters.txt
kernel/power/swap.c

index 6c42061ca20e581b5192b66c6f25aba38d4f8ff8..46db3cbb838f2249d771c95b5d46af51985491aa 100644 (file)
                        /sys/power/pm_test). Only available when CONFIG_PM_DEBUG
                        is set. Default value is 5.
 
+       hibernate_compression_threads=
+                       [HIBERNATION]
+                       Set the number of threads used for compressing or decompressing
+                       hibernation images.
+
+                       Format: <integer>
+                       Default: 3
+                       Minimum: 1
+                       Example: hibernate_compression_threads=4
+
        highmem=nn[KMG] [KNL,BOOT,EARLY] forces the highmem zone to have an exact
                        size of <nn>. This works even on boxes that have no
                        highmem otherwise. This also works to reduce highmem
index f8c13f5672ec2289875468de2143d3bf954e089c..aa11576e92a97442f1c353835f73f355c9d156e6 100644 (file)
@@ -519,8 +519,9 @@ static int swap_writer_finish(struct swap_map_handle *handle,
                                CMP_HEADER, PAGE_SIZE)
 #define CMP_SIZE       (CMP_PAGES * PAGE_SIZE)
 
-/* Maximum number of threads for compression/decompression. */
-#define CMP_THREADS    3
+/* Default number of threads for compression/decompression. */
+#define CMP_THREADS    3
+static unsigned int hibernate_compression_threads = CMP_THREADS;
 
 /* Minimum/maximum number of pages for read buffering. */
 #define CMP_MIN_RD_PAGES       1024
@@ -741,7 +742,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, hibernate_compression_threads);
 
        page = (void *)__get_free_page(GFP_NOIO | __GFP_HIGH);
        if (!page) {
@@ -1257,7 +1258,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, hibernate_compression_threads);
 
        page = vmalloc_array(CMP_MAX_RD_PAGES, sizeof(*page));
        if (!page) {
@@ -1697,3 +1698,19 @@ static int __init swsusp_header_init(void)
 }
 
 core_initcall(swsusp_header_init);
+
+static int __init hibernate_compression_threads_setup(char *str)
+{
+       int rc = kstrtouint(str, 0, &hibernate_compression_threads);
+
+       if (rc)
+               return rc;
+
+       if (hibernate_compression_threads < 1)
+               hibernate_compression_threads = CMP_THREADS;
+
+       return 1;
+
+}
+
+__setup("hibernate_compression_threads=", hibernate_compression_threads_setup);