📄 swsusp.txt
字号:
Some warnings, first. * BIG FAT WARNING ********************************************************* * * If you touch anything on disk between suspend and resume... * ...kiss your data goodbye. * * If you do resume from initrd after your filesystems are mounted... * ...bye bye root partition. * [this is actually same case as above] * * If you have unsupported (*) devices using DMA, you may have some * problems. If your disk driver does not support suspend... (IDE does), * it may cause some problems, too. If you change kernel command line * between suspend and resume, it may do something wrong. If you change * your hardware while system is suspended... well, it was not good idea; * but it will probably only crash. * * (*) suspend/resume support is needed to make it safe. * * If you have any filesystems on USB devices mounted before software suspend, * they won't be accessible after resume and you may lose data, as though * you have unplugged the USB devices with mounted filesystems on them; * see the FAQ below for details. (This is not true for more traditional * power states like "standby", which normally don't turn USB off.)You need to append resume=/dev/your_swap_partition to kernel commandline. Then you suspend byecho shutdown > /sys/power/disk; echo disk > /sys/power/state. If you feel ACPI works pretty well on your system, you might tryecho platform > /sys/power/disk; echo disk > /sys/power/state. If you have SATA disks, you'll need recent kernels with SATA suspendsupport. For suspend and resume to work, make sure your disk driversare built into kernel -- not modules. [There's way to makesuspend/resume with modular disk drivers, see FAQ, but you probablyshould not do that.]If you want to limit the suspend image size to N bytes, doecho N > /sys/power/image_sizebefore suspend (it is limited to 500 MB by default).Article about goals and implementation of Software Suspend for Linux~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Author: Gábor KutiLast revised: 2003-10-20 by Pavel MachekIdea and goals to achieveNowadays it is common in several laptops that they have a suspend button. Itsaves the state of the machine to a filesystem or to a partition and switchesto standby mode. Later resuming the machine the saved state is loaded back toram and the machine can continue its work. It has two real benefits. First wesave ourselves the time machine goes down and later boots up, energy costsare real high when running from batteries. The other gain is that we don't have tointerrupt our programs so processes that are calculating something for a longtime shouldn't need to be written interruptible.swsusp saves the state of the machine into active swaps and then reboots orpowerdowns. You must explicitly specify the swap partition to resume from with``resume='' kernel option. If signature is found it loads and restores savedstate. If the option ``noresume'' is specified as a boot parameter, it skipsthe resuming.In the meantime while the system is suspended you should not add/remove anyof the hardware, write to the filesystems, etc.Sleep states summary====================There are three different interfaces you can use, /proc/acpi shouldwork like this:In a really perfect world:echo 1 > /proc/acpi/sleep # for standbyecho 2 > /proc/acpi/sleep # for suspend to ramecho 3 > /proc/acpi/sleep # for suspend to ram, but with more power conservativeecho 4 > /proc/acpi/sleep # for suspend to diskecho 5 > /proc/acpi/sleep # for shutdown unfriendly the systemand perhapsecho 4b > /proc/acpi/sleep # for suspend to disk via s4biosFrequently Asked Questions==========================Q: well, suspending a server is IMHO a really stupid thing,but... (Diego Zuccato):A: You bought new UPS for your server. How do you install it withoutbringing machine down? Suspend to disk, rearrange power cables,resume.You have your server on UPS. Power died, and UPS is indicating 30seconds to failure. What do you do? Suspend to disk.Q: Maybe I'm missing something, but why don't the regular I/O paths work?A: We do use the regular I/O paths. However we cannot restore the datato its original location as we load it. That would create aninconsistent kernel state which would certainly result in an oops.Instead, we load the image into unused memory and then atomically copyit back to it original location. This implies, of course, a maximumimage size of half the amount of memory.There are two solutions to this:* require half of memory to be free during suspend. That way you canread "new" data onto free spots, then cli and copy* assume we had special "polling" ide driver that only uses memorybetween 0-640KB. That way, I'd have to make sure that 0-640KB is freeduring suspending, but otherwise it would work...suspend2 shares this fundamental limitation, but does not include userdata and disk caches into "used memory" by saving them inadvance. That means that the limitation goes away in practice.Q: Does linux support ACPI S4?A: Yes. That's what echo platform > /sys/power/disk does.Q: What is 'suspend2'?A: suspend2 is 'Software Suspend 2', a forked implementation ofsuspend-to-disk which is available as separate patches for 2.4 and 2.6kernels from swsusp.sourceforge.net. It includes support for SMP, 4GBhighmem and preemption. It also has a extensible architecture thatallows for arbitrary transformations on the image (compression,encryption) and arbitrary backends for writing the image (eg to swapor an NFS share[Work In Progress]). Questions regarding suspend2should be sent to the mailing list available through the suspend2website, and not to the Linux Kernel Mailing List. We are workingtoward merging suspend2 into the mainline kernel.Q: What is the freezing of tasks and why are we using it?A: The freezing of tasks is a mechanism by which user space processes and somekernel threads are controlled during hibernation or system-wide suspend (on somearchitectures). See freezing-of-tasks.txt for details.Q: What is the difference between "platform" and "shutdown"?A:shutdown: save state in linux, then tell bios to powerdownplatform: save state in linux, then tell bios to powerdown and blink "suspended led""platform" is actually right thing to do where supported, but"shutdown" is most reliable (except on ACPI systems).Q: I do not understand why you have such strong objections to idea ofselective suspend.A: Do selective suspend during runtime power management, that's okay. Butit's useless for suspend-to-disk. (And I do not see how you could useit for suspend-to-ram, I hope you do not want that).Lets see, so you suggest to* SUSPEND all but swap device and parents* Snapshot* Write image to disk* SUSPEND swap device and parents* PowerdownOh no, that does not work, if swap device or its parents uses DMA,you've corrupted data. You'd have to do* SUSPEND all but swap device and parents* FREEZE swap device and parents* Snapshot* UNFREEZE swap device and parents* Write* SUSPEND swap device and parentsWhich means that you still need that FREEZE state, and you get morecomplicated code. (And I have not yet introduce details like systemdevices).Q: There don't seem to be any generally useful behavioraldistinctions between SUSPEND and FREEZE.A: Doing SUSPEND when you are asked to do FREEZE is always correct,but it may be unneccessarily slow. If you want your driver to stay simple,slowness may not matter to you. It can always be fixed later.For devices like disk it does matter, you do not want to spindown forFREEZE.Q: After resuming, system is paging heavily, leading to very bad interactivity.A: Try running
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -