3 * BIG FAT WARNING *********************************************************
5 * If you have unsupported (*) devices using DMA...
6 * ...say goodbye to your data.
8 * If you touch anything on disk between suspend and resume...
9 * ...kiss your data goodbye.
11 * If your disk driver does not support suspend... (IDE does)
12 * ...you'd better find out how to get along
15 * If you change kernel command line between suspend and resume...
16 * ...prepare for nasty fsck or worse.
18 * (*) pm interface support is needed to make it safe.
20 You need to append resume=/dev/your_swap_partition to kernel command
21 line. Then you suspend by echo 4 > /proc/acpi/sleep.
23 Article about goals and implementation of Software Suspend for Linux
24 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
26 Last revised: 2003-10-20 by Pavel Machek
28 Idea and goals to achieve
30 Nowadays it is common in several laptops that they have a suspend button. It
31 saves the state of the machine to a filesystem or to a partition and switches
32 to standby mode. Later resuming the machine the saved state is loaded back to
33 ram and the machine can continue its work. It has two real benefits. First we
34 save ourselves the time machine goes down and later boots up, energy costs
35 real high when running from batteries. The other gain is that we don't have to
36 interrupt our programs so processes that are calculating something for a long
37 time shouldn't need to be written interruptible.
41 You have two ways to use this code. The first one is is with a patched
42 SysVinit (my patch is against 2.76 and available at my home page). You
43 might call 'swsusp' or 'shutdown -z <time>'. Next way is to echo 4 >
46 Either way it saves the state of the machine into active swaps and then
47 reboots. You must explicitly specify the swap partition to resume from with
48 ``resume='' kernel option. If signature is found it loads and restores saved
49 state. If the option ``noresume'' is specified as a boot parameter, it skips
52 In the meantime while the system is suspended you should not touch any of the
58 - We should only make a copy of data related to kernel segment, since any
59 process data won't be changed.
60 - Should make more sanity checks. Or are these enough?
62 Not so important ideas for implementing
64 - If a real time process is running then don't suspend the machine.
65 - Support for adding/removing hardware while suspended?
66 - We should not free pages at the beginning so aggressively, most of them
69 Sleep states summary (thanx, Ducrot)
70 ====================================
72 In a really perfect world:
73 echo 1 > /proc/acpi/sleep # for standby
74 echo 2 > /proc/acpi/sleep # for suspend to ram
75 echo 3 > /proc/acpi/sleep # for suspend to ram, but with more power conservative
76 echo 4 > /proc/acpi/sleep # for suspend to disk
77 echo 5 > /proc/acpi/sleep # for shutdown unfriendly the system
80 echo 4b > /proc/acpi/sleep # for suspend to disk via s4bios
83 Frequently Asked Questions
84 ==========================
86 Q: well, suspending a server is IMHO a really stupid thing,
87 but... (Diego Zuccato):
89 A: You bought new UPS for your server. How do you install it without
90 bringing machine down? Suspend to disk, rearrange power cables,
93 You have your server on UPS. Power died, and UPS is indicating 30
94 seconds to failure. What do you do? Suspend to disk.
96 Ethernet card in your server died. You want to replace it. Your
97 server is not hotplug capable. What do you do? Suspend to disk,
98 replace ethernet card, resume. If you are fast your users will not
99 even see broken connections.
102 Q: Maybe I'm missing something, but why don't the regular I/O paths work?
104 A: We do use the regular I/O paths. However we cannot restore the data
105 to its original location as we load it. That would create an
106 inconsistent kernel state which would certainly result in an oops.
107 Instead, we load the image into unused memory and then atomically copy
108 it back to it original location. This implies, of course, a maximum
109 image size of half the amount of memory.
111 There are two solutions to this:
113 * require half of memory to be free during suspend. That way you can
114 read "new" data onto free spots, then cli and copy
116 * assume we had special "polling" ide driver that only uses memory
117 between 0-640KB. That way, I'd have to make sure that 0-640KB is free
118 during suspending, but otherwise it would work...
120 suspend2 shares this fundamental limitation, but does not include user
121 data and disk caches into "used memory" by saving them in
122 advance. That means that the limitation goes away in practice.
124 Q: Does linux support ACPI S4?
128 When swsusp was created, ACPI was not too widespread, so we tried to
129 avoid using ACPI-specific stuff. ACPI also is/was notoriously
130 buggy. These days swsusp works on APM-only i386 machines and even
131 without any power managment at all. Some versions also work on PPC.
133 That means that machine does not enter S4 on suspend-to-disk, but
134 simply enters S5. That has few advantages, you can for example boot
135 windows on next boot, and return to your Linux session later. You
136 could even have few different Linuxes on your box (not sharing any
137 partitions), and switch between them.
139 It also has disadvantages. On HP nx5000, if you unplug power cord
140 while machine is suspended-to-disk, Linux will fail to notice that.
142 Q: My machine doesn't work with ACPI. How can I use swsusp than ?
144 A: Do a reboot() syscall with right parameters. Warning: glibc gets in
145 its way, so check with strace:
147 reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, 0xd000fce2)
149 (Thanks to Peter Osterlund:)
154 #define LINUX_REBOOT_MAGIC1 0xfee1dead
155 #define LINUX_REBOOT_MAGIC2 672274793
156 #define LINUX_REBOOT_CMD_SW_SUSPEND 0xD000FCE2
160 syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2,
161 LINUX_REBOOT_CMD_SW_SUSPEND, 0);
165 Q: What is 'suspend2'?
167 A: suspend2 is 'Software Suspend 2', a forked implementation of
168 suspend-to-disk which is available as separate patches for 2.4 and 2.6
169 kernels from swsusp.sourceforge.net. It includes support for SMP, 4GB
170 highmem and preemption. It also has a extensible architecture that
171 allows for arbitrary transformations on the image (compression,
172 encryption) and arbitrary backends for writing the image (eg to swap
173 or an NFS share[Work In Progress]). Questions regarding suspend2
174 should be sent to the mailing list available through the suspend2
175 website, and not to the Linux Kernel Mailing List. We are working
176 toward merging suspend2 into the mainline kernel.
178 Q: Kernel thread must voluntarily freeze itself (call 'refrigerator'). But
179 I found some kernel threads don't do it, and they don't freeze, and
180 so the system can't sleep. Is this a known behavior?
182 A: All such kernel threads need to be fixed, one by one. Select place
183 where it is safe to be frozen (no kernel semaphores should be held at
184 that point and it must be safe to sleep there), and add:
186 if (current->flags & PF_FREEZE)
187 refrigerator(PF_FREEZE);
189 Q: What is the difference between between "platform", "shutdown" and
190 "firmware" in /sys/power/disk?
194 shutdown: save state in linux, then tell bios to powerdown
196 platform: save state in linux, then tell bios to powerdown and blink
199 firmware: tell bios to save state itself [needs BIOS-specific suspend
200 partition, and has very little to do with swsusp]
202 "platform" is actually right thing to do, but "shutdown" is most