Skip to content

Commit 3550646

Browse files
Mario Limonciellorafaeljw
authored andcommitted
PM / hibernate: Make passing hibernate offsets more friendly
Currently the only way to specify a hibernate offset for a swap file is on the kernel command line. Add a new /sys/power/resume_offset that lets userspace specify the offset and disk to use when initiating a hibernate cycle. Signed-off-by: Mario Limonciello <mario.limonciello@dell.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent dbdd0f5 commit 3550646

3 files changed

Lines changed: 47 additions & 1 deletion

File tree

‎Documentation/ABI/testing/sysfs-power‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,17 @@ Description:
287287
Writing a "1" to this file enables the debug messages and
288288
writing a "0" (default) to it disables them. Reads from
289289
this file return the current value.
290+
291+
What: /sys/power/resume_offset
292+
Date: April 2018
293+
Contact: Mario Limonciello <mario.limonciello@dell.com>
294+
Description:
295+
This file is used for telling the kernel an offset into a disk
296+
to use when hibernating the system such as with a swap file.
297+
298+
Reads from this file will display the current offset
299+
the kernel will be using on the next hibernation
300+
attempt.
301+
302+
Using this sysfs file will override any values that were
303+
set using the kernel command line for disk offset.

‎Documentation/power/swsusp.txt‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,16 @@ Some warnings, first.
2424
* see the FAQ below for details. (This is not true for more traditional
2525
* power states like "standby", which normally don't turn USB off.)
2626

27+
Swap partition:
2728
You need to append resume=/dev/your_swap_partition to kernel command
28-
line. Then you suspend by
29+
line or specify it using /sys/power/resume.
30+
31+
Swap file:
32+
If using a swapfile you can also specify a resume offset using
33+
resume_offset=<number> on the kernel command line or specify it
34+
in /sys/power/resume_offset.
35+
36+
After preparing then you suspend by
2937

3038
echo shutdown > /sys/power/disk; echo disk > /sys/power/state
3139

‎kernel/power/hibernate.c‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,29 @@ static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,
10611061

10621062
power_attr(resume);
10631063

1064+
static ssize_t resume_offset_show(struct kobject *kobj,
1065+
struct kobj_attribute *attr, char *buf)
1066+
{
1067+
return sprintf(buf, "%llu\n", (unsigned long long)swsusp_resume_block);
1068+
}
1069+
1070+
static ssize_t resume_offset_store(struct kobject *kobj,
1071+
struct kobj_attribute *attr, const char *buf,
1072+
size_t n)
1073+
{
1074+
unsigned long long offset;
1075+
int rc;
1076+
1077+
rc = kstrtoull(buf, 0, &offset);
1078+
if (rc)
1079+
return rc;
1080+
swsusp_resume_block = offset;
1081+
1082+
return n;
1083+
}
1084+
1085+
power_attr(resume_offset);
1086+
10641087
static ssize_t image_size_show(struct kobject *kobj, struct kobj_attribute *attr,
10651088
char *buf)
10661089
{
@@ -1106,6 +1129,7 @@ power_attr(reserved_size);
11061129

11071130
static struct attribute * g[] = {
11081131
&disk_attr.attr,
1132+
&resume_offset_attr.attr,
11091133
&resume_attr.attr,
11101134
&image_size_attr.attr,
11111135
&reserved_size_attr.attr,

0 commit comments

Comments
 (0)