44Concepts overview
55=================
66
7- The memory management in Linux is complex system that evolved over the
8- years and included more and more functionality to support variety of
7+ The memory management in Linux is a complex system that evolved over the
8+ years and included more and more functionality to support a variety of
99systems from MMU-less microcontrollers to supercomputers. The memory
10- management for systems without MMU is called ``nommu `` and it
10+ management for systems without an MMU is called ``nommu `` and it
1111definitely deserves a dedicated document, which hopefully will be
1212eventually written. Yet, although some of the concepts are the same,
13- here we assume that MMU is available and CPU can translate a virtual
13+ here we assume that an MMU is available and a CPU can translate a virtual
1414address to a physical address.
1515
1616.. contents :: :local:
@@ -21,10 +21,10 @@ Virtual Memory Primer
2121The physical memory in a computer system is a limited resource and
2222even for systems that support memory hotplug there is a hard limit on
2323the amount of memory that can be installed. The physical memory is not
24- necessary contiguous, it might be accessible as a set of distinct
24+ necessarily contiguous; it might be accessible as a set of distinct
2525address ranges. Besides, different CPU architectures, and even
26- different implementations of the same architecture have different view
27- how these address ranges defined.
26+ different implementations of the same architecture have different views
27+ of how these address ranges are defined.
2828
2929All this makes dealing directly with physical memory quite complex and
3030to avoid this complexity a concept of virtual memory was developed.
@@ -48,8 +48,8 @@ appropriate kernel configuration option.
4848
4949Each physical memory page can be mapped as one or more virtual
5050pages. These mappings are described by page tables that allow
51- translation from virtual address used by programs to real address in
52- the physical memory. The page tables organized hierarchically.
51+ translation from a virtual address used by programs to the physical
52+ memory address . The page tables are organized hierarchically.
5353
5454The tables at the lowest level of the hierarchy contain physical
5555addresses of actual pages used by the software. The tables at higher
@@ -121,8 +121,8 @@ Nodes
121121Many multi-processor machines are NUMA - Non-Uniform Memory Access -
122122systems. In such systems the memory is arranged into banks that have
123123different access latency depending on the "distance" from the
124- processor. Each bank is referred as `node ` and for each node Linux
125- constructs an independent memory management subsystem. A node has it's
124+ processor. Each bank is referred to as a `node ` and for each node Linux
125+ constructs an independent memory management subsystem. A node has its
126126own set of zones, lists of free and used pages and various statistics
127127counters. You can find more details about NUMA in
128128:ref: `Documentation/vm/numa.rst <numa >` and in
@@ -149,9 +149,9 @@ for program's stack and heap or by explicit calls to mmap(2) system
149149call. Usually, the anonymous mappings only define virtual memory areas
150150that the program is allowed to access. The read accesses will result
151151in creation of a page table entry that references a special physical
152- page filled with zeroes. When the program performs a write, regular
152+ page filled with zeroes. When the program performs a write, a regular
153153physical page will be allocated to hold the written data. The page
154- will be marked dirty and if the kernel will decide to repurpose it,
154+ will be marked dirty and if the kernel decides to repurpose it,
155155the dirty page will be swapped out.
156156
157157Reclaim
@@ -181,16 +181,16 @@ pressure.
181181The process of freeing the reclaimable physical memory pages and
182182repurposing them is called (surprise!) `reclaim `. Linux can reclaim
183183pages either asynchronously or synchronously, depending on the state
184- of the system. When system is not loaded, most of the memory is free
185- and allocation request will be satisfied immediately from the free
184+ of the system. When the system is not loaded, most of the memory is free
185+ and allocation requests will be satisfied immediately from the free
186186pages supply. As the load increases, the amount of the free pages goes
187187down and when it reaches a certain threshold (high watermark), an
188188allocation request will awaken the ``kswapd `` daemon. It will
189189asynchronously scan memory pages and either just free them if the data
190190they contain is available elsewhere, or evict to the backing storage
191191device (remember those dirty pages?). As memory usage increases even
192192more and reaches another threshold - min watermark - an allocation
193- will trigger the `direct reclaim `. In this case allocation is stalled
193+ will trigger `direct reclaim `. In this case allocation is stalled
194194until enough memory pages are reclaimed to satisfy the request.
195195
196196Compaction
@@ -200,23 +200,24 @@ As the system runs, tasks allocate and free the memory and it becomes
200200fragmented. Although with virtual memory it is possible to present
201201scattered physical pages as virtually contiguous range, sometimes it is
202202necessary to allocate large physically contiguous memory areas. Such
203- need may arise, for instance, when a device driver requires large
203+ need may arise, for instance, when a device driver requires a large
204204buffer for DMA, or when THP allocates a huge page. Memory `compaction `
205205addresses the fragmentation issue. This mechanism moves occupied pages
206206from the lower part of a memory zone to free pages in the upper part
207207of the zone. When a compaction scan is finished free pages are grouped
208208together at the beginning of the zone and allocations of large
209209physically contiguous areas become possible.
210210
211- Like reclaim, the compaction may happen asynchronously in ``kcompactd ``
212- daemon or synchronously as a result of memory allocation request.
211+ Like reclaim, the compaction may happen asynchronously in the ``kcompactd ``
212+ daemon or synchronously as a result of a memory allocation request.
213213
214214OOM killer
215215==========
216216
217- It may happen, that on a loaded machine memory will be exhausted. When
218- the kernel detects that the system runs out of memory (OOM) it invokes
219- `OOM killer `. Its mission is simple: all it has to do is to select a
220- task to sacrifice for the sake of the overall system health. The
221- selected task is killed in a hope that after it exits enough memory
222- will be freed to continue normal operation.
217+ It is possible that on a loaded machine memory will be exhausted and the
218+ kernel will be unable to reclaim enough memory to continue to operate. In
219+ order to save the rest of the system, it invokes the `OOM killer `.
220+
221+ The `OOM killer ` selects a task to sacrifice for the sake of the overall
222+ system health. The selected task is killed in a hope that after it exits
223+ enough memory will be freed to continue normal operation.
0 commit comments