Skip to content

Commit ea35806

Browse files
Xueqin Luorafaeljw
authored andcommitted
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>
1 parent 090bf5a commit ea35806

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

Documentation/ABI/testing/sysfs-power

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,3 +454,19 @@ Description:
454454
disables it. Reads from the file return the current value.
455455
The default is "1" if the build-time "SUSPEND_SKIP_SYNC" config
456456
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

kernel/power/swap.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,8 +1689,46 @@ int swsusp_unmark(void)
16891689
}
16901690
#endif
16911691

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+
16921724
static int __init swsusp_header_init(void)
16931725
{
1726+
int error;
1727+
1728+
error = sysfs_create_group(power_kobj, &attr_group);
1729+
if (error)
1730+
return -ENOMEM;
1731+
16941732
swsusp_header = (struct swsusp_header*) __get_free_page(GFP_KERNEL);
16951733
if (!swsusp_header)
16961734
panic("Could not allocate memory for swsusp_header\n");

0 commit comments

Comments
 (0)