swsusp-and-swap-files.txt 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. Using swap files with software suspend (swsusp)
  2. (C) 2006 Rafael J. Wysocki <rjw@sisk.pl>
  3. The Linux kernel handles swap files almost in the same way as it handles swap
  4. partitions and there are only two differences between these two types of swap
  5. areas:
  6. (1) swap files need not be contiguous,
  7. (2) the header of a swap file is not in the first block of the partition that
  8. holds it. From the swsusp's point of view (1) is not a problem, because it is
  9. already taken care of by the swap-handling code, but (2) has to be taken into
  10. consideration.
  11. In principle the location of a swap file's header may be determined with the
  12. help of appropriate filesystem driver. Unfortunately, however, it requires the
  13. filesystem holding the swap file to be mounted, and if this filesystem is
  14. journaled, it cannot be mounted during resume from disk. For this reason to
  15. identify a swap file swsusp uses the name of the partition that holds the file
  16. and the offset from the beginning of the partition at which the swap file's
  17. header is located. For convenience, this offset is expressed in <PAGE_SIZE>
  18. units.
  19. In order to use a swap file with swsusp, you need to:
  20. 1) Create the swap file and make it active, eg.
  21. # dd if=/dev/zero of=<swap_file_path> bs=1024 count=<swap_file_size_in_k>
  22. # mkswap <swap_file_path>
  23. # swapon <swap_file_path>
  24. 2) Use an application that will bmap the swap file with the help of the
  25. FIBMAP ioctl and determine the location of the file's swap header, as the
  26. offset, in <PAGE_SIZE> units, from the beginning of the partition which
  27. holds the swap file.
  28. 3) Add the following parameters to the kernel command line:
  29. resume=<swap_file_partition> resume_offset=<swap_file_offset>
  30. where <swap_file_partition> is the partition on which the swap file is located
  31. and <swap_file_offset> is the offset of the swap header determined by the
  32. application in 2) (of course, this step may be carried out automatically
  33. by the same application that determines the swap file's header offset using the
  34. FIBMAP ioctl)
  35. OR
  36. Use a userland suspend application that will set the partition and offset
  37. with the help of the SNAPSHOT_SET_SWAP_AREA ioctl described in
  38. Documentation/power/userland-swsusp.txt (this is the only method to suspend
  39. to a swap file allowing the resume to be initiated from an initrd or initramfs
  40. image).
  41. Now, swsusp will use the swap file in the same way in which it would use a swap
  42. partition. In particular, the swap file has to be active (ie. be present in
  43. /proc/swaps) so that it can be used for suspending.
  44. Note that if the swap file used for suspending is deleted and recreated,
  45. the location of its header need not be the same as before. Thus every time
  46. this happens the value of the "resume_offset=" kernel command line parameter
  47. has to be updated.