← Documents Documentation/mm/swap-table.rst GitHub 원문 ↗

Linux 6.18.37 · Memory management

Swap Table

Swap entry 인코딩, swap-cache 값 상태와 cluster별 배열의 조회·잠금 규칙을 설명합니다.

Source pathDocumentation/mm/swap-table.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

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

1. 요약·해설

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

요약·해설

swap-table.rst:1-69

Swap table은 이미 swap in·out 경로가 알고 있는 cluster를 활용해 swap cache를 cluster별 pointer 배열로 바꿉니다. Tree인 XArray의 여러 node를 거치지 않아 locality와 속도가 좋아지며, 수정에는 명확한 folio→cluster lock 순서가 적용됩니다.

Swap entry에서 cache 값까지
Swap entrySwap typeSwap device 선택Swap offsetSwap file page 위치
Swap entrySwap clusterSwap table indexCache value

Type과 offset으로 device·위치를 결정한 뒤 cluster 안의 값을 조회합니다.

Swap-cache 값의 세 상태
상태Data 위치
`NULL`Entry 미사용없음
`folio`Swap in/out 중 일시 상태Folio, swap file 또는 둘 다
`shadow`Swap out 정상 상태Working-set 정보

Entry 생명주기에 따라 조회 결과의 의미가 달라집니다.

XArray와 swap table 조회
구조조회 경로특성
XArrayTree의 여러 node간접 접근이 많음
Swap tableCluster 내부 array index단순하고 locality가 높음

Cluster를 이미 알고 있다는 특성을 배열 조회에 활용합니다.

Swap table 잠금 순서
Folio 추가·제거Folio lockCluster lockTable 수정Folio unlock
조회RCU + atomic readFolio 반환사용 전 folio lock

수정과 조회는 서로 다른 동기화 규칙을 사용합니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 :Author: Chris Li <[email protected]>, Kairui Song <[email protected]>
4
5 ==========
6 Swap Table
7 ==========
8
9 Swap table implements swap cache as a per-cluster swap cache value array.
10
11 Swap Entry
12 ----------
13
14 A swap entry contains the information required to serve the anonymous page
15 fault.
16
17 Swap entry is encoded as two parts: swap type and swap offset.
18
19 The swap type indicates which swap device to use.
20 The swap offset is the offset of the swap file to read the page data from.
21
22 Swap Cache
23 ----------
24
25 Swap cache is a map to look up folios using swap entry as the key. The result
26 value can have three possible types depending on which stage of this swap entry
27 was in.
28
29 1. NULL: This swap entry is not used.
30
31 2. folio: A folio has been allocated and bound to this swap entry. This is
32 the transient state of swap out or swap in. The folio data can be in
33 the folio or swap file, or both.
34
35 3. shadow: The shadow contains the working set information of the swapped
36 out folio. This is the normal state for a swapped out page.
37
38 Swap Table Internals
39 --------------------
40
41 The previous swap cache is implemented by XArray. The XArray is a tree
42 structure. Each lookup will go through multiple nodes. Can we do better?
43
44 Notice that most of the time when we look up the swap cache, we are either
45 in a swap in or swap out path. We should already have the swap cluster,
46 which contains the swap entry.
47
48 If we have a per-cluster array to store swap cache value in the cluster.
49 Swap cache lookup within the cluster can be a very simple array lookup.
50
51 We give such a per-cluster swap cache value array a name: the swap table.
52
53 A swap table is an array of pointers. Each pointer is the same size as a
54 PTE. The size of a swap table for one swap cluster typically matches a PTE
55 page table, which is one page on modern 64-bit systems.
56
57 With swap table, swap cache lookup can achieve great locality, simpler,
58 and faster.
59
60 Locking
61 -------
62
63 Swap table modification requires taking the cluster lock. If a folio
64 is being added to or removed from the swap table, the folio must be
65 locked prior to the cluster lock. After adding or removing is done, the
66 folio shall be unlocked.
67
68 Swap table lookup is protected by RCU and atomic read. If the lookup
69 returns a folio, the user must lock the folio before use.
70

3. 한국어 전문 번역

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

Swap table과 swap entry

1-16

저자: Chris Li <[email protected]>, Kairui Song <[email protected]>

Swap Table

Swap table은 swap cache를 cluster별 swap-cache 값 배열로 구현합니다.

Swap Entry

swap entry에는 anonymous page fault를 처리하는 데 필요한 정보가 들어 있습니다.

.. SPDX-License-Identifier: GPL-2.0

:Author: Chris Li <[email protected]>, Kairui Song <[email protected]>

==========
Swap Table
==========

Swap table implements swap cache as a per-cluster swap cache value array.

Swap Entry
----------

A swap entry contains the information required to serve the anonymous page
fault.

Swap entry 인코딩과 cache 상태

17-35

swap entry는 swap type과 swap offset의 두 부분으로 인코딩됩니다. swap type은 사용할 swap device를 나타내고, swap offset은 page data를 읽을 swap file의 오프셋입니다.

Swap cache는 swap entry를 key로 사용해 folio를 찾는 map입니다. 조회 값은 해당 swap entry가 놓인 단계에 따라 세 종류가 될 수 있습니다.

  • `NULL`: 이 swap entry는 사용되지 않습니다.
  • `folio`: folio가 할당되어 이 swap entry에 결합된 상태입니다. swap out 또는 swap in의 일시적 상태이며 data는 folio, swap file 또는 둘 모두에 있을 수 있습니다.
  • `shadow`: swap out된 folio의 working-set 정보를 담습니다. swap out된 page의 정상 상태입니다.
Swap entry is encoded as two parts: swap type and swap offset.

The swap type indicates which swap device to use.
The swap offset is the offset of the swap file to read the page data from.

Swap Cache
----------

Swap cache is a map to look up folios using swap entry as the key. The result
value can have three possible types depending on which stage of this swap entry
was in.

1. NULL: This swap entry is not used.

2. folio: A folio has been allocated and bound to this swap entry. This is
   the transient state of swap out or swap in. The folio data can be in
   the folio or swap file, or both.

3. shadow: The shadow contains the working set information of the swapped

XArray에서 cluster 배열로

36-57

Swap Table 내부 구조

이전 swap cache는 tree 구조인 XArray로 구현되어 조회할 때마다 여러 node를 거쳤습니다. 그러나 대부분의 swap-cache 조회는 swap in 또는 swap out 경로에서 일어나므로, 호출 경로는 이미 swap entry를 포함한 swap cluster를 알고 있습니다.

cluster 안에 swap-cache 값을 저장하는 cluster별 배열이 있으면 조회는 단순한 배열 접근이 됩니다. 이 배열을 swap table이라 부릅니다.

swap table은 pointer 배열이며 각 pointer의 크기는 PTE와 같습니다. swap cluster 하나의 swap table 크기는 보통 PTE page table 하나와 같고, 현대 64비트 시스템에서는 page 하나입니다.

이 구조는 swap-cache 조회의 locality를 높이고 구현을 단순화하며 속도를 높입니다.

   out folio. This is the normal state for a swapped out page.

Swap Table Internals
--------------------

The previous swap cache is implemented by XArray. The XArray is a tree
structure. Each lookup will go through multiple nodes. Can we do better?

Notice that most of the time when we look up the swap cache, we are either
in a swap in or swap out path. We should already have the swap cluster,
which contains the swap entry.

If we have a per-cluster array to store swap cache value in the cluster.
Swap cache lookup within the cluster can be a very simple array lookup.

We give such a per-cluster swap cache value array a name: the swap table.

A swap table is an array of pointers. Each pointer is the same size as a
PTE. The size of a swap table for one swap cluster typically matches a PTE
page table, which is one page on modern 64-bit systems.

With swap table, swap cache lookup can achieve great locality, simpler,

수정과 조회의 잠금 규칙

58-69

잠금

swap table을 수정하려면 cluster lock을 획득해야 합니다. folio를 table에 추가하거나 제거할 때는 folio lock을 cluster lock보다 먼저 획득하고, 작업이 끝난 뒤 folio lock을 해제해야 합니다.

swap table 조회는 RCU와 atomic read로 보호됩니다. 조회 결과가 folio라면 사용자는 그 folio를 쓰기 전에 반드시 잠가야 합니다.

and faster.

Locking
-------

Swap table modification requires taking the cluster lock. If a folio
is being added to or removed from the swap table, the folio must be
locked prior to the cluster lock. After adding or removing is done, the
folio shall be unlocked.

Swap table lookup is protected by RCU and atomic read. If the lookup
returns a folio, the user must lock the folio before use.