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