← Documents Documentation/mm/highmem.rst GitHub 원문 ↗

Linux 6.18.37 · Memory management

High Memory Handling

Highmem 경계, i386 3:1 주소 공간, local·atomic·global 임시 mapping API와 PAE 비용을 설명합니다.

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

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

1. 요약·해설

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

요약·해설

highmem.rst:1-213

Highmem은 커널의 영구 virtual mapping이 덮지 못하는 물리 메모리입니다. 필요한 page에 임시 mapping을 만들되, 현대 코드는 짧은 thread-local 사용에 `kmap_local_page()` 또는 `kmap_local_folio()`를 우선하고 deprecated된 `kmap_atomic()`과 `kmap()`을 피해야 합니다.

i386 가상 주소 공간
주소용도비고
0xc0000000–0xffffffffKernel 1 GiB임시 map 등도 포함
0x00000000–0xbfffffffUser 3 GiB프로세스 사용자 공간
실제 direct map약 896 MiB커널 1 GiB보다 작음

전통적인 3:1 분할과 실제 direct-map 한계를 나타냅니다.

Temporary mapping API 선택
API범위·기간상태·제약
`kmap_local_page()` / `kmap_local_folio()`한 thread·CPU, 단기기본 권장, interrupt 가능
`kmap_atomic()`CPU-local, 매우 단기Deprecated, fault·preemption 부수 효과
`kmap()`page 하나, 더 넓은 contextDeprecated, global lock·TLB 비용
`vmap()`여러 page, 장기연속 가상 공간, unmap global sync

Mapping 기간과 pointer 유효 범위에 따른 권장 선택입니다.

Local mapping 사용 규칙
kmap_local_*()같은 thread에서 pointer 사용중첩 시 LIFO 순서 유지kunmap_local()

반환 pointer를 획득한 thread 밖으로 넘기지 않고 stack 순서로 해제합니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 ====================
2 High Memory Handling
3 ====================
4
5 By: Peter Zijlstra <[email protected]>
6
7 .. contents:: :local:
8
9 What Is High Memory?
10 ====================
11
12 High memory (highmem) is used when the size of physical memory approaches or
13 exceeds the maximum size of virtual memory. At that point it becomes
14 impossible for the kernel to keep all of the available physical memory mapped
15 at all times. This means the kernel needs to start using temporary mappings of
16 the pieces of physical memory that it wants to access.
17
18 The part of (physical) memory not covered by a permanent mapping is what we
19 refer to as 'highmem'. There are various architecture dependent constraints on
20 where exactly that border lies.
21
22 In the i386 arch, for example, we choose to map the kernel into every process's
23 VM space so that we don't have to pay the full TLB invalidation costs for
24 kernel entry/exit. This means the available virtual memory space (4GiB on
25 i386) has to be divided between user and kernel space.
26
27 The traditional split for architectures using this approach is 3:1, 3GiB for
28 userspace and the top 1GiB for kernel space::
29
30 +--------+ 0xffffffff
31 | Kernel |
32 +--------+ 0xc0000000
33 | |
34 | User |
35 | |
36 +--------+ 0x00000000
37
38 This means that the kernel can at most map 1GiB of physical memory at any one
39 time, but because we need virtual address space for other things - including
40 temporary maps to access the rest of the physical memory - the actual direct
41 map will typically be less (usually around ~896MiB).
42
43 Other architectures that have mm context tagged TLBs can have separate kernel
44 and user maps. Some hardware (like some ARMs), however, have limited virtual
45 space when they use mm context tags.
46
47
48 Temporary Virtual Mappings
49 ==========================
50
51 The kernel contains several ways of creating temporary mappings. The following
52 list shows them in order of preference of use.
53
54 * kmap_local_page(), kmap_local_folio() - These functions are used to create
55 short term mappings. They can be invoked from any context (including
56 interrupts) but the mappings can only be used in the context which acquired
57 them. The only differences between them consist in the first taking a pointer
58 to a struct page and the second taking a pointer to struct folio and the byte
59 offset within the folio which identifies the page.
60
61 These functions should always be used, whereas kmap_atomic() and kmap() have
62 been deprecated.
63
64 These mappings are thread-local and CPU-local, meaning that the mapping
65 can only be accessed from within this thread and the thread is bound to the
66 CPU while the mapping is active. Although preemption is never disabled by
67 this function, the CPU can not be unplugged from the system via
68 CPU-hotplug until the mapping is disposed.
69
70 It's valid to take pagefaults in a local kmap region, unless the context
71 in which the local mapping is acquired does not allow it for other reasons.
72
73 As said, pagefaults and preemption are never disabled. There is no need to
74 disable preemption because, when context switches to a different task, the
75 maps of the outgoing task are saved and those of the incoming one are
76 restored.
77
78 kmap_local_page(), as well as kmap_local_folio() always returns valid virtual
79 kernel addresses and it is assumed that kunmap_local() will never fail.
80
81 On CONFIG_HIGHMEM=n kernels and for low memory pages they return the
82 virtual address of the direct mapping. Only real highmem pages are
83 temporarily mapped. Therefore, users may call a plain page_address()
84 for pages which are known to not come from ZONE_HIGHMEM. However, it is
85 always safe to use kmap_local_{page,folio}() / kunmap_local().
86
87 While they are significantly faster than kmap(), for the highmem case they
88 come with restrictions about the pointers validity. Contrary to kmap()
89 mappings, the local mappings are only valid in the context of the caller
90 and cannot be handed to other contexts. This implies that users must
91 be absolutely sure to keep the use of the return address local to the
92 thread which mapped it.
93
94 Most code can be designed to use thread local mappings. User should
95 therefore try to design their code to avoid the use of kmap() by mapping
96 pages in the same thread the address will be used and prefer
97 kmap_local_page() or kmap_local_folio().
98
99 Nesting kmap_local_page() and kmap_atomic() mappings is allowed to a certain
100 extent (up to KMAP_TYPE_NR) but their invocations have to be strictly ordered
101 because the map implementation is stack based. See kmap_local_page() kdocs
102 (included in the "Functions" section) for details on how to manage nested
103 mappings.
104
105 * kmap_atomic(). This function has been deprecated; use kmap_local_page().
106
107 NOTE: Conversions to kmap_local_page() must take care to follow the mapping
108 restrictions imposed on kmap_local_page(). Furthermore, the code between
109 calls to kmap_atomic() and kunmap_atomic() may implicitly depend on the side
110 effects of atomic mappings, i.e. disabling page faults or preemption, or both.
111 In that case, explicit calls to pagefault_disable() or preempt_disable() or
112 both must be made in conjunction with the use of kmap_local_page().
113
114 [Legacy documentation]
115
116 This permits a very short duration mapping of a single page. Since the
117 mapping is restricted to the CPU that issued it, it performs well, but
118 the issuing task is therefore required to stay on that CPU until it has
119 finished, lest some other task displace its mappings.
120
121 kmap_atomic() may also be used by interrupt contexts, since it does not
122 sleep and the callers too may not sleep until after kunmap_atomic() is
123 called.
124
125 Each call of kmap_atomic() in the kernel creates a non-preemptible section
126 and disable pagefaults. This could be a source of unwanted latency. Therefore
127 users should prefer kmap_local_page() instead of kmap_atomic().
128
129 It is assumed that k[un]map_atomic() won't fail.
130
131 * kmap(). This function has been deprecated; use kmap_local_page().
132
133 NOTE: Conversions to kmap_local_page() must take care to follow the mapping
134 restrictions imposed on kmap_local_page(). In particular, it is necessary to
135 make sure that the kernel virtual memory pointer is only valid in the thread
136 that obtained it.
137
138 [Legacy documentation]
139
140 This should be used to make short duration mapping of a single page with no
141 restrictions on preemption or migration. It comes with an overhead as mapping
142 space is restricted and protected by a global lock for synchronization. When
143 mapping is no longer needed, the address that the page was mapped to must be
144 released with kunmap().
145
146 Mapping changes must be propagated across all the CPUs. kmap() also
147 requires global TLB invalidation when the kmap's pool wraps and it might
148 block when the mapping space is fully utilized until a slot becomes
149 available. Therefore, kmap() is only callable from preemptible context.
150
151 All the above work is necessary if a mapping must last for a relatively
152 long time but the bulk of high-memory mappings in the kernel are
153 short-lived and only used in one place. This means that the cost of
154 kmap() is mostly wasted in such cases. kmap() was not intended for long
155 term mappings but it has morphed in that direction and its use is
156 strongly discouraged in newer code and the set of the preceding functions
157 should be preferred.
158
159 On 64-bit systems, calls to kmap_local_page(), kmap_atomic() and kmap() have
160 no real work to do because a 64-bit address space is more than sufficient to
161 address all the physical memory whose pages are permanently mapped.
162
163 * vmap(). This can be used to make a long duration mapping of multiple
164 physical pages into a contiguous virtual space. It needs global
165 synchronization to unmap.
166
167
168 Cost of Temporary Mappings
169 ==========================
170
171 The cost of creating temporary mappings can be quite high. The arch has to
172 manipulate the kernel's page tables, the data TLB and/or the MMU's registers.
173
174 If CONFIG_HIGHMEM is not set, then the kernel will try and create a mapping
175 simply with a bit of arithmetic that will convert the page struct address into
176 a pointer to the page contents rather than juggling mappings about. In such a
177 case, the unmap operation may be a null operation.
178
179 If CONFIG_MMU is not set, then there can be no temporary mappings and no
180 highmem. In such a case, the arithmetic approach will also be used.
181
182
183 i386 PAE
184 ========
185
186 The i386 arch, under some circumstances, will permit you to stick up to 64GiB
187 of RAM into your 32-bit machine. This has a number of consequences:
188
189 * Linux needs a page-frame structure for each page in the system and the
190 pageframes need to live in the permanent mapping, which means:
191
192 * you can have 896M/sizeof(struct page) page-frames at most; with struct
193 page being 32-bytes that would end up being something in the order of 112G
194 worth of pages; the kernel, however, needs to store more than just
195 page-frames in that memory...
196
197 * PAE makes your page tables larger - which slows the system down as more
198 data has to be accessed to traverse in TLB fills and the like. One
199 advantage is that PAE has more PTE bits and can provide advanced features
200 like NX and PAT.
201
202 The general recommendation is that you don't use more than 8GiB on a 32-bit
203 machine - although more might work for you and your workload, you're pretty
204 much on your own - don't expect kernel developers to really care much if things
205 come apart.
206
207
208 Functions
209 =========
210
211 .. kernel-doc:: include/linux/highmem.h
212 .. kernel-doc:: mm/highmem.c
213 .. kernel-doc:: include/linux/highmem-internal.h
214

3. 한국어 전문 번역

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

High memory의 의미

1-20

이 문서는 Peter Zijlstra가 작성한 high memory 처리 가이드입니다. High memory, 즉 highmem은 물리 메모리 크기가 가상 메모리의 최대 크기에 가까워지거나 이를 넘을 때 사용합니다.

이 시점에는 커널이 사용 가능한 모든 물리 메모리를 항상 mapping해 둘 수 없으므로 접근하려는 물리 메모리 조각에 임시 mapping을 만들어야 합니다. 영구 mapping이 덮지 않는 물리 메모리 부분을 `highmem`이라고 하며, 정확한 경계는 아키텍처별 제약에 따라 달라집니다.

====================
High Memory Handling
====================

By: Peter Zijlstra <[email protected]>

.. contents:: :local:

What Is High Memory?
====================

High memory (highmem) is used when the size of physical memory approaches or
exceeds the maximum size of virtual memory.  At that point it becomes
impossible for the kernel to keep all of the available physical memory mapped
at all times.  This means the kernel needs to start using temporary mappings of
the pieces of physical memory that it wants to access.

The part of (physical) memory not covered by a permanent mapping is what we
refer to as 'highmem'.  There are various architecture dependent constraints on
where exactly that border lies.

i386의 3:1 가상 주소 공간

21-47

i386에서는 kernel entry와 exit 때 전체 TLB invalidation 비용을 내지 않도록 커널을 모든 프로세스의 VM 공간에 mapping합니다. 따라서 i386의 4 GiB 가상 메모리 공간을 사용자 공간과 커널 공간으로 나눠야 합니다.

이 방식을 쓰는 아키텍처의 전통적인 분할은 사용자 공간 3 GiB와 위쪽 커널 공간 1 GiB의 3:1입니다.

i386 3:1 주소 공간 배치
가상 주소 범위영역크기
0xc0000000–0xffffffffKernel1 GiB
0x00000000–0xbfffffffUser3 GiB

원문의 세로 ASCII 배치를 주소 범위 표로 다시 구성했습니다.

커널이 한 번에 mapping할 수 있는 물리 메모리는 최대 1 GiB이지만, 나머지 물리 메모리에 접근하는 임시 map 등 다른 용도로도 가상 주소 공간이 필요하므로 실제 direct map은 보통 약 896 MiB보다 작습니다.

MM context tag가 붙은 TLB를 가진 다른 아키텍처는 kernel map과 user map을 분리할 수 있습니다. 그러나 일부 ARM 같은 하드웨어는 MM context tag를 사용할 때 가상 공간이 제한됩니다.


In the i386 arch, for example, we choose to map the kernel into every process's
VM space so that we don't have to pay the full TLB invalidation costs for
kernel entry/exit.  This means the available virtual memory space (4GiB on
i386) has to be divided between user and kernel space.

The traditional split for architectures using this approach is 3:1, 3GiB for
userspace and the top 1GiB for kernel space::

                +--------+ 0xffffffff
                | Kernel |
                +--------+ 0xc0000000
                |        |
                | User   |
                |        |
                +--------+ 0x00000000

This means that the kernel can at most map 1GiB of physical memory at any one
time, but because we need virtual address space for other things - including
temporary maps to access the rest of the physical memory - the actual direct
map will typically be less (usually around ~896MiB).

Other architectures that have mm context tagged TLBs can have separate kernel
and user maps.  Some hardware (like some ARMs), however, have limited virtual
space when they use mm context tags.

kmap_local_page()와 kmap_local_folio()

48-104

커널에는 여러 임시 mapping 방식이 있으며 선호 순서는 `kmap_local_page()`와 `kmap_local_folio()`가 가장 앞입니다. 이 함수들은 짧은 기간의 mapping을 만들고 interrupt를 포함한 모든 context에서 호출할 수 있지만, mapping을 획득한 context 안에서만 사용할 수 있습니다.

`kmap_local_page()`는 `struct page` pointer를 받고, `kmap_local_folio()`는 `struct folio` pointer와 folio 안의 page를 식별하는 byte offset을 받는다는 점만 다릅니다. Deprecated된 `kmap_atomic()`과 `kmap()` 대신 항상 이 함수들을 사용해야 합니다.

이 mapping은 thread-local이자 CPU-local입니다. Mapping은 해당 thread 안에서만 접근할 수 있고, 활성화된 동안 thread는 CPU에 묶입니다. 함수가 preemption을 끄지는 않지만 mapping이 해제될 때까지 CPU-hotplug로 해당 CPU를 시스템에서 unplug할 수 없습니다.

Local kmap region에서 page fault를 일으키는 것은 유효합니다. 다만 local mapping을 얻은 context가 다른 이유로 page fault를 허용하지 않는 경우는 예외입니다. Page fault와 preemption은 비활성화되지 않으며, context switch 때 나가는 task의 map을 저장하고 들어오는 task의 map을 복원하므로 preemption을 끌 필요가 없습니다.

`kmap_local_page()`와 `kmap_local_folio()`는 항상 유효한 virtual kernel address를 반환하며 `kunmap_local()`은 실패하지 않는다고 가정합니다.

`CONFIG_HIGHMEM=n` 커널과 low memory page에서는 direct mapping의 가상 주소를 반환하고 실제 highmem page만 임시 mapping합니다. `ZONE_HIGHMEM`에서 오지 않았다는 사실을 아는 page에는 평범한 `page_address()`를 호출할 수 있지만, `kmap_local_{page,folio}()`와 `kunmap_local()` 조합은 언제나 안전합니다.

이 함수들은 `kmap()`보다 훨씬 빠르지만 highmem에서는 pointer 유효 범위가 제한됩니다. Local mapping은 호출자 context 안에서만 유효해 다른 context로 전달할 수 없으므로 반환 주소의 사용을 mapping한 thread 안에 엄격히 한정해야 합니다.

대부분의 코드는 page를 주소를 사용할 같은 thread에서 mapping해 thread-local mapping을 쓸 수 있도록 설계할 수 있습니다. 따라서 `kmap()`을 피하고 `kmap_local_page()` 또는 `kmap_local_folio()`를 선호해야 합니다.

`kmap_local_page()`와 `kmap_atomic()` mapping은 `KMAP_TYPE_NR`까지 중첩할 수 있지만 구현이 stack 기반이므로 호출 순서를 엄격히 지켜야 합니다. 자세한 중첩 관리 방법은 Functions 절에 포함된 `kmap_local_page()` kernel-doc을 참조합니다.

Temporary Virtual Mappings
==========================

The kernel contains several ways of creating temporary mappings. The following
list shows them in order of preference of use.

* kmap_local_page(), kmap_local_folio() - These functions are used to create
  short term mappings. They can be invoked from any context (including
  interrupts) but the mappings can only be used in the context which acquired
  them. The only differences between them consist in the first taking a pointer
  to a struct page and the second taking a pointer to struct folio and the byte
  offset within the folio which identifies the page.

  These functions should always be used, whereas kmap_atomic() and kmap() have
  been deprecated.

  These mappings are thread-local and CPU-local, meaning that the mapping
  can only be accessed from within this thread and the thread is bound to the
  CPU while the mapping is active. Although preemption is never disabled by
  this function, the CPU can not be unplugged from the system via
  CPU-hotplug until the mapping is disposed.

  It's valid to take pagefaults in a local kmap region, unless the context
  in which the local mapping is acquired does not allow it for other reasons.

  As said, pagefaults and preemption are never disabled. There is no need to
  disable preemption because, when context switches to a different task, the
  maps of the outgoing task are saved and those of the incoming one are
  restored.

  kmap_local_page(), as well as kmap_local_folio() always returns valid virtual
  kernel addresses and it is assumed that kunmap_local() will never fail.

  On CONFIG_HIGHMEM=n kernels and for low memory pages they return the
  virtual address of the direct mapping. Only real highmem pages are
  temporarily mapped. Therefore, users may call a plain page_address()
  for pages which are known to not come from ZONE_HIGHMEM. However, it is
  always safe to use kmap_local_{page,folio}() / kunmap_local().

  While they are significantly faster than kmap(), for the highmem case they
  come with restrictions about the pointers validity. Contrary to kmap()
  mappings, the local mappings are only valid in the context of the caller
  and cannot be handed to other contexts. This implies that users must
  be absolutely sure to keep the use of the return address local to the
  thread which mapped it.

  Most code can be designed to use thread local mappings. User should
  therefore try to design their code to avoid the use of kmap() by mapping
  pages in the same thread the address will be used and prefer
  kmap_local_page() or kmap_local_folio().

  Nesting kmap_local_page() and kmap_atomic() mappings is allowed to a certain
  extent (up to KMAP_TYPE_NR) but their invocations have to be strictly ordered
  because the map implementation is stack based. See kmap_local_page() kdocs
  (included in the "Functions" section) for details on how to manage nested
  mappings.

Deprecated kmap_atomic()

105-130

`kmap_atomic()`은 deprecated됐으므로 `kmap_local_page()`를 사용해야 합니다. 전환할 때는 `kmap_local_page()`의 mapping 제한을 지켜야 합니다.

기존 `kmap_atomic()`과 `kunmap_atomic()` 사이 코드는 atomic mapping의 부수 효과인 page fault 또는 preemption 비활성화에 암묵적으로 의존할 수 있습니다. 그런 경우 `kmap_local_page()`로 전환하면서 `pagefault_disable()`이나 `preempt_disable()` 또는 둘 다를 명시적으로 호출해야 합니다.

Legacy 동작에서 `kmap_atomic()`은 page 하나를 매우 짧게 mapping합니다. Mapping이 요청한 CPU에 한정되므로 빠르지만, 다른 task가 mapping을 밀어내지 않도록 완료할 때까지 요청 task가 그 CPU에 머물러야 합니다.

Sleep하지 않으므로 interrupt context에서도 쓸 수 있지만 호출자 역시 `kunmap_atomic()`을 부를 때까지 sleep할 수 없습니다. 호출할 때마다 non-preemptible section을 만들고 page fault를 비활성화해 원치 않는 latency를 만들 수 있으므로 `kmap_local_page()`를 선호해야 합니다. `k[un]map_atomic()`은 실패하지 않는다고 가정합니다.

* kmap_atomic(). This function has been deprecated; use kmap_local_page().

  NOTE: Conversions to kmap_local_page() must take care to follow the mapping
  restrictions imposed on kmap_local_page(). Furthermore, the code between
  calls to kmap_atomic() and kunmap_atomic() may implicitly depend on the side
  effects of atomic mappings, i.e. disabling page faults or preemption, or both.
  In that case, explicit calls to pagefault_disable() or preempt_disable() or
  both must be made in conjunction with the use of kmap_local_page().

  [Legacy documentation]

  This permits a very short duration mapping of a single page.  Since the
  mapping is restricted to the CPU that issued it, it performs well, but
  the issuing task is therefore required to stay on that CPU until it has
  finished, lest some other task displace its mappings.

  kmap_atomic() may also be used by interrupt contexts, since it does not
  sleep and the callers too may not sleep until after kunmap_atomic() is
  called.

  Each call of kmap_atomic() in the kernel creates a non-preemptible section
  and disable pagefaults. This could be a source of unwanted latency. Therefore
  users should prefer kmap_local_page() instead of kmap_atomic().

  It is assumed that k[un]map_atomic() won't fail.

Deprecated kmap()과 장기 vmap()

131-167

`kmap()`도 deprecated됐으므로 `kmap_local_page()`를 사용해야 합니다. 전환할 때 특히 kernel virtual memory pointer가 이를 얻은 thread에서만 유효하다는 제한을 지켜야 합니다.

Legacy `kmap()`은 preemption이나 migration 제한 없이 page 하나를 짧게 mapping하는 용도였습니다. Mapping 공간이 제한되고 동기화를 위한 global lock으로 보호되므로 오버헤드가 있습니다. Mapping이 더 필요 없으면 `kunmap()`으로 page가 mapping된 주소를 해제해야 합니다.

Mapping 변경은 모든 CPU에 전파해야 합니다. `kmap()` pool이 wrap되면 global TLB invalidation도 필요하고, mapping 공간이 가득 차면 slot이 생길 때까지 block할 수 있으므로 preemptible context에서만 호출할 수 있습니다.

상대적으로 긴 mapping이 꼭 필요하다면 이 작업이 필요하지만, 커널의 high-memory mapping 대부분은 짧고 한곳에서만 사용되므로 `kmap()` 비용은 대개 낭비입니다. `kmap()`은 본래 장기 mapping용이 아니었으나 그 방향으로 변해 왔고, 새 코드에서는 사용을 강하게 피하며 앞의 local 함수들을 선호해야 합니다.

64-bit 시스템에서는 주소 공간이 영구 mapping된 모든 물리 메모리를 다루기에 충분하므로 `kmap_local_page()`, `kmap_atomic()`, `kmap()` 호출이 실제 mapping 작업을 할 필요가 없습니다.

`vmap()`은 여러 물리 page를 연속된 가상 공간에 장기간 mapping할 때 사용합니다. Unmap에는 global synchronization이 필요합니다.

* kmap(). This function has been deprecated; use kmap_local_page().

  NOTE: Conversions to kmap_local_page() must take care to follow the mapping
  restrictions imposed on kmap_local_page(). In particular, it is necessary to
  make sure that the kernel virtual memory pointer is only valid in the thread
  that obtained it.

  [Legacy documentation]

  This should be used to make short duration mapping of a single page with no
  restrictions on preemption or migration. It comes with an overhead as mapping
  space is restricted and protected by a global lock for synchronization. When
  mapping is no longer needed, the address that the page was mapped to must be
  released with kunmap().

  Mapping changes must be propagated across all the CPUs. kmap() also
  requires global TLB invalidation when the kmap's pool wraps and it might
  block when the mapping space is fully utilized until a slot becomes
  available. Therefore, kmap() is only callable from preemptible context.

  All the above work is necessary if a mapping must last for a relatively
  long time but the bulk of high-memory mappings in the kernel are
  short-lived and only used in one place. This means that the cost of
  kmap() is mostly wasted in such cases. kmap() was not intended for long
  term mappings but it has morphed in that direction and its use is
  strongly discouraged in newer code and the set of the preceding functions
  should be preferred.

  On 64-bit systems, calls to kmap_local_page(), kmap_atomic() and kmap() have
  no real work to do because a 64-bit address space is more than sufficient to
  address all the physical memory whose pages are permanently mapped.

* vmap().  This can be used to make a long duration mapping of multiple
  physical pages into a contiguous virtual space.  It needs global
  synchronization to unmap.

임시 mapping 비용

168-181

임시 mapping 생성 비용은 상당히 클 수 있습니다. 아키텍처가 kernel page table, data TLB 또는 MMU register를 조작해야 하기 때문입니다.

`CONFIG_HIGHMEM`이 설정되지 않았다면 커널은 mapping을 바꾸는 대신 `struct page` 주소를 page 내용 pointer로 변환하는 간단한 산술 연산으로 mapping을 만들려고 합니다. 이 경우 unmap은 아무 작업도 하지 않을 수 있습니다.

`CONFIG_MMU`가 설정되지 않으면 임시 mapping과 highmem 자체가 존재할 수 없으며, 이때도 산술 변환 방식을 사용합니다.

Cost of Temporary Mappings
==========================

The cost of creating temporary mappings can be quite high.  The arch has to
manipulate the kernel's page tables, the data TLB and/or the MMU's registers.

If CONFIG_HIGHMEM is not set, then the kernel will try and create a mapping
simply with a bit of arithmetic that will convert the page struct address into
a pointer to the page contents rather than juggling mappings about.  In such a
case, the unmap operation may be a null operation.

If CONFIG_MMU is not set, then there can be no temporary mappings and no
highmem.  In such a case, the arithmetic approach will also be used.

i386 PAE의 영향과 권장 한계

182-205

일부 조건에서 i386 PAE는 32-bit machine에 최대 64 GiB RAM을 장착하게 합니다. Linux는 시스템의 각 page마다 영구 mapping 안에 존재해야 하는 page-frame 구조체를 필요로 합니다.

따라서 page-frame 수의 이론적 상한은 `896M / sizeof(struct page)`입니다. `struct page`가 32 byte라면 약 112 GiB 분량의 page에 해당하지만, 커널은 그 영구 mapping 메모리에 page-frame 이외의 데이터도 저장해야 합니다.

PAE는 page table을 더 크게 만들어 TLB fill 등에서 순회할 데이터가 늘고 시스템이 느려집니다. 장점은 PTE bit가 더 많아 NX와 PAT 같은 고급 기능을 제공할 수 있다는 점입니다.

일반적인 권장은 32-bit machine에서 8 GiB보다 많은 메모리를 사용하지 않는 것입니다. 더 많은 메모리가 특정 workload에서 동작할 수는 있지만 문제가 생기면 사실상 사용자가 스스로 해결해야 하며 kernel developer의 적극적인 지원을 기대하기 어렵습니다.


i386 PAE
========

The i386 arch, under some circumstances, will permit you to stick up to 64GiB
of RAM into your 32-bit machine.  This has a number of consequences:

* Linux needs a page-frame structure for each page in the system and the
  pageframes need to live in the permanent mapping, which means:

* you can have 896M/sizeof(struct page) page-frames at most; with struct
  page being 32-bytes that would end up being something in the order of 112G
  worth of pages; the kernel, however, needs to store more than just
  page-frames in that memory...

* PAE makes your page tables larger - which slows the system down as more
  data has to be accessed to traverse in TLB fills and the like.  One
  advantage is that PAE has more PTE bits and can provide advanced features
  like NX and PAT.

The general recommendation is that you don't use more than 8GiB on a 32-bit
machine - although more might work for you and your workload, you're pretty
much on your own - don't expect kernel developers to really care much if things
come apart.

관련 함수 reference

206-213

High memory 관련 함수 reference는 `include/linux/highmem.h`, `mm/highmem.c`, `include/linux/highmem-internal.h`의 kernel-doc에서 생성됩니다.



Functions
=========

.. kernel-doc:: include/linux/highmem.h
.. kernel-doc:: mm/highmem.c
.. kernel-doc:: include/linux/highmem-internal.h