Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

PM: hibernate: add sysfs interface for hibernate_compression_threads

Add a sysfs attribute `/sys/power/hibernate_compression_threads` to
allow runtime configuration of the number of threads used for
compressing and decompressing hibernation images.

The new sysfs interface enables dynamic adjustment at runtime:

# cat /sys/power/hibernate_compression_threads
3
# echo 4 > /sys/power/hibernate_compression_threads

This change provides greater flexibility for debugging and performance
tuning of hibernation without requiring a reboot.

Signed-off-by: Xueqin Luo <luoxueqin@kylinos.cn>
Link: https://patch.msgid.link/c68c62f97fabf32507b8794ad8c16cd22ee656ac.1761046167.git.luoxueqin@kylinos.cn
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Xueqin Luo and committed by
Rafael J. Wysocki
ea358066 090bf5a0

+54
+16
Documentation/ABI/testing/sysfs-power
··· 454 454 disables it. Reads from the file return the current value. 455 455 The default is "1" if the build-time "SUSPEND_SKIP_SYNC" config 456 456 flag is unset, or "0" otherwise. 457 + 458 + What: /sys/power/hibernate_compression_threads 459 + Date: October 2025 460 + Contact: <luoxueqin@kylinos.cn> 461 + Description: 462 + Controls the number of threads used for compression 463 + and decompression of hibernation images. 464 + 465 + The value can be adjusted at runtime to balance 466 + performance and CPU utilization. 467 + 468 + The change takes effect on the next hibernation or 469 + resume operation. 470 + 471 + Minimum value: 1 472 + Default value: 3
+38
kernel/power/swap.c
··· 1689 1689 } 1690 1690 #endif 1691 1691 1692 + static ssize_t hibernate_compression_threads_show(struct kobject *kobj, 1693 + struct kobj_attribute *attr, char *buf) 1694 + { 1695 + return sysfs_emit(buf, "%d\n", hibernate_compression_threads); 1696 + } 1697 + 1698 + static ssize_t hibernate_compression_threads_store(struct kobject *kobj, 1699 + struct kobj_attribute *attr, 1700 + const char *buf, size_t n) 1701 + { 1702 + unsigned long val; 1703 + 1704 + if (kstrtoul(buf, 0, &val)) 1705 + return -EINVAL; 1706 + 1707 + if (val < 1) 1708 + return -EINVAL; 1709 + 1710 + hibernate_compression_threads = val; 1711 + return n; 1712 + } 1713 + power_attr(hibernate_compression_threads); 1714 + 1715 + static struct attribute *g[] = { 1716 + &hibernate_compression_threads_attr.attr, 1717 + NULL, 1718 + }; 1719 + 1720 + static const struct attribute_group attr_group = { 1721 + .attrs = g, 1722 + }; 1723 + 1692 1724 static int __init swsusp_header_init(void) 1693 1725 { 1726 + int error; 1727 + 1728 + error = sysfs_create_group(power_kobj, &attr_group); 1729 + if (error) 1730 + return -ENOMEM; 1731 + 1694 1732 swsusp_header = (struct swsusp_header*) __get_free_page(GFP_KERNEL); 1695 1733 if (!swsusp_header) 1696 1734 panic("Could not allocate memory for swsusp_header\n");