← Documents Documentation/power/swsusp-and-swap-files.rst GitHub 원문 ↗

Linux 6.18.37 · Power

Using swap files with software suspend (swsusp)

Swap file header offset을 찾아 resume parameter 또는 snapshot ioctl로 swsusp에 사용하는 절차입니다.

Source pathDocumentation/power/swsusp-and-swap-files.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

swsusp-and-swap-files.rst:1-63

Swap file header offset을 찾아 resume parameter 또는 snapshot ioctl로 swsusp에 사용하는 절차입니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

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

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

Swap file header 위치

1-24

Linux kernel은 swap file과 swap partition을 거의 같게 처리하지만 두 차이가 있습니다. Swap file은 연속 공간일 필요가 없고, header가 이를 담는 partition의 첫 block에 있지 않습니다.

비연속성은 swap code가 이미 처리하므로 swsusp 문제가 아닙니다. 그러나 header 위치는 알아야 합니다. Filesystem driver로 찾으려면 filesystem을 mount해야 하는데 journaled filesystem은 resume-from-disk 중 mount할 수 없습니다.

따라서 swsusp는 swap file이 있는 partition 이름과 partition 시작점에서 swap header까지의 offset으로 file을 식별합니다. Offset은 편의상 `<PAGE_SIZE>` 단위입니다.

Swap file 식별
swap file partitionpartition startPAGE_SIZE-unit offsetswap file header

Filesystem mount 없이 resume image header를 찾습니다.

===============================================
Using swap files with software suspend (swsusp)
===============================================

        (C) 2006 Rafael J. Wysocki <[email protected]>

The Linux kernel handles swap files almost in the same way as it handles swap
partitions and there are only two differences between these two types of swap
areas:
(1) swap files need not be contiguous,
(2) the header of a swap file is not in the first block of the partition that
holds it.  From the swsusp's point of view (1) is not a problem, because it is
already taken care of by the swap-handling code, but (2) has to be taken into
consideration.

In principle the location of a swap file's header may be determined with the
help of appropriate filesystem driver.  Unfortunately, however, it requires the
filesystem holding the swap file to be mounted, and if this filesystem is
journaled, it cannot be mounted during resume from disk.  For this reason to
identify a swap file swsusp uses the name of the partition that holds the file
and the offset from the beginning of the partition at which the swap file's
header is located.  For convenience, this offset is expressed in <PAGE_SIZE>
units.

Swap file 생성과 kernel parameter

25-47

먼저 `dd`로 swap file을 만들고 `mkswap`, `swapon`으로 활성화합니다. 그런 다음 `FIBMAP` ioctl을 사용하는 application으로 file을 bmap해 partition 시작점에서 header까지의 `<PAGE_SIZE>` 단위 offset을 구합니다.

Kernel command line에는 `resume=<swap_file_partition> resume_offset=<swap_file_offset>`을 추가합니다. 같은 application이 FIBMAP 결과를 이용해 이 설정을 자동화할 수도 있습니다.

Swap file suspend 설정
항목
swap_file_partitionswap file을 담은 block partition
swap_file_offsetpartition 시작 기준 swap header offset
offset 단위PAGE_SIZE
kernel parameterresume=... resume_offset=...

세 값의 단위와 역할을 혼동하지 않아야 합니다.

In order to use a swap file with swsusp, you need to:

1) Create the swap file and make it active, eg.::

    # dd if=/dev/zero of=<swap_file_path> bs=1024 count=<swap_file_size_in_k>
    # mkswap <swap_file_path>
    # swapon <swap_file_path>

2) Use an application that will bmap the swap file with the help of the
FIBMAP ioctl and determine the location of the file's swap header, as the
offset, in <PAGE_SIZE> units, from the beginning of the partition which
holds the swap file.

3) Add the following parameters to the kernel command line::

    resume=<swap_file_partition> resume_offset=<swap_file_offset>

where <swap_file_partition> is the partition on which the swap file is located
and <swap_file_offset> is the offset of the swap header determined by the
application in 2) (of course, this step may be carried out automatically
by the same application that determines the swap file's header offset using the
FIBMAP ioctl)

Userspace ioctl과 offset 갱신

48-63

대안으로 userspace suspend application이 `Documentation/power/userland-swsusp.rst`의 `SNAPSHOT_SET_SWAP_AREA` ioctl로 partition과 offset을 설정할 수 있습니다. Initrd 또는 initramfs image에서 resume을 시작하면서 swap file에 suspend할 수 있는 유일한 방법입니다.

설정 뒤 swsusp는 swap partition과 같은 방식으로 file을 사용합니다. Suspend 시 swap file은 `/proc/swaps`에 나타나는 active 상태여야 합니다.

Suspend용 swap file을 삭제하고 다시 만들면 header 위치가 달라질 수 있으므로 그때마다 `resume_offset=` kernel parameter를 갱신해야 합니다.

Resume 설정 방식
방식용도
resume + resume_offset일반 kernel command line
SNAPSHOT_SET_SWAP_AREAuserspace suspend, initrd/initramfs resume

Boot 환경에 따라 command line 또는 snapshot ioctl을 선택합니다.

OR

Use a userland suspend application that will set the partition and offset
with the help of the SNAPSHOT_SET_SWAP_AREA ioctl described in
Documentation/power/userland-swsusp.rst (this is the only method to suspend
to a swap file allowing the resume to be initiated from an initrd or initramfs
image).

Now, swsusp will use the swap file in the same way in which it would use a swap
partition.  In particular, the swap file has to be active (ie. be present in
/proc/swaps) so that it can be used for suspending.

Note that if the swap file used for suspending is deleted and recreated,
the location of its header need not be the same as before.  Thus every time
this happens the value of the "resume_offset=" kernel command line parameter
has to be updated.