€•&ˆŒsphinx.addnodes”Œdocument”“”)”}”(Œ rawsource”Œ”Œchildren”]”(Œ translations”Œ LanguagesNode”“”)”}”(hhh]”(hŒ pending_xref”“”)”}”(hhh]”Œdocutils.nodes”ŒText”“”ŒChinese (Simplified)”…””}”Œparent”hsbaŒ attributes”}”(Œids”]”Œclasses”]”Œnames”]”Œdupnames”]”Œbackrefs”]”Œ refdomain”Œstd”Œreftype”Œdoc”Œ reftarget”Œ+/translations/zh_CN/admin-guide/mm/concepts”Œmodname”NŒ classname”NŒ refexplicit”ˆuŒtagname”hhh ubh)”}”(hhh]”hŒChinese (Traditional)”…””}”hh2sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ+/translations/zh_TW/admin-guide/mm/concepts”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒItalian”…””}”hhFsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ+/translations/it_IT/admin-guide/mm/concepts”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒJapanese”…””}”hhZsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ+/translations/ja_JP/admin-guide/mm/concepts”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒKorean”…””}”hhnsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ+/translations/ko_KR/admin-guide/mm/concepts”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒSpanish”…””}”hh‚sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ+/translations/sp_SP/admin-guide/mm/concepts”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubeh}”(h]”h ]”h"]”h$]”h&]”Œcurrent_language”ŒEnglish”uh1h hhŒ _document”hŒsource”NŒline”NubhŒsection”“”)”}”(hhh]”(hŒtitle”“”)”}”(hŒConcepts overview”h]”hŒConcepts overview”…””}”(hh¨hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h¦hh£hžhhŸŒE/var/lib/git/docbuild/linux/Documentation/admin-guide/mm/concepts.rst”h KubhŒ paragraph”“”)”}”(hXThe memory management in Linux is a complex system that evolved over the years and included more and more functionality to support a variety of systems from MMU-less microcontrollers to supercomputers. The memory management for systems without an MMU is called ``nommu`` and it definitely deserves a dedicated document, which hopefully will be eventually written. Yet, although some of the concepts are the same, here we assume that an MMU is available and a CPU can translate a virtual address to a physical address.”h]”(hXThe memory management in Linux is a complex system that evolved over the years and included more and more functionality to support a variety of systems from MMU-less microcontrollers to supercomputers. The memory management for systems without an MMU is called ”…””}”(hh¹hžhhŸNh NubhŒliteral”“”)”}”(hŒ ``nommu``”h]”hŒnommu”…””}”(hhÃhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÁhh¹ubhŒ÷ and it definitely deserves a dedicated document, which hopefully will be eventually written. Yet, although some of the concepts are the same, here we assume that an MMU is available and a CPU can translate a virtual address to a physical address.”…””}”(hh¹hžhhŸNh Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Khh£hžhubhŒtopic”“”)”}”(hhh]”hŒ bullet_list”“”)”}”(hhh]”(hŒ list_item”“”)”}”(hhh]”h¸)”}”(hhh]”hŒ reference”“”)”}”(hhh]”hŒVirtual Memory Primer”…””}”(hhïhžhhŸNh Nubah}”(h]”Œid1”ah ]”h"]”h$]”h&]”Œrefid”Œvirtual-memory-primer”uh1híhhêubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hhçubah}”(h]”h ]”h"]”h$]”h&]”uh1håhhâubhæ)”}”(hhh]”h¸)”}”(hhh]”hî)”}”(hhh]”hŒ Huge Pages”…””}”(hjhžhhŸNh Nubah}”(h]”Œid2”ah ]”h"]”h$]”h&]”Œrefid”Œ huge-pages”uh1híhjubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hj ubah}”(h]”h ]”h"]”h$]”h&]”uh1håhhâubhæ)”}”(hhh]”h¸)”}”(hhh]”hî)”}”(hhh]”hŒZones”…””}”(hj3hžhhŸNh Nubah}”(h]”Œid3”ah ]”h"]”h$]”h&]”Œrefid”Œzones”uh1híhj0ubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hj-ubah}”(h]”h ]”h"]”h$]”h&]”uh1håhhâubhæ)”}”(hhh]”h¸)”}”(hhh]”hî)”}”(hhh]”hŒNodes”…””}”(hjUhžhhŸNh Nubah}”(h]”Œid4”ah ]”h"]”h$]”h&]”Œrefid”Œnodes”uh1híhjRubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hjOubah}”(h]”h ]”h"]”h$]”h&]”uh1håhhâubhæ)”}”(hhh]”h¸)”}”(hhh]”hî)”}”(hhh]”hŒ Page cache”…””}”(hjwhžhhŸNh Nubah}”(h]”Œid5”ah ]”h"]”h$]”h&]”Œrefid”Œ page-cache”uh1híhjtubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hjqubah}”(h]”h ]”h"]”h$]”h&]”uh1håhhâubhæ)”}”(hhh]”h¸)”}”(hhh]”hî)”}”(hhh]”hŒAnonymous Memory”…””}”(hj™hžhhŸNh Nubah}”(h]”Œid6”ah ]”h"]”h$]”h&]”Œrefid”Œanonymous-memory”uh1híhj–ubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hj“ubah}”(h]”h ]”h"]”h$]”h&]”uh1håhhâubhæ)”}”(hhh]”h¸)”}”(hhh]”hî)”}”(hhh]”hŒReclaim”…””}”(hj»hžhhŸNh Nubah}”(h]”Œid7”ah ]”h"]”h$]”h&]”Œrefid”Œreclaim”uh1híhj¸ubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hjµubah}”(h]”h ]”h"]”h$]”h&]”uh1håhhâubhæ)”}”(hhh]”h¸)”}”(hhh]”hî)”}”(hhh]”hŒ Compaction”…””}”(hjÝhžhhŸNh Nubah}”(h]”Œid8”ah ]”h"]”h$]”h&]”Œrefid”Œ compaction”uh1híhjÚubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hj×ubah}”(h]”h ]”h"]”h$]”h&]”uh1håhhâubhæ)”}”(hhh]”h¸)”}”(hhh]”hî)”}”(hhh]”hŒ OOM killer”…””}”(hjÿhžhhŸNh Nubah}”(h]”Œid9”ah ]”h"]”h$]”h&]”Œrefid”Œ oom-killer”uh1híhjüubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hjùubah}”(h]”h ]”h"]”h$]”h&]”uh1håhhâubeh}”(h]”h ]”h"]”h$]”h&]”uh1hàhhÝhžhhŸNh Nubah}”(h]”Œcontents”ah ]”(Œcontents”Œlocal”eh"]”Œcontents”ah$]”h&]”uh1hÛhŸh¶h Khh£hžhubh¢)”}”(hhh]”(h§)”}”(hŒVirtual Memory Primer”h]”hŒVirtual Memory Primer”…””}”(hj.hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”Œrefid”høuh1h¦hj+hžhhŸh¶h Kubh¸)”}”(hXÃThe physical memory in a computer system is a limited resource and even for systems that support memory hotplug there is a hard limit on the amount of memory that can be installed. The physical memory is not necessarily contiguous; it might be accessible as a set of distinct address ranges. Besides, different CPU architectures, and even different implementations of the same architecture have different views of how these address ranges are defined.”h]”hXÃThe physical memory in a computer system is a limited resource and even for systems that support memory hotplug there is a hard limit on the amount of memory that can be installed. The physical memory is not necessarily contiguous; it might be accessible as a set of distinct address ranges. Besides, different CPU architectures, and even different implementations of the same architecture have different views of how these address ranges are defined.”…””}”(hj=hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Khj+hžhubh¸)”}”(hŒŠAll this makes dealing directly with physical memory quite complex and to avoid this complexity a concept of virtual memory was developed.”h]”hŒŠAll this makes dealing directly with physical memory quite complex and to avoid this complexity a concept of virtual memory was developed.”…””}”(hjKhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Khj+hžhubh¸)”}”(hXThe virtual memory abstracts the details of physical memory from the application software, allows to keep only needed information in the physical memory (demand paging) and provides a mechanism for the protection and controlled sharing of data between processes.”h]”hXThe virtual memory abstracts the details of physical memory from the application software, allows to keep only needed information in the physical memory (demand paging) and provides a mechanism for the protection and controlled sharing of data between processes.”…””}”(hjYhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Khj+hžhubh¸)”}”(hX'With virtual memory, each and every memory access uses a virtual address. When the CPU decodes an instruction that reads (or writes) from (or to) the system memory, it translates the `virtual` address encoded in that instruction to a `physical` address that the memory controller can understand.”h]”(hŒ·With virtual memory, each and every memory access uses a virtual address. When the CPU decodes an instruction that reads (or writes) from (or to) the system memory, it translates the ”…””}”(hjghžhhŸNh NubhŒtitle_reference”“”)”}”(hŒ `virtual`”h]”hŒvirtual”…””}”(hjqhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1johjgubhŒ* address encoded in that instruction to a ”…””}”(hjghžhhŸNh Nubjp)”}”(hŒ `physical`”h]”hŒphysical”…””}”(hjƒhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1johjgubhŒ3 address that the memory controller can understand.”…””}”(hjghžhhŸNh Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K#hj+hžhubh¸)”}”(hX0The physical system memory is divided into page frames, or pages. The size of each page is architecture specific. Some architectures allow selection of the page size from several supported values; this selection is performed at the kernel build time by setting an appropriate kernel configuration option.”h]”hX0The physical system memory is divided into page frames, or pages. The size of each page is architecture specific. Some architectures allow selection of the page size from several supported values; this selection is performed at the kernel build time by setting an appropriate kernel configuration option.”…””}”(hj›hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K)hj+hžhubh¸)”}”(hŒþEach physical memory page can be mapped as one or more virtual pages. These mappings are described by page tables that allow translation from a virtual address used by programs to the physical memory address. The page tables are organized hierarchically.”h]”hŒþEach physical memory page can be mapped as one or more virtual pages. These mappings are described by page tables that allow translation from a virtual address used by programs to the physical memory address. The page tables are organized hierarchically.”…””}”(hj©hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K/hj+hžhubh¸)”}”(hX¼The tables at the lowest level of the hierarchy contain physical addresses of actual pages used by the software. The tables at higher levels contain physical addresses of the pages belonging to the lower levels. The pointer to the top level page table resides in a register. When the CPU performs the address translation, it uses this register to access the top level page table. The high bits of the virtual address are used to index an entry in the top level page table. That entry is then used to access the next level in the hierarchy with the next bits of the virtual address as the index to that level page table. The lowest bits in the virtual address define the offset inside the actual page.”h]”hX¼The tables at the lowest level of the hierarchy contain physical addresses of actual pages used by the software. The tables at higher levels contain physical addresses of the pages belonging to the lower levels. The pointer to the top level page table resides in a register. When the CPU performs the address translation, it uses this register to access the top level page table. The high bits of the virtual address are used to index an entry in the top level page table. That entry is then used to access the next level in the hierarchy with the next bits of the virtual address as the index to that level page table. The lowest bits in the virtual address define the offset inside the actual page.”…””}”(hj·hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K4hj+hžhubeh}”(h]”hþah ]”h"]”Œvirtual memory primer”ah$]”h&]”uh1h¡hh£hžhhŸh¶h Kubh¢)”}”(hhh]”(h§)”}”(hŒ Huge Pages”h]”hŒ Huge Pages”…””}”(hjÏhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”j<juh1h¦hjÌhžhhŸh¶h KAubh¸)”}”(hX›The address translation requires several memory accesses and memory accesses are slow relatively to CPU speed. To avoid spending precious processor cycles on the address translation, CPUs maintain a cache of such translations called Translation Lookaside Buffer (or TLB). Usually TLB is pretty scarce resource and applications with large memory working set will experience performance hit because of TLB misses.”h]”hX›The address translation requires several memory accesses and memory accesses are slow relatively to CPU speed. To avoid spending precious processor cycles on the address translation, CPUs maintain a cache of such translations called Translation Lookaside Buffer (or TLB). Usually TLB is pretty scarce resource and applications with large memory working set will experience performance hit because of TLB misses.”…””}”(hjÝhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KChjÌhžhubh¸)”}”(hX”Many modern CPU architectures allow mapping of the memory pages directly by the higher levels in the page table. For instance, on x86, it is possible to map 2M and even 1G pages using entries in the second and the third level page tables. In Linux such pages are called `huge`. Usage of huge pages significantly reduces pressure on TLB, improves TLB hit-rate and thus improves overall system performance.”h]”(hXMany modern CPU architectures allow mapping of the memory pages directly by the higher levels in the page table. For instance, on x86, it is possible to map 2M and even 1G pages using entries in the second and the third level page tables. In Linux such pages are called ”…””}”(hjëhžhhŸNh Nubjp)”}”(hŒ`huge`”h]”hŒhuge”…””}”(hjóhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1johjëubhŒ€. Usage of huge pages significantly reduces pressure on TLB, improves TLB hit-rate and thus improves overall system performance.”…””}”(hjëhžhhŸNh Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KKhjÌhžhubh¸)”}”(hX…There are two mechanisms in Linux that enable mapping of the physical memory with the huge pages. The first one is `HugeTLB filesystem`, or hugetlbfs. It is a pseudo filesystem that uses RAM as its backing store. For the files created in this filesystem the data resides in the memory and mapped using huge pages. The hugetlbfs is described at Documentation/admin-guide/mm/hugetlbpage.rst.”h]”(hŒsThere are two mechanisms in Linux that enable mapping of the physical memory with the huge pages. The first one is ”…””}”(hj hžhhŸNh Nubjp)”}”(hŒ`HugeTLB filesystem`”h]”hŒHugeTLB filesystem”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1johj ubhŒþ, or hugetlbfs. It is a pseudo filesystem that uses RAM as its backing store. For the files created in this filesystem the data resides in the memory and mapped using huge pages. The hugetlbfs is described at Documentation/admin-guide/mm/hugetlbpage.rst.”…””}”(hj hžhhŸNh Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KRhjÌhžhubh¸)”}”(hXŸAnother, more recent, mechanism that enables use of the huge pages is called `Transparent HugePages`, or THP. Unlike the hugetlbfs that requires users and/or system administrators to configure what parts of the system memory should and can be mapped by the huge pages, THP manages such mappings transparently to the user and hence the name. See Documentation/admin-guide/mm/transhuge.rst for more details about THP.”h]”(hŒMAnother, more recent, mechanism that enables use of the huge pages is called ”…””}”(hj+hžhhŸNh Nubjp)”}”(hŒ`Transparent HugePages`”h]”hŒTransparent HugePages”…””}”(hj3hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1johj+ubhX;, or THP. Unlike the hugetlbfs that requires users and/or system administrators to configure what parts of the system memory should and can be mapped by the huge pages, THP manages such mappings transparently to the user and hence the name. See Documentation/admin-guide/mm/transhuge.rst for more details about THP.”…””}”(hj+hžhhŸNh Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KYhjÌhžhubeh}”(h]”j ah ]”h"]”Œ huge pages”ah$]”h&]”uh1h¡hh£hžhhŸh¶h KAubh¢)”}”(hhh]”(h§)”}”(hŒZones”h]”hŒZones”…””}”(hjUhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”j<j<uh1h¦hjRhžhhŸh¶h Kbubh¸)”}”(hXyOften hardware poses restrictions on how different physical memory ranges can be accessed. In some cases, devices cannot perform DMA to all the addressable memory. In other cases, the size of the physical memory exceeds the maximal addressable size of virtual memory and special actions are required to access portions of the memory. Linux groups memory pages into `zones` according to their possible usage. For example, ZONE_DMA will contain memory that can be used by devices for DMA, ZONE_HIGHMEM will contain memory that is not permanently mapped into kernel's address space and ZONE_NORMAL will contain normally addressed pages.”h]”(hXmOften hardware poses restrictions on how different physical memory ranges can be accessed. In some cases, devices cannot perform DMA to all the addressable memory. In other cases, the size of the physical memory exceeds the maximal addressable size of virtual memory and special actions are required to access portions of the memory. Linux groups memory pages into ”…””}”(hjchžhhŸNh Nubjp)”}”(hŒ`zones`”h]”hŒzones”…””}”(hjkhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1johjcubhX according to their possible usage. For example, ZONE_DMA will contain memory that can be used by devices for DMA, ZONE_HIGHMEM will contain memory that is not permanently mapped into kernel’s address space and ZONE_NORMAL will contain normally addressed pages.”…””}”(hjchžhhŸNh Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KdhjRhžhubh¸)”}”(hŒ¦The actual layout of the memory zones is hardware dependent as not all architectures define all zones, and requirements for DMA are different for different platforms.”h]”hŒ¦The actual layout of the memory zones is hardware dependent as not all architectures define all zones, and requirements for DMA are different for different platforms.”…””}”(hjƒhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KohjRhžhubeh}”(h]”jBah ]”h"]”Œzones”ah$]”h&]”uh1h¡hh£hžhhŸh¶h Kbubh¢)”}”(hhh]”(h§)”}”(hŒNodes”h]”hŒNodes”…””}”(hj›hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”j<j^uh1h¦hj˜hžhhŸh¶h Ktubh¸)”}”(hX$Many multi-processor machines are NUMA - Non-Uniform Memory Access - systems. In such systems the memory is arranged into banks that have different access latency depending on the "distance" from the processor. Each bank is referred to as a `node` and for each node Linux constructs an independent memory management subsystem. A node has its own set of zones, lists of free and used pages and various statistics counters. You can find more details about NUMA in Documentation/mm/numa.rst` and in Documentation/admin-guide/mm/numa_memory_policy.rst.”h]”(hŒõMany multi-processor machines are NUMA - Non-Uniform Memory Access - systems. In such systems the memory is arranged into banks that have different access latency depending on the “distance†from the processor. Each bank is referred to as a ”…””}”(hj©hžhhŸNh Nubjp)”}”(hŒ`node`”h]”hŒnode”…””}”(hj±hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1johj©ubhX- and for each node Linux constructs an independent memory management subsystem. A node has its own set of zones, lists of free and used pages and various statistics counters. You can find more details about NUMA in Documentation/mm/numa.rst` and in Documentation/admin-guide/mm/numa_memory_policy.rst.”…””}”(hj©hžhhŸNh Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Kvhj˜hžhubeh}”(h]”jdah ]”h"]”Œnodes”ah$]”h&]”uh1h¡hh£hžhhŸh¶h Ktubh¢)”}”(hhh]”(h§)”}”(hŒ Page cache”h]”hŒ Page cache”…””}”(hjÓhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”j<j€uh1h¦hjÐhžhhŸh¶h Kubh¸)”}”(hXThe physical memory is volatile and the common case for getting data into the memory is to read it from files. Whenever a file is read, the data is put into the `page cache` to avoid expensive disk access on the subsequent reads. Similarly, when one writes to a file, the data is placed in the page cache and eventually gets into the backing storage device. The written pages are marked as `dirty` and when Linux decides to reuse them for other purposes, it makes sure to synchronize the file contents on the device with the updated data.”h]”(hŒ¡The physical memory is volatile and the common case for getting data into the memory is to read it from files. Whenever a file is read, the data is put into the ”…””}”(hjáhžhhŸNh Nubjp)”}”(hŒ `page cache`”h]”hŒ page cache”…””}”(hjéhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1johjáubhŒÙ to avoid expensive disk access on the subsequent reads. Similarly, when one writes to a file, the data is placed in the page cache and eventually gets into the backing storage device. The written pages are marked as ”…””}”(hjáhžhhŸNh Nubjp)”}”(hŒ`dirty`”h]”hŒdirty”…””}”(hjûhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1johjáubhŒ and when Linux decides to reuse them for other purposes, it makes sure to synchronize the file contents on the device with the updated data.”…””}”(hjáhžhhŸNh Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KƒhjÐhžhubeh}”(h]”j†ah ]”h"]”Œ page cache”ah$]”h&]”uh1h¡hh£hžhhŸh¶h Kubh¢)”}”(hhh]”(h§)”}”(hŒAnonymous Memory”h]”hŒAnonymous Memory”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”j<j¢uh1h¦hjhžhhŸh¶h Kubh¸)”}”(hXŠThe `anonymous memory` or `anonymous mappings` represent memory that is not backed by a filesystem. Such mappings are implicitly created for program's stack and heap or by explicit calls to mmap(2) system call. Usually, the anonymous mappings only define virtual memory areas that the program is allowed to access. The read accesses will result in creation of a page table entry that references a special physical page filled with zeroes. When the program performs a write, a regular physical page will be allocated to hold the written data. The page will be marked dirty and if the kernel decides to repurpose it, the dirty page will be swapped out.”h]”(hŒThe ”…””}”(hj+hžhhŸNh Nubjp)”}”(hŒ`anonymous memory`”h]”hŒanonymous memory”…””}”(hj3hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1johj+ubhŒ or ”…””}”(hj+hžhhŸNh Nubjp)”}”(hŒ`anonymous mappings`”h]”hŒanonymous mappings”…””}”(hjEhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1johj+ubhX^ represent memory that is not backed by a filesystem. Such mappings are implicitly created for program’s stack and heap or by explicit calls to mmap(2) system call. Usually, the anonymous mappings only define virtual memory areas that the program is allowed to access. The read accesses will result in creation of a page table entry that references a special physical page filled with zeroes. When the program performs a write, a regular physical page will be allocated to hold the written data. The page will be marked dirty and if the kernel decides to repurpose it, the dirty page will be swapped out.”…””}”(hj+hžhhŸNh Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Khjhžhubeh}”(h]”j¨ah ]”h"]”Œanonymous memory”ah$]”h&]”uh1h¡hh£hžhhŸh¶h Kubh¢)”}”(hhh]”(h§)”}”(hŒReclaim”h]”hŒReclaim”…””}”(hjghžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”j<jÄuh1h¦hjdhžhhŸh¶h K›ubh¸)”}”(hŒÿThroughout the system lifetime, a physical page can be used for storing different types of data. It can be kernel internal data structures, DMA'able buffers for device drivers use, data read from a filesystem, memory allocated by user space processes etc.”h]”hXThroughout the system lifetime, a physical page can be used for storing different types of data. It can be kernel internal data structures, DMA’able buffers for device drivers use, data read from a filesystem, memory allocated by user space processes etc.”…””}”(hjuhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h Khjdhžhubh¸)”}”(hX…Depending on the page usage it is treated differently by the Linux memory management. The pages that can be freed at any time, either because they cache the data available elsewhere, for instance, on a hard disk, or because they can be swapped out, again, to the hard disk, are called `reclaimable`. The most notable categories of the reclaimable pages are page cache and anonymous memory.”h]”(hXDepending on the page usage it is treated differently by the Linux memory management. The pages that can be freed at any time, either because they cache the data available elsewhere, for instance, on a hard disk, or because they can be swapped out, again, to the hard disk, are called ”…””}”(hjƒhžhhŸNh Nubjp)”}”(hŒ `reclaimable`”h]”hŒ reclaimable”…””}”(hj‹hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1johjƒubhŒ[. The most notable categories of the reclaimable pages are page cache and anonymous memory.”…””}”(hjƒhžhhŸNh Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K¢hjdhžhubh¸)”}”(hXæIn most cases, the pages holding internal kernel data and used as DMA buffers cannot be repurposed, and they remain pinned until freed by their user. Such pages are called `unreclaimable`. However, in certain circumstances, even pages occupied with kernel data structures can be reclaimed. For instance, in-memory caches of filesystem metadata can be re-read from the storage device and therefore it is possible to discard them from the main memory when system is under memory pressure.”h]”(hŒ¬In most cases, the pages holding internal kernel data and used as DMA buffers cannot be repurposed, and they remain pinned until freed by their user. Such pages are called ”…””}”(hj£hžhhŸNh Nubjp)”}”(hŒ`unreclaimable`”h]”hŒ unreclaimable”…””}”(hj«hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1johj£ubhX+. However, in certain circumstances, even pages occupied with kernel data structures can be reclaimed. For instance, in-memory caches of filesystem metadata can be re-read from the storage device and therefore it is possible to discard them from the main memory when system is under memory pressure.”…””}”(hj£hžhhŸNh Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K©hjdhžhubh¸)”}”(hX²The process of freeing the reclaimable physical memory pages and repurposing them is called (surprise!) `reclaim`. Linux can reclaim pages either asynchronously or synchronously, depending on the state of the system. When the system is not loaded, most of the memory is free and allocation requests will be satisfied immediately from the free pages supply. As the load increases, the amount of the free pages goes down and when it reaches a certain threshold (low watermark), an allocation request will awaken the ``kswapd`` daemon. It will asynchronously scan memory pages and either just free them if the data they contain is available elsewhere, or evict to the backing storage device (remember those dirty pages?). As memory usage increases even more and reaches another threshold - min watermark - an allocation will trigger `direct reclaim`. In this case allocation is stalled until enough memory pages are reclaimed to satisfy the request.”h]”(hŒhThe process of freeing the reclaimable physical memory pages and repurposing them is called (surprise!) ”…””}”(hjÃhžhhŸNh Nubjp)”}”(hŒ `reclaim`”h]”hŒreclaim”…””}”(hjËhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1johjÃubhX‘. Linux can reclaim pages either asynchronously or synchronously, depending on the state of the system. When the system is not loaded, most of the memory is free and allocation requests will be satisfied immediately from the free pages supply. As the load increases, the amount of the free pages goes down and when it reaches a certain threshold (low watermark), an allocation request will awaken the ”…””}”(hjÃhžhhŸNh NubhÂ)”}”(hŒ ``kswapd``”h]”hŒkswapd”…””}”(hjÝhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÁhjÃubhX2 daemon. It will asynchronously scan memory pages and either just free them if the data they contain is available elsewhere, or evict to the backing storage device (remember those dirty pages?). As memory usage increases even more and reaches another threshold - min watermark - an allocation will trigger ”…””}”(hjÃhžhhŸNh Nubjp)”}”(hŒ`direct reclaim`”h]”hŒdirect reclaim”…””}”(hjïhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1johjÃubhŒd. In this case allocation is stalled until enough memory pages are reclaimed to satisfy the request.”…””}”(hjÃhžhhŸNh Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h K²hjdhžhubeh}”(h]”jÊah ]”h"]”Œreclaim”ah$]”h&]”uh1h¡hh£hžhhŸh¶h K›ubh¢)”}”(hhh]”(h§)”}”(hŒ Compaction”h]”hŒ Compaction”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”j<jæuh1h¦hjhžhhŸh¶h KÂubh¸)”}”(hXßAs the system runs, tasks allocate and free the memory and it becomes fragmented. Although with virtual memory it is possible to present scattered physical pages as virtually contiguous range, sometimes it is necessary to allocate large physically contiguous memory areas. Such need may arise, for instance, when a device driver requires a large buffer for DMA, or when THP allocates a huge page. Memory `compaction` addresses the fragmentation issue. This mechanism moves occupied pages from the lower part of a memory zone to free pages in the upper part of the zone. When a compaction scan is finished free pages are grouped together at the beginning of the zone and allocations of large physically contiguous areas become possible.”h]”(hX”As the system runs, tasks allocate and free the memory and it becomes fragmented. Although with virtual memory it is possible to present scattered physical pages as virtually contiguous range, sometimes it is necessary to allocate large physically contiguous memory areas. Such need may arise, for instance, when a device driver requires a large buffer for DMA, or when THP allocates a huge page. Memory ”…””}”(hjhžhhŸNh Nubjp)”}”(hŒ `compaction`”h]”hŒ compaction”…””}”(hj'hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1johjubhX? addresses the fragmentation issue. This mechanism moves occupied pages from the lower part of a memory zone to free pages in the upper part of the zone. When a compaction scan is finished free pages are grouped together at the beginning of the zone and allocations of large physically contiguous areas become possible.”…””}”(hjhžhhŸNh Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KÄhjhžhubh¸)”}”(hŒLike reclaim, the compaction may happen asynchronously in the ``kcompactd`` daemon or synchronously as a result of a memory allocation request.”h]”(hŒ>Like reclaim, the compaction may happen asynchronously in the ”…””}”(hj?hžhhŸNh NubhÂ)”}”(hŒ ``kcompactd``”h]”hŒ kcompactd”…””}”(hjGhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÁhj?ubhŒD daemon or synchronously as a result of a memory allocation request.”…””}”(hj?hžhhŸNh Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KÐhjhžhubeh}”(h]”jìah ]”h"]”Œ compaction”ah$]”h&]”uh1h¡hh£hžhhŸh¶h KÂubh¢)”}”(hhh]”(h§)”}”(hŒ OOM killer”h]”hŒ OOM killer”…””}”(hjihžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”j<juh1h¦hjfhžhhŸh¶h KÔubh¸)”}”(hŒÕIt is possible that on a loaded machine memory will be exhausted and the kernel will be unable to reclaim enough memory to continue to operate. In order to save the rest of the system, it invokes the `OOM killer`.”h]”(hŒÈIt is possible that on a loaded machine memory will be exhausted and the kernel will be unable to reclaim enough memory to continue to operate. In order to save the rest of the system, it invokes the ”…””}”(hjwhžhhŸNh Nubjp)”}”(hŒ `OOM killer`”h]”hŒ OOM killer”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1johjwubhŒ.”…””}”(hjwhžhhŸNh Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KÖhjfhžhubh¸)”}”(hŒËThe `OOM killer` selects a task to sacrifice for the sake of the overall system health. The selected task is killed in a hope that after it exits enough memory will be freed to continue normal operation.”h]”(hŒThe ”…””}”(hj—hžhhŸNh Nubjp)”}”(hŒ `OOM killer`”h]”hŒ OOM killer”…””}”(hjŸhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1johj—ubhŒ» selects a task to sacrifice for the sake of the overall system health. The selected task is killed in a hope that after it exits enough memory will be freed to continue normal operation.”…””}”(hj—hžhhŸNh Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1h·hŸh¶h KÚhjfhžhubeh}”(h]”jah ]”h"]”Œ oom killer”ah$]”h&]”uh1h¡hh£hžhhŸh¶h KÔubeh}”(h]”Œconcepts-overview”ah ]”h"]”Œconcepts overview”ah$]”h&]”uh1h¡hhhžhhŸh¶h Kubeh}”(h]”h ]”h"]”h$]”h&]”Œsource”h¶uh1hŒcurrent_source”NŒ current_line”NŒsettings”Œdocutils.frontend”ŒValues”“”)”}”(h¦NŒ generator”NŒ datestamp”NŒ source_link”NŒ source_url”NŒ toc_backlinks”Œentry”Œfootnote_backlinks”KŒ sectnum_xform”KŒstrip_comments”NŒstrip_elements_with_classes”NŒ strip_classes”NŒ report_level”KŒ halt_level”KŒexit_status_level”KŒdebug”NŒwarning_stream”NŒ traceback”ˆŒinput_encoding”Œ utf-8-sig”Œinput_encoding_error_handler”Œstrict”Œoutput_encoding”Œutf-8”Œoutput_encoding_error_handler”jéŒerror_encoding”Œutf-8”Œerror_encoding_error_handler”Œbackslashreplace”Œ language_code”Œen”Œrecord_dependencies”NŒconfig”NŒ id_prefix”hŒauto_id_prefix”Œid”Œ dump_settings”NŒdump_internals”NŒdump_transforms”NŒdump_pseudo_xml”NŒexpose_internals”NŒstrict_visitor”NŒ_disable_config”NŒ_source”h¶Œ _destination”NŒ _config_files”]”Œ7/var/lib/git/docbuild/linux/Documentation/docutils.conf”aŒfile_insertion_enabled”ˆŒ raw_enabled”KŒline_length_limit”M'Œpep_references”NŒ pep_base_url”Œhttps://peps.python.org/”Œpep_file_url_template”Œpep-%04d”Œrfc_references”NŒ rfc_base_url”Œ&https://datatracker.ietf.org/doc/html/”Œ tab_width”KŒtrim_footnote_reference_space”‰Œsyntax_highlight”Œlong”Œ smart_quotes”ˆŒsmartquotes_locales”]”Œcharacter_level_inline_markup”‰Œdoctitle_xform”‰Œ docinfo_xform”KŒsectsubtitle_xform”‰Œ image_loading”Œlink”Œembed_stylesheet”‰Œcloak_email_addresses”ˆŒsection_self_link”‰Œenv”NubŒreporter”NŒindirect_targets”]”Œsubstitution_defs”}”Œsubstitution_names”}”Œrefnames”}”Œrefids”}”Œnameids”}”(jÃjÀj(j#jÉhþjOj j•jBjÍjdjj†jaj¨j jÊjcjìj»juŒ nametypes”}”(jÉj(‰jɉjO‰j•‰j͉j‰ja‰j ‰jc‰j»‰uh}”(jÀh£j#hÝhþj+j jÌjBjRjdj˜j†jÐj¨jjÊjdjìjjjfhøhïjjj<j3j^jUj€jwj¢j™jÄj»jæjÝjjÿuŒ footnote_refs”}”Œ citation_refs”}”Œ autofootnotes”]”Œautofootnote_refs”]”Œsymbol_footnotes”]”Œsymbol_footnote_refs”]”Œ footnotes”]”Œ citations”]”Œautofootnote_start”KŒsymbol_footnote_start”KŒ id_counter”Œ collections”ŒCounter”“”}”j÷K s…”R”Œparse_messages”]”Œtransform_messages”]”Œ transformer”NŒ include_log”]”Œ decoration”Nhžhub.