[RFC PATCH 5/6] PM: hibernate: add compress_on_copy sysfs policy
From: Nhat-Trieu Huynh-Pham
Date: Sat Nov 28 2026 - 14:32:10 EST
Expose compress-on-copy runtime control through /sys/power/compress_on_copy
under CONFIG_HIBERNATION_COMPRESS_ON_COPY, in addition to the
hibernate=compress_on_copy boot parameter. Writes are parsed with
kstrtobool() and serialized with system sleep transitions via
lock_system_sleep().
Document the new sysfs attribute in Documentation/ABI/testing/sysfs-power,
Documentation/power/swsusp.rst and the Kconfig help text.
Signed-off-by: Nhat-Trieu Huynh-Pham <trieu2.huynh@xxxxxxx>
---
Documentation/ABI/testing/sysfs-power | 29 +++++++++++++++++++++++
Documentation/power/swsusp.rst | 3 ++-
kernel/power/Kconfig | 3 ++-
kernel/power/hibernate.c | 33 +++++++++++++++++++++++++++
4 files changed, 66 insertions(+), 2 deletions(-)
diff --git a/Documentation/ABI/testing/sysfs-power b/Documentation/ABI/testing/sysfs-power
index d38da077905a..a6287d5615d8 100644
--- a/Documentation/ABI/testing/sysfs-power
+++ b/Documentation/ABI/testing/sysfs-power
@@ -470,3 +470,32 @@ Description:
Minimum value: 1
Default value: 3
+
+What: /sys/power/compress_on_copy
+Date: November 2026
+Contact: Nhat-Trieu Huynh-Pham <trieu2.huynh@xxxxxxx>
+Description:
+ Controls the compress-on-copy fallback for hibernation.
+
+ "off"
+ Use the stock 1:1 copy-page preallocation. This is
+ the default.
+
+ "on"
+ Run the stock 1:1 copy-page allocation first. If it
+ comes up short, keep the pages it did allocate and
+ fill a pool of compressed image pages up to the
+ usable free budget before activating it. If no pool
+ page can be obtained, hibernation fails. The whole
+ compressed image must fit in the pool, otherwise
+ hibernation fails with -ENOMEM before anything is
+ written.
+
+ The setting applies to the next hibernation and is
+ serialized with system sleep transitions. Available when
+ CONFIG_HIBERNATION_COMPRESS_ON_COPY is enabled. The same
+ policy can be selected at boot with
+ hibernate=compress_on_copy.
+
+ See Documentation/power/swsusp.rst for the pool layout,
+ the codec and the atomic-copy timing constraints.
diff --git a/Documentation/power/swsusp.rst b/Documentation/power/swsusp.rst
index 0ab7bc6173de..a17d0d3c1489 100644
--- a/Documentation/power/swsusp.rst
+++ b/Documentation/power/swsusp.rst
@@ -84,7 +84,8 @@ in the existing length-prefixed format; only the metadata pages are
compressed while writing. The on-disk image, the resume path and the CRC
layout are unchanged.
-Enable it with ``hibernate=compress_on_copy``. With ``on``, the stock
+Enable it with ``hibernate=compress_on_copy`` or by writing ``on`` to
+``/sys/power/compress_on_copy``. With ``on``, the stock
copy-page allocation is tried first. If it completes, the stock image is
used. If it fails, the pages it allocated are kept and the fallback fills
the pool up to the usable free budget before activating it. That budget
diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
index aa42b0ffd23b..3f6e2605bd4f 100644
--- a/kernel/power/Kconfig
+++ b/kernel/power/Kconfig
@@ -107,7 +107,8 @@ config HIBERNATION_COMPRESS_ON_COPY
uncompressed copy. The on-disk image format and resume path are
unchanged.
- Enable at runtime via hibernate=compress_on_copy.
+ Enable at runtime via hibernate=compress_on_copy or
+ /sys/power/compress_on_copy.
If unsure, say N.
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index bf0e93016477..b0efdddf8870 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -1386,12 +1386,45 @@ static ssize_t reserved_size_store(struct kobject *kobj,
power_attr(reserved_size);
+#ifdef CONFIG_HIBERNATION_COMPRESS_ON_COPY
+static ssize_t compress_on_copy_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
+{
+ return sysfs_emit(buf, "%s\n",
+ snapshot_cocopy_enabled() ? "on" : "off");
+}
+
+static ssize_t compress_on_copy_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t n)
+{
+ unsigned int sleep_flags;
+ bool enable;
+ int ret;
+
+ ret = kstrtobool(buf, &enable);
+ if (ret)
+ return ret;
+
+ sleep_flags = lock_system_sleep();
+ ret = snapshot_cocopy_set_enabled(enable);
+ unlock_system_sleep(sleep_flags);
+
+ return ret ? ret : n;
+}
+
+power_attr(compress_on_copy);
+#endif
+
static struct attribute *g[] = {
&disk_attr.attr,
&resume_offset_attr.attr,
&resume_attr.attr,
&image_size_attr.attr,
&reserved_size_attr.attr,
+#ifdef CONFIG_HIBERNATION_COMPRESS_ON_COPY
+ &compress_on_copy_attr.attr,
+#endif
NULL,
};
--
2.43.0