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 * If you change your hardware while system is suspended...
19 * ...well, it was not good idea.
21 * (*) suspend/resume support is needed to make it safe.
23 You need to append resume=/dev/your_swap_partition to kernel command
24 line. Then you suspend by
26 echo shutdown > /sys/power/disk; echo disk > /sys/power/state
28 . If you feel ACPI works pretty well on your system, you might try
30 echo platform > /sys/power/disk; echo disk > /sys/power/state
34 Article about goals and implementation of Software Suspend for Linux
35 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37 Last revised: 2003-10-20 by Pavel Machek
39 Idea and goals to achieve
41 Nowadays it is common in several laptops that they have a suspend button. It
42 saves the state of the machine to a filesystem or to a partition and switches
43 to standby mode. Later resuming the machine the saved state is loaded back to
44 ram and the machine can continue its work. It has two real benefits. First we
45 save ourselves the time machine goes down and later boots up, energy costs
46 are real high when running from batteries. The other gain is that we don't have to
47 interrupt our programs so processes that are calculating something for a long
48 time shouldn't need to be written interruptible.
50 swsusp saves the state of the machine into active swaps and then reboots or
51 powerdowns. You must explicitly specify the swap partition to resume from with
52 ``resume='' kernel option. If signature is found it loads and restores saved
53 state. If the option ``noresume'' is specified as a boot parameter, it skips
56 In the meantime while the system is suspended you should not add/remove any
57 of the hardware, write to the filesystems, etc.
62 There are three different interfaces you can use, /proc/acpi should
65 In a really perfect world:
66 echo 1 > /proc/acpi/sleep # for standby
67 echo 2 > /proc/acpi/sleep # for suspend to ram
68 echo 3 > /proc/acpi/sleep # for suspend to ram, but with more power conservative
69 echo 4 > /proc/acpi/sleep # for suspend to disk
70 echo 5 > /proc/acpi/sleep # for shutdown unfriendly the system
73 echo 4b > /proc/acpi/sleep # for suspend to disk via s4bios
75 Frequently Asked Questions
76 ==========================
78 Q: well, suspending a server is IMHO a really stupid thing,
79 but... (Diego Zuccato):
81 A: You bought new UPS for your server. How do you install it without
82 bringing machine down? Suspend to disk, rearrange power cables,
85 You have your server on UPS. Power died, and UPS is indicating 30
86 seconds to failure. What do you do? Suspend to disk.
88 Ethernet card in your server died. You want to replace it. Your
89 server is not hotplug capable. What do you do? Suspend to disk,
90 replace ethernet card, resume. If you are fast your users will not
91 even see broken connections.
94 Q: Maybe I'm missing something, but why don't the regular I/O paths work?
96 A: We do use the regular I/O paths. However we cannot restore the data
97 to its original location as we load it. That would create an
98 inconsistent kernel state which would certainly result in an oops.
99 Instead, we load the image into unused memory and then atomically copy
100 it back to it original location. This implies, of course, a maximum
101 image size of half the amount of memory.
103 There are two solutions to this:
105 * require half of memory to be free during suspend. That way you can
106 read "new" data onto free spots, then cli and copy
108 * assume we had special "polling" ide driver that only uses memory
109 between 0-640KB. That way, I'd have to make sure that 0-640KB is free
110 during suspending, but otherwise it would work...
112 suspend2 shares this fundamental limitation, but does not include user
113 data and disk caches into "used memory" by saving them in
114 advance. That means that the limitation goes away in practice.
116 Q: Does linux support ACPI S4?
118 A: Yes. That's what echo platform > /sys/power/disk does.
120 Q: My machine doesn't work with ACPI. How can I use swsusp than ?
122 A: Do a reboot() syscall with right parameters. Warning: glibc gets in
123 its way, so check with strace:
125 reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, 0xd000fce2)
127 (Thanks to Peter Osterlund:)
132 #define LINUX_REBOOT_MAGIC1 0xfee1dead
133 #define LINUX_REBOOT_MAGIC2 672274793
134 #define LINUX_REBOOT_CMD_SW_SUSPEND 0xD000FCE2
138 syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2,
139 LINUX_REBOOT_CMD_SW_SUSPEND, 0);
143 Also /sys/ interface should be still present.
145 Q: What is 'suspend2'?
147 A: suspend2 is 'Software Suspend 2', a forked implementation of
148 suspend-to-disk which is available as separate patches for 2.4 and 2.6
149 kernels from swsusp.sourceforge.net. It includes support for SMP, 4GB
150 highmem and preemption. It also has a extensible architecture that
151 allows for arbitrary transformations on the image (compression,
152 encryption) and arbitrary backends for writing the image (eg to swap
153 or an NFS share[Work In Progress]). Questions regarding suspend2
154 should be sent to the mailing list available through the suspend2
155 website, and not to the Linux Kernel Mailing List. We are working
156 toward merging suspend2 into the mainline kernel.
158 Q: A kernel thread must voluntarily freeze itself (call 'refrigerator').
159 I found some kernel threads that don't do it, and they don't freeze
160 so the system can't sleep. Is this a known behavior?
162 A: All such kernel threads need to be fixed, one by one. Select the
163 place where the thread is safe to be frozen (no kernel semaphores
164 should be held at that point and it must be safe to sleep there), and
167 if (current->flags & PF_FREEZE)
168 refrigerator(PF_FREEZE);
170 If the thread is needed for writing the image to storage, you should
171 instead set the PF_NOFREEZE process flag when creating the thread.
174 Q: What is the difference between between "platform", "shutdown" and
175 "firmware" in /sys/power/disk?
179 shutdown: save state in linux, then tell bios to powerdown
181 platform: save state in linux, then tell bios to powerdown and blink
184 firmware: tell bios to save state itself [needs BIOS-specific suspend
185 partition, and has very little to do with swsusp]
187 "platform" is actually right thing to do, but "shutdown" is most
190 Q: I do not understand why you have such strong objections to idea of
193 A: Do selective suspend during runtime power managment, that's okay. But
194 its useless for suspend-to-disk. (And I do not see how you could use
195 it for suspend-to-ram, I hope you do not want that).
197 Lets see, so you suggest to
199 * SUSPEND all but swap device and parents
201 * Write image to disk
202 * SUSPEND swap device and parents
205 Oh no, that does not work, if swap device or its parents uses DMA,
206 you've corrupted data. You'd have to do
208 * SUSPEND all but swap device and parents
209 * FREEZE swap device and parents
211 * UNFREEZE swap device and parents
213 * SUSPEND swap device and parents
215 Which means that you still need that FREEZE state, and you get more
216 complicated code. (And I have not yet introduce details like system
219 Q: There don't seem to be any generally useful behavioral
220 distinctions between SUSPEND and FREEZE.
222 A: Doing SUSPEND when you are asked to do FREEZE is always correct,
223 but it may be unneccessarily slow. If you want USB to stay simple,
224 slowness may not matter to you. It can always be fixed later.
226 For devices like disk it does matter, you do not want to spindown for
229 Q: After resuming, system is paging heavilly, leading to very bad interactivity.
233 cat `cat /proc/[0-9]*/maps | grep / | sed 's:.* /:/:' | sort -u` > /dev/null
235 after resume. swapoff -a; swapon -a may also be usefull.