📄 swsusp.txt
字号:
cat `cat /proc/[0-9]*/maps | grep / | sed 's:.* /:/:' | sort -u` > /dev/nullafter resume. swapoff -a; swapon -a may also be useful.Q: What happens to devices during swsusp? They seem to be resumedduring system suspend?A: That's correct. We need to resume them if we want to write image todisk. Whole sequence goes like Suspend part ~~~~~~~~~~~~ running system, user asks for suspend-to-disk user processes are stopped suspend(PMSG_FREEZE): devices are frozen so that they don't interfere with state snapshot state snapshot: copy of whole used memory is taken with interrupts disabled resume(): devices are woken up so that we can write image to swap write image to swap suspend(PMSG_SUSPEND): suspend devices so that we can power off turn the power off Resume part ~~~~~~~~~~~ (is actually pretty similar) running system, user asks for suspend-to-disk user processes are stopped (in common case there are none, but with resume-from-initrd, noone knows) read image from disk suspend(PMSG_FREEZE): devices are frozen so that they don't interfere with image restoration image restoration: rewrite memory with image resume(): devices are woken up so that system can continue thaw all user processesQ: What is this 'Encrypt suspend image' for?A: First of all: it is not a replacement for dm-crypt encrypted swap.It cannot protect your computer while it is suspended. Instead it doesprotect from leaking sensitive data after resume from suspend.Think of the following: you suspend while an application is runningthat keeps sensitive data in memory. The application itself preventsthe data from being swapped out. Suspend, however, must write thesedata to swap to be able to resume later on. Without suspend encryptionyour sensitive data are then stored in plaintext on disk. This meansthat after resume your sensitive data are accessible to allapplications having direct access to the swap device which was usedfor suspend. If you don't need swap after resume these data can remainon disk virtually forever. Thus it can happen that your system getsbroken in weeks later and sensitive data which you thought wereencrypted and protected are retrieved and stolen from the swap device.To prevent this situation you should use 'Encrypt suspend image'.During suspend a temporary key is created and this key is used toencrypt the data written to disk. When, during resume, the data wasread back into memory the temporary key is destroyed which simplymeans that all data written to disk during suspend are theninaccessible so they can't be stolen later on. The only thing thatyou must then take care of is that you call 'mkswap' for the swappartition used for suspend as early as possible during regularboot. This asserts that any temporary key from an oopsed suspend orfrom a failed or aborted resume is erased from the swap device.As a rule of thumb use encrypted swap to protect your data while yoursystem is shut down or suspended. Additionally use the encryptedsuspend image to prevent sensitive data from being stolen afterresume.Q: Can I suspend to a swap file?A: Generally, yes, you can. However, it requires you to use the "resume=" and"resume_offset=" kernel command line parameters, so the resume from a swap filecannot be initiated from an initrd or initramfs image. Seeswsusp-and-swap-files.txt for details.Q: Is there a maximum system RAM size that is supported by swsusp?A: It should work okay with highmem.Q: Does swsusp (to disk) use only one swap partition or can it usemultiple swap partitions (aggregate them into one logical space)?A: Only one swap partition, sorry.Q: If my application(s) causes lots of memory & swap space to be used(over half of the total system RAM), is it correct that it is likelyto be useless to try to suspend to disk while that app is running?A: No, it should work okay, as long as your app does not mlock()it. Just prepare big enough swap partition.Q: What information is useful for debugging suspend-to-disk problems?A: Well, last messages on the screen are always useful. If somethingis broken, it is usually some kernel driver, therefore trying with aslittle as possible modules loaded helps a lot. I also prefer people tosuspend from console, preferably without X running. Booting withinit=/bin/bash, then swapon and starting suspend sequence manuallyusually does the trick. Then it is good idea to try with latestvanilla kernel.Q: How can distributions ship a swsusp-supporting kernel with modulardisk drivers (especially SATA)?A: Well, it can be done, load the drivers, then do echo into/sys/power/disk/resume file from initrd. Be sure not to mountanything, not even read-only mount, or you are going to lose yourdata.Q: How do I make suspend more verbose?A: If you want to see any non-error kernel messages on the virtualterminal the kernel switches to during suspend, you have to set thekernel console loglevel to at least 4 (KERN_WARNING), for example bydoing # save the old loglevel read LOGLEVEL DUMMY < /proc/sys/kernel/printk # set the loglevel so we see the progress bar. # if the level is higher than needed, we leave it alone. if [ $LOGLEVEL -lt 5 ]; then echo 5 > /proc/sys/kernel/printk fi IMG_SZ=0 read IMG_SZ < /sys/power/image_size echo -n disk > /sys/power/state RET=$? # # the logic here is: # if image_size > 0 (without kernel support, IMG_SZ will be zero), # then try again with image_size set to zero. if [ $RET -ne 0 -a $IMG_SZ -ne 0 ]; then # try again with minimal image size echo 0 > /sys/power/image_size echo -n disk > /sys/power/state RET=$? fi # restore previous loglevel echo $LOGLEVEL > /proc/sys/kernel/printk exit $RETQ: Is this true that if I have a mounted filesystem on a USB device andI suspend to disk, I can lose data unless the filesystem has been mountedwith "sync"?A: That's right ... if you disconnect that device, you may lose data.In fact, even with "-o sync" you can lose data if your programs haveinformation in buffers they haven't written out to a disk you disconnect,or if you disconnect before the device finished saving data you wrote.Software suspend normally powers down USB controllers, which is equivalentto disconnecting all USB devices attached to your system.Your system might well support low-power modes for its USB controllerswhile the system is asleep, maintaining the connection, using true sleepmodes like "suspend-to-RAM" or "standby". (Don't write "disk" to the/sys/power/state file; write "standby" or "mem".) We've not seen anyhardware that can use these modes through software suspend, although intheory some systems might support "platform" modes that won't break theUSB connections.Remember that it's always a bad idea to unplug a disk drive containing amounted filesystem. That's true even when your system is asleep! Thesafest thing is to unmount all filesystems on removable media (such USB,Firewire, CompactFlash, MMC, external SATA, or even IDE hotplug bays)before suspending; then remount them after resuming.There is a work-around for this problem. For more information, seeDocumentation/usb/persist.txt.Q: I upgraded the kernel from 2.6.15 to 2.6.16. Both kernels werecompiled with the similar configuration files. Anyway I found thatsuspend to disk (and resume) is much slower on 2.6.16 compared to2.6.15. Any idea for why that might happen or how can I speed it up?A: This is because the size of the suspend image is now greater thanfor 2.6.15 (by saving more data we can get more responsive systemafter resume).There's the /sys/power/image_size knob that controls the size of theimage. If you set it to 0 (eg. by echo 0 > /sys/power/image_size asroot), the 2.6.15 behavior should be restored. If it is still tooslow, take a look at suspend.sf.net -- userland suspend is faster andsupports LZF compression to speed it up further.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -