Lines Matching +full:memory +full:- +full:to +full:- +full:memory

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
9 systems from MMU-less microcontrollers to supercomputers. The memory
14 address to a physical address.
18 Virtual Memory Primer
21 The physical memory in a computer system is a limited resource and
22 even for systems that support memory hotplug there is a hard limit on
23 the amount of memory that can be installed. The physical memory is not
29 All this makes dealing directly with physical memory quite complex and
30 to avoid this complexity a concept of virtual memory was developed.
32 The virtual memory abstracts the details of physical memory from the
33 application software, allows to keep only needed information in the
34 physical memory (demand paging) and provides a mechanism for the
37 With virtual memory, each and every memory access uses a virtual
39 writes) from (or to) the system memory, it translates the `virtual`
40 address encoded in that instruction to a `physical` address that the
41 memory controller can understand.
43 The physical system memory is divided into page frames, or pages. The
49 Each physical memory page can be mapped as one or more virtual
51 translation from a virtual address used by programs to the physical
52 memory address. The page tables are organized hierarchically.
56 levels contain physical addresses of the pages belonging to the lower
57 levels. The pointer to the top level page table resides in a
59 register to access the top level page table. The high bits of the
60 virtual address are used to index an entry in the top level page
61 table. That entry is then used to access the next level in the
62 hierarchy with the next bits of the virtual address as the index to
69 The address translation requires several memory accesses and memory
70 accesses are slow relatively to CPU speed. To avoid spending precious
74 large memory working set will experience performance hit because of
77 Many modern CPU architectures allow mapping of the memory pages
79 it is possible to map 2M and even 1G pages using entries in the second
82 improves TLB hit-rate and thus improves overall system performance.
85 memory with the huge pages. The first one is `HugeTLB filesystem`, or
88 the memory and mapped using huge pages. The hugetlbfs is described at
89 :ref:`Documentation/admin-guide/mm/hugetlbpage.rst <hugetlbpage>`.
93 requires users and/or system administrators to configure what parts of
94 the system memory should and can be mapped by the huge pages, THP
95 manages such mappings transparently to the user and hence the
97 :ref:`Documentation/admin-guide/mm/transhuge.rst <admin_guide_transhuge>`
103 Often hardware poses restrictions on how different physical memory
104 ranges can be accessed. In some cases, devices cannot perform DMA to
105 all the addressable memory. In other cases, the size of the physical
106 memory exceeds the maximal addressable size of virtual memory and
107 special actions are required to access portions of the memory. Linux
108 groups memory pages into `zones` according to their possible
109 usage. For example, ZONE_DMA will contain memory that can be used by
110 devices for DMA, ZONE_HIGHMEM will contain memory that is not
114 The actual layout of the memory zones is hardware dependent as not all
121 Many multi-processor machines are NUMA - Non-Uniform Memory Access -
122 systems. In such systems the memory is arranged into banks that have
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
129 :ref:`Documentation/admin-guide/mm/numa_memory_policy.rst <numa_memory_policy>`.
134 The physical memory is volatile and the common case for getting data
135 into the memory is to read it from files. Whenever a file is read, the
136 data is put into the `page cache` to avoid expensive disk access on
137 the subsequent reads. Similarly, when one writes to a file, the data
140 decides to reuse them for other purposes, it makes sure to synchronize
143 Anonymous Memory
146 The `anonymous memory` or `anonymous mappings` represent memory that
148 for program's stack and heap or by explicit calls to mmap(2) system
149 call. Usually, the anonymous mappings only define virtual memory areas
150 that the program is allowed to access. The read accesses will result
153 physical page will be allocated to hold the written data. The page
154 will be marked dirty and if the kernel decides to repurpose it,
163 memory allocated by user space processes etc.
166 memory management. The pages that can be freed at any time, either
168 hard disk, or because they can be swapped out, again, to the hard
170 reclaimable pages are page cache and anonymous memory.
176 reclaimed. For instance, in-memory caches of filesystem metadata can
177 be re-read from the storage device and therefore it is possible to
178 discard them from the main memory when system is under memory
181 The process of freeing the reclaimable physical memory pages and
184 of the system. When the system is not loaded, most of the memory is free
189 asynchronously scan memory pages and either just free them if the data
190 they contain is available elsewhere, or evict to the backing storage
191 device (remember those dirty pages?). As memory usage increases even
192 more and reaches another threshold - min watermark - an allocation
194 until enough memory pages are reclaimed to satisfy the request.
199 As the system runs, tasks allocate and free the memory and it becomes
200 fragmented. Although with virtual memory it is possible to present
202 necessary to allocate large physically contiguous memory areas. Such
204 buffer for DMA, or when THP allocates a huge page. Memory `compaction`
206 from the lower part of a memory zone to free pages in the upper part
212 daemon or synchronously as a result of a memory allocation request.
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`.
221 The `OOM killer` selects a task to sacrifice for the sake of the overall
223 enough memory will be freed to continue normal operation.