]>
Commit | Line | Data |
---|---|---|
d7ae79c7 | 1 | Some warnings, first. |
1da177e4 LT |
2 | |
3 | * BIG FAT WARNING ********************************************************* | |
4 | * | |
1da177e4 LT |
5 | * If you touch anything on disk between suspend and resume... |
6 | * ...kiss your data goodbye. | |
7 | * | |
d7ae79c7 PM |
8 | * If you do resume from initrd after your filesystems are mounted... |
9 | * ...bye bye root partition. | |
10 | * [this is actually same case as above] | |
1da177e4 | 11 | * |
d7ae79c7 PM |
12 | * If you have unsupported (*) devices using DMA, you may have some |
13 | * problems. If your disk driver does not support suspend... (IDE does), | |
14 | * it may cause some problems, too. If you change kernel command line | |
15 | * between suspend and resume, it may do something wrong. If you change | |
16 | * your hardware while system is suspended... well, it was not good idea; | |
17 | * but it will probably only crash. | |
1da177e4 LT |
18 | * |
19 | * (*) suspend/resume support is needed to make it safe. | |
543cc27d | 20 | * |
b9827e4b | 21 | * If you have any filesystems on USB devices mounted before software suspend, |
543cc27d | 22 | * they won't be accessible after resume and you may lose data, as though |
b9827e4b DB |
23 | * you have unplugged the USB devices with mounted filesystems on them; |
24 | * see the FAQ below for details. (This is not true for more traditional | |
25 | * power states like "standby", which normally don't turn USB off.) | |
1da177e4 LT |
26 | |
27 | You need to append resume=/dev/your_swap_partition to kernel command | |
28 | line. Then you suspend by | |
29 | ||
30 | echo shutdown > /sys/power/disk; echo disk > /sys/power/state | |
31 | ||
32 | . If you feel ACPI works pretty well on your system, you might try | |
33 | ||
34 | echo platform > /sys/power/disk; echo disk > /sys/power/state | |
35 | ||
543cc27d PM |
36 | . If you have SATA disks, you'll need recent kernels with SATA suspend |
37 | support. For suspend and resume to work, make sure your disk drivers | |
38 | are built into kernel -- not modules. [There's way to make | |
39 | suspend/resume with modular disk drivers, see FAQ, but you probably | |
40 | should not do that.] | |
41 | ||
853609b6 | 42 | If you want to limit the suspend image size to N bytes, do |
ca0aec0f RW |
43 | |
44 | echo N > /sys/power/image_size | |
45 | ||
46 | before suspend (it is limited to 500 MB by default). | |
1da177e4 LT |
47 | |
48 | ||
49 | Article about goals and implementation of Software Suspend for Linux | |
50 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
be2a608b | 51 | Author: G\82ábor Kuti |
1da177e4 LT |
52 | Last revised: 2003-10-20 by Pavel Machek |
53 | ||
54 | Idea and goals to achieve | |
55 | ||
56 | Nowadays it is common in several laptops that they have a suspend button. It | |
57 | saves the state of the machine to a filesystem or to a partition and switches | |
58 | to standby mode. Later resuming the machine the saved state is loaded back to | |
59 | ram and the machine can continue its work. It has two real benefits. First we | |
60 | save ourselves the time machine goes down and later boots up, energy costs | |
61 | are real high when running from batteries. The other gain is that we don't have to | |
62 | interrupt our programs so processes that are calculating something for a long | |
63 | time shouldn't need to be written interruptible. | |
64 | ||
65 | swsusp saves the state of the machine into active swaps and then reboots or | |
66 | powerdowns. You must explicitly specify the swap partition to resume from with | |
67 | ``resume='' kernel option. If signature is found it loads and restores saved | |
68 | state. If the option ``noresume'' is specified as a boot parameter, it skips | |
69 | the resuming. | |
70 | ||
71 | In the meantime while the system is suspended you should not add/remove any | |
72 | of the hardware, write to the filesystems, etc. | |
73 | ||
74 | Sleep states summary | |
75 | ==================== | |
76 | ||
77 | There are three different interfaces you can use, /proc/acpi should | |
78 | work like this: | |
79 | ||
80 | In a really perfect world: | |
81 | echo 1 > /proc/acpi/sleep # for standby | |
82 | echo 2 > /proc/acpi/sleep # for suspend to ram | |
83 | echo 3 > /proc/acpi/sleep # for suspend to ram, but with more power conservative | |
84 | echo 4 > /proc/acpi/sleep # for suspend to disk | |
85 | echo 5 > /proc/acpi/sleep # for shutdown unfriendly the system | |
86 | ||
87 | and perhaps | |
88 | echo 4b > /proc/acpi/sleep # for suspend to disk via s4bios | |
89 | ||
90 | Frequently Asked Questions | |
91 | ========================== | |
92 | ||
93 | Q: well, suspending a server is IMHO a really stupid thing, | |
94 | but... (Diego Zuccato): | |
95 | ||
96 | A: You bought new UPS for your server. How do you install it without | |
97 | bringing machine down? Suspend to disk, rearrange power cables, | |
98 | resume. | |
99 | ||
100 | You have your server on UPS. Power died, and UPS is indicating 30 | |
101 | seconds to failure. What do you do? Suspend to disk. | |
102 | ||
1da177e4 LT |
103 | |
104 | Q: Maybe I'm missing something, but why don't the regular I/O paths work? | |
105 | ||
106 | A: We do use the regular I/O paths. However we cannot restore the data | |
107 | to its original location as we load it. That would create an | |
108 | inconsistent kernel state which would certainly result in an oops. | |
109 | Instead, we load the image into unused memory and then atomically copy | |
110 | it back to it original location. This implies, of course, a maximum | |
111 | image size of half the amount of memory. | |
112 | ||
113 | There are two solutions to this: | |
114 | ||
115 | * require half of memory to be free during suspend. That way you can | |
116 | read "new" data onto free spots, then cli and copy | |
117 | ||
118 | * assume we had special "polling" ide driver that only uses memory | |
119 | between 0-640KB. That way, I'd have to make sure that 0-640KB is free | |
120 | during suspending, but otherwise it would work... | |
121 | ||
122 | suspend2 shares this fundamental limitation, but does not include user | |
123 | data and disk caches into "used memory" by saving them in | |
124 | advance. That means that the limitation goes away in practice. | |
125 | ||
126 | Q: Does linux support ACPI S4? | |
127 | ||
128 | A: Yes. That's what echo platform > /sys/power/disk does. | |
129 | ||
1da177e4 LT |
130 | Q: What is 'suspend2'? |
131 | ||
132 | A: suspend2 is 'Software Suspend 2', a forked implementation of | |
133 | suspend-to-disk which is available as separate patches for 2.4 and 2.6 | |
134 | kernels from swsusp.sourceforge.net. It includes support for SMP, 4GB | |
135 | highmem and preemption. It also has a extensible architecture that | |
136 | allows for arbitrary transformations on the image (compression, | |
137 | encryption) and arbitrary backends for writing the image (eg to swap | |
138 | or an NFS share[Work In Progress]). Questions regarding suspend2 | |
139 | should be sent to the mailing list available through the suspend2 | |
140 | website, and not to the Linux Kernel Mailing List. We are working | |
141 | toward merging suspend2 into the mainline kernel. | |
142 | ||
83144186 | 143 | Q: What is the freezing of tasks and why are we using it? |
1da177e4 | 144 | |
83144186 RW |
145 | A: The freezing of tasks is a mechanism by which user space processes and some |
146 | kernel threads are controlled during hibernation or system-wide suspend (on some | |
147 | architectures). See freezing-of-tasks.txt for details. | |
1da177e4 | 148 | |
11d77d0c | 149 | Q: What is the difference between "platform" and "shutdown"? |
1da177e4 LT |
150 | |
151 | A: | |
152 | ||
153 | shutdown: save state in linux, then tell bios to powerdown | |
154 | ||
155 | platform: save state in linux, then tell bios to powerdown and blink | |
156 | "suspended led" | |
157 | ||
11d77d0c JB |
158 | "platform" is actually right thing to do where supported, but |
159 | "shutdown" is most reliable (except on ACPI systems). | |
1da177e4 LT |
160 | |
161 | Q: I do not understand why you have such strong objections to idea of | |
162 | selective suspend. | |
163 | ||
2fe0ae78 ML |
164 | A: Do selective suspend during runtime power management, that's okay. But |
165 | it's useless for suspend-to-disk. (And I do not see how you could use | |
1da177e4 LT |
166 | it for suspend-to-ram, I hope you do not want that). |
167 | ||
168 | Lets see, so you suggest to | |
169 | ||
170 | * SUSPEND all but swap device and parents | |
171 | * Snapshot | |
172 | * Write image to disk | |
173 | * SUSPEND swap device and parents | |
174 | * Powerdown | |
175 | ||
176 | Oh no, that does not work, if swap device or its parents uses DMA, | |
177 | you've corrupted data. You'd have to do | |
178 | ||
179 | * SUSPEND all but swap device and parents | |
180 | * FREEZE swap device and parents | |
181 | * Snapshot | |
182 | * UNFREEZE swap device and parents | |
183 | * Write | |
184 | * SUSPEND swap device and parents | |
185 | ||
186 | Which means that you still need that FREEZE state, and you get more | |
187 | complicated code. (And I have not yet introduce details like system | |
188 | devices). | |
189 | ||
190 | Q: There don't seem to be any generally useful behavioral | |
191 | distinctions between SUSPEND and FREEZE. | |
192 | ||
193 | A: Doing SUSPEND when you are asked to do FREEZE is always correct, | |
b9827e4b | 194 | but it may be unneccessarily slow. If you want your driver to stay simple, |
1da177e4 LT |
195 | slowness may not matter to you. It can always be fixed later. |
196 | ||
197 | For devices like disk it does matter, you do not want to spindown for | |
198 | FREEZE. | |
199 | ||
2fe0ae78 | 200 | Q: After resuming, system is paging heavily, leading to very bad interactivity. |
1da177e4 LT |
201 | |
202 | A: Try running | |
203 | ||
204 | cat `cat /proc/[0-9]*/maps | grep / | sed 's:.* /:/:' | sort -u` > /dev/null | |
205 | ||
a58a414f | 206 | after resume. swapoff -a; swapon -a may also be useful. |
fc5fb2c6 PM |
207 | |
208 | Q: What happens to devices during swsusp? They seem to be resumed | |
209 | during system suspend? | |
210 | ||
211 | A: That's correct. We need to resume them if we want to write image to | |
212 | disk. Whole sequence goes like | |
213 | ||
214 | Suspend part | |
215 | ~~~~~~~~~~~~ | |
216 | running system, user asks for suspend-to-disk | |
217 | ||
218 | user processes are stopped | |
219 | ||
220 | suspend(PMSG_FREEZE): devices are frozen so that they don't interfere | |
221 | with state snapshot | |
222 | ||
223 | state snapshot: copy of whole used memory is taken with interrupts disabled | |
224 | ||
225 | resume(): devices are woken up so that we can write image to swap | |
226 | ||
227 | write image to swap | |
228 | ||
229 | suspend(PMSG_SUSPEND): suspend devices so that we can power off | |
230 | ||
231 | turn the power off | |
232 | ||
233 | Resume part | |
234 | ~~~~~~~~~~~ | |
235 | (is actually pretty similar) | |
236 | ||
237 | running system, user asks for suspend-to-disk | |
238 | ||
239 | user processes are stopped (in common case there are none, but with resume-from-initrd, noone knows) | |
240 | ||
241 | read image from disk | |
242 | ||
243 | suspend(PMSG_FREEZE): devices are frozen so that they don't interfere | |
244 | with image restoration | |
245 | ||
246 | image restoration: rewrite memory with image | |
247 | ||
248 | resume(): devices are woken up so that system can continue | |
249 | ||
250 | thaw all user processes | |
251 | ||
252 | Q: What is this 'Encrypt suspend image' for? | |
253 | ||
254 | A: First of all: it is not a replacement for dm-crypt encrypted swap. | |
255 | It cannot protect your computer while it is suspended. Instead it does | |
256 | protect from leaking sensitive data after resume from suspend. | |
257 | ||
258 | Think of the following: you suspend while an application is running | |
259 | that keeps sensitive data in memory. The application itself prevents | |
260 | the data from being swapped out. Suspend, however, must write these | |
261 | data to swap to be able to resume later on. Without suspend encryption | |
262 | your sensitive data are then stored in plaintext on disk. This means | |
263 | that after resume your sensitive data are accessible to all | |
264 | applications having direct access to the swap device which was used | |
265 | for suspend. If you don't need swap after resume these data can remain | |
266 | on disk virtually forever. Thus it can happen that your system gets | |
267 | broken in weeks later and sensitive data which you thought were | |
268 | encrypted and protected are retrieved and stolen from the swap device. | |
269 | To prevent this situation you should use 'Encrypt suspend image'. | |
270 | ||
271 | During suspend a temporary key is created and this key is used to | |
272 | encrypt the data written to disk. When, during resume, the data was | |
273 | read back into memory the temporary key is destroyed which simply | |
274 | means that all data written to disk during suspend are then | |
275 | inaccessible so they can't be stolen later on. The only thing that | |
276 | you must then take care of is that you call 'mkswap' for the swap | |
277 | partition used for suspend as early as possible during regular | |
278 | boot. This asserts that any temporary key from an oopsed suspend or | |
279 | from a failed or aborted resume is erased from the swap device. | |
280 | ||
281 | As a rule of thumb use encrypted swap to protect your data while your | |
282 | system is shut down or suspended. Additionally use the encrypted | |
283 | suspend image to prevent sensitive data from being stolen after | |
284 | resume. | |
7e958883 | 285 | |
ecbd0da1 | 286 | Q: Can I suspend to a swap file? |
7e958883 | 287 | |
ecbd0da1 RW |
288 | A: Generally, yes, you can. However, it requires you to use the "resume=" and |
289 | "resume_offset=" kernel command line parameters, so the resume from a swap file | |
290 | cannot be initiated from an initrd or initramfs image. See | |
291 | swsusp-and-swap-files.txt for details. | |
d7ae79c7 PM |
292 | |
293 | Q: Is there a maximum system RAM size that is supported by swsusp? | |
294 | ||
295 | A: It should work okay with highmem. | |
296 | ||
297 | Q: Does swsusp (to disk) use only one swap partition or can it use | |
298 | multiple swap partitions (aggregate them into one logical space)? | |
299 | ||
300 | A: Only one swap partition, sorry. | |
301 | ||
302 | Q: If my application(s) causes lots of memory & swap space to be used | |
303 | (over half of the total system RAM), is it correct that it is likely | |
304 | to be useless to try to suspend to disk while that app is running? | |
305 | ||
306 | A: No, it should work okay, as long as your app does not mlock() | |
307 | it. Just prepare big enough swap partition. | |
308 | ||
a58a414f | 309 | Q: What information is useful for debugging suspend-to-disk problems? |
d7ae79c7 PM |
310 | |
311 | A: Well, last messages on the screen are always useful. If something | |
312 | is broken, it is usually some kernel driver, therefore trying with as | |
313 | little as possible modules loaded helps a lot. I also prefer people to | |
314 | suspend from console, preferably without X running. Booting with | |
315 | init=/bin/bash, then swapon and starting suspend sequence manually | |
316 | usually does the trick. Then it is good idea to try with latest | |
317 | vanilla kernel. | |
318 | ||
543cc27d PM |
319 | Q: How can distributions ship a swsusp-supporting kernel with modular |
320 | disk drivers (especially SATA)? | |
321 | ||
322 | A: Well, it can be done, load the drivers, then do echo into | |
323 | /sys/power/disk/resume file from initrd. Be sure not to mount | |
324 | anything, not even read-only mount, or you are going to lose your | |
325 | data. | |
326 | ||
327 | Q: How do I make suspend more verbose? | |
328 | ||
329 | A: If you want to see any non-error kernel messages on the virtual | |
330 | terminal the kernel switches to during suspend, you have to set the | |
e084dbd3 PM |
331 | kernel console loglevel to at least 4 (KERN_WARNING), for example by |
332 | doing | |
333 | ||
334 | # save the old loglevel | |
335 | read LOGLEVEL DUMMY < /proc/sys/kernel/printk | |
336 | # set the loglevel so we see the progress bar. | |
337 | # if the level is higher than needed, we leave it alone. | |
338 | if [ $LOGLEVEL -lt 5 ]; then | |
339 | echo 5 > /proc/sys/kernel/printk | |
340 | fi | |
341 | ||
342 | IMG_SZ=0 | |
343 | read IMG_SZ < /sys/power/image_size | |
344 | echo -n disk > /sys/power/state | |
345 | RET=$? | |
346 | # | |
347 | # the logic here is: | |
348 | # if image_size > 0 (without kernel support, IMG_SZ will be zero), | |
349 | # then try again with image_size set to zero. | |
350 | if [ $RET -ne 0 -a $IMG_SZ -ne 0 ]; then # try again with minimal image size | |
351 | echo 0 > /sys/power/image_size | |
352 | echo -n disk > /sys/power/state | |
353 | RET=$? | |
354 | fi | |
355 | ||
356 | # restore previous loglevel | |
357 | echo $LOGLEVEL > /proc/sys/kernel/printk | |
358 | exit $RET | |
543cc27d PM |
359 | |
360 | Q: Is this true that if I have a mounted filesystem on a USB device and | |
361 | I suspend to disk, I can lose data unless the filesystem has been mounted | |
362 | with "sync"? | |
363 | ||
b9827e4b DB |
364 | A: That's right ... if you disconnect that device, you may lose data. |
365 | In fact, even with "-o sync" you can lose data if your programs have | |
366 | information in buffers they haven't written out to a disk you disconnect, | |
367 | or if you disconnect before the device finished saving data you wrote. | |
543cc27d | 368 | |
b9827e4b DB |
369 | Software suspend normally powers down USB controllers, which is equivalent |
370 | to disconnecting all USB devices attached to your system. | |
371 | ||
372 | Your system might well support low-power modes for its USB controllers | |
373 | while the system is asleep, maintaining the connection, using true sleep | |
374 | modes like "suspend-to-RAM" or "standby". (Don't write "disk" to the | |
375 | /sys/power/state file; write "standby" or "mem".) We've not seen any | |
376 | hardware that can use these modes through software suspend, although in | |
11d77d0c JB |
377 | theory some systems might support "platform" modes that won't break the |
378 | USB connections. | |
543cc27d PM |
379 | |
380 | Remember that it's always a bad idea to unplug a disk drive containing a | |
b9827e4b DB |
381 | mounted filesystem. That's true even when your system is asleep! The |
382 | safest thing is to unmount all filesystems on removable media (such USB, | |
383 | Firewire, CompactFlash, MMC, external SATA, or even IDE hotplug bays) | |
384 | before suspending; then remount them after resuming. | |
d7ae79c7 | 385 | |
0458d5b4 AS |
386 | There is a work-around for this problem. For more information, see |
387 | Documentation/usb/persist.txt. | |
388 | ||
23b168d4 PM |
389 | Q: Can I suspend-to-disk using a swap partition under LVM? |
390 | ||
391 | A: No. You can suspend successfully, but you'll not be able to | |
392 | resume. uswsusp should be able to work with LVM. See suspend.sf.net. | |
393 | ||
e084dbd3 PM |
394 | Q: I upgraded the kernel from 2.6.15 to 2.6.16. Both kernels were |
395 | compiled with the similar configuration files. Anyway I found that | |
396 | suspend to disk (and resume) is much slower on 2.6.16 compared to | |
397 | 2.6.15. Any idea for why that might happen or how can I speed it up? | |
398 | ||
399 | A: This is because the size of the suspend image is now greater than | |
400 | for 2.6.15 (by saving more data we can get more responsive system | |
401 | after resume). | |
402 | ||
403 | There's the /sys/power/image_size knob that controls the size of the | |
404 | image. If you set it to 0 (eg. by echo 0 > /sys/power/image_size as | |
405 | root), the 2.6.15 behavior should be restored. If it is still too | |
406 | slow, take a look at suspend.sf.net -- userland suspend is faster and | |
407 | supports LZF compression to speed it up further. |