[PATCH] power: Changed CMP_THREADS from hardwired value to configurable value

From: Jay Penny
Date: Fri Feb 14 2025 - 06:27:39 EST


I don't know what the rules are (unspoken or otherwise) for stating
that this is your patch - The CoC doesn't say anything regarding it,
so I'm just going to mention it here. This is my first kernel patch,
so if I mess something up, it's due to a lack of experience on my part.

Changed CMP_THREADS in kernel/power/swap.c from a hardwired 3 threads,
to a configurable one, and created a corresponding config option in
kernel/power/Kconfig.

The fact that this is such a simple change that hasn't been made yet
probably means that it shouldn't be made. That, or I'm just being
pessimistic.

Signed-off-by: Jay Penny <hills.a.joel@xxxxxxxxx>
---
kernel/power/Kconfig | 13 +++++++++++++
kernel/power/swap.c | 2 +-
2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
index ca947ed32e3d..432e75c76c49 100644
--- a/kernel/power/Kconfig
+++ b/kernel/power/Kconfig
@@ -80,6 +80,19 @@ config HIBERNATION
=20
For more information take a look at
<file:Documentation/power/swsusp.rst>.
=20
+config HIBERNATION_THREADS
+ int "Hibernation threads"
+ depends on HIBERNATION
+ range 1 65535
+ default 3
+ help
+ The maximum number of threads that should be used when
+ compressing/decompressing a hibernation image. The number
+ of threads used is calculated as:
+ clamp(num_online_cpus() - 1, 1, HIBERNATION_THREADS).
+
+ If in doubt, leave at the default of 3
+
config HIBERNATION_SNAPSHOT_DEV
bool "Userspace snapshot device"
depends on HIBERNATION
diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index 82b884b67152..6ac787f8421a 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -534,7 +534,7 @@ static int swap_writer_finish(struct
swap_map_handle *handle,
#define CMP_SIZE (CMP_PAGES * PAGE_SIZE)
=20
/* Maximum number of threads for compression/decompression. */
-#define CMP_THREADS 3
+#define CMP_THREADS CONFIG_HIBERNATION_THREADS
=20
/* Minimum/maximum number of pages for read buffering. */
#define CMP_MIN_RD_PAGES 1024
--=20
2.48.1