1*151f4e2bSMauro Carvalho Chehab=============================================== 2ecbd0da1SRafael J. WysockiUsing swap files with software suspend (swsusp) 3*151f4e2bSMauro Carvalho Chehab=============================================== 4*151f4e2bSMauro Carvalho Chehab 5ecbd0da1SRafael J. Wysocki (C) 2006 Rafael J. Wysocki <rjw@sisk.pl> 6ecbd0da1SRafael J. Wysocki 7ecbd0da1SRafael J. WysockiThe Linux kernel handles swap files almost in the same way as it handles swap 8ecbd0da1SRafael J. Wysockipartitions and there are only two differences between these two types of swap 9ecbd0da1SRafael J. Wysockiareas: 10ecbd0da1SRafael J. Wysocki(1) swap files need not be contiguous, 11ecbd0da1SRafael J. Wysocki(2) the header of a swap file is not in the first block of the partition that 12ecbd0da1SRafael J. Wysockiholds it. From the swsusp's point of view (1) is not a problem, because it is 13ecbd0da1SRafael J. Wysockialready taken care of by the swap-handling code, but (2) has to be taken into 14ecbd0da1SRafael J. Wysockiconsideration. 15ecbd0da1SRafael J. Wysocki 16ecbd0da1SRafael J. WysockiIn principle the location of a swap file's header may be determined with the 17ecbd0da1SRafael J. Wysockihelp of appropriate filesystem driver. Unfortunately, however, it requires the 18ecbd0da1SRafael J. Wysockifilesystem holding the swap file to be mounted, and if this filesystem is 19ecbd0da1SRafael J. Wysockijournaled, it cannot be mounted during resume from disk. For this reason to 20ecbd0da1SRafael J. Wysockiidentify a swap file swsusp uses the name of the partition that holds the file 21ecbd0da1SRafael J. Wysockiand the offset from the beginning of the partition at which the swap file's 22ecbd0da1SRafael J. Wysockiheader is located. For convenience, this offset is expressed in <PAGE_SIZE> 23ecbd0da1SRafael J. Wysockiunits. 24ecbd0da1SRafael J. Wysocki 25ecbd0da1SRafael J. WysockiIn order to use a swap file with swsusp, you need to: 26ecbd0da1SRafael J. Wysocki 27*151f4e2bSMauro Carvalho Chehab1) Create the swap file and make it active, eg.:: 28ecbd0da1SRafael J. Wysocki 29ecbd0da1SRafael J. Wysocki # dd if=/dev/zero of=<swap_file_path> bs=1024 count=<swap_file_size_in_k> 30ecbd0da1SRafael J. Wysocki # mkswap <swap_file_path> 31ecbd0da1SRafael J. Wysocki # swapon <swap_file_path> 32ecbd0da1SRafael J. Wysocki 33ecbd0da1SRafael J. Wysocki2) Use an application that will bmap the swap file with the help of the 34ecbd0da1SRafael J. WysockiFIBMAP ioctl and determine the location of the file's swap header, as the 35ecbd0da1SRafael J. Wysockioffset, in <PAGE_SIZE> units, from the beginning of the partition which 36ecbd0da1SRafael J. Wysockiholds the swap file. 37ecbd0da1SRafael J. Wysocki 38*151f4e2bSMauro Carvalho Chehab3) Add the following parameters to the kernel command line:: 39ecbd0da1SRafael J. Wysocki 40ecbd0da1SRafael J. Wysocki resume=<swap_file_partition> resume_offset=<swap_file_offset> 41ecbd0da1SRafael J. Wysocki 42ecbd0da1SRafael J. Wysockiwhere <swap_file_partition> is the partition on which the swap file is located 43ecbd0da1SRafael J. Wysockiand <swap_file_offset> is the offset of the swap header determined by the 44bf73bae6SRafael J. Wysockiapplication in 2) (of course, this step may be carried out automatically 4501dd2fbfSMatt LaPlanteby the same application that determines the swap file's header offset using the 46bf73bae6SRafael J. WysockiFIBMAP ioctl) 47bf73bae6SRafael J. Wysocki 48bf73bae6SRafael J. WysockiOR 49bf73bae6SRafael J. Wysocki 50bf73bae6SRafael J. WysockiUse a userland suspend application that will set the partition and offset 51bf73bae6SRafael J. Wysockiwith the help of the SNAPSHOT_SET_SWAP_AREA ioctl described in 52*151f4e2bSMauro Carvalho ChehabDocumentation/power/userland-swsusp.rst (this is the only method to suspend 53bf73bae6SRafael J. Wysockito a swap file allowing the resume to be initiated from an initrd or initramfs 54bf73bae6SRafael J. Wysockiimage). 55ecbd0da1SRafael J. Wysocki 56ecbd0da1SRafael J. WysockiNow, swsusp will use the swap file in the same way in which it would use a swap 57bf73bae6SRafael J. Wysockipartition. In particular, the swap file has to be active (ie. be present in 58bf73bae6SRafael J. Wysocki/proc/swaps) so that it can be used for suspending. 59ecbd0da1SRafael J. Wysocki 60ecbd0da1SRafael J. WysockiNote that if the swap file used for suspending is deleted and recreated, 61ecbd0da1SRafael J. Wysockithe location of its header need not be the same as before. Thus every time 62ecbd0da1SRafael J. Wysockithis happens the value of the "resume_offset=" kernel command line parameter 63ecbd0da1SRafael J. Wysockihas to be updated. 64