sphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget$/translations/zh_CN/mm/vmemmap_dedupmodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget$/translations/zh_TW/mm/vmemmap_dedupmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget$/translations/it_IT/mm/vmemmap_dedupmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget$/translations/ja_JP/mm/vmemmap_dedupmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget$/translations/ko_KR/mm/vmemmap_dedupmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hPortuguese (Brazilian)}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget$/translations/pt_BR/mm/vmemmap_dedupmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget$/translations/sp_SP/mm/vmemmap_dedupmodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhcomment)}(h SPDX-License-Identifier: GPL-2.0h]h SPDX-License-Identifier: GPL-2.0}hhsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1hhhhhh>/var/lib/git/docbuild/linux/Documentation/mm/vmemmap_dedup.rsthKubhsection)}(hhh](htitle)}(h)A vmemmap diet for HugeTLB and Device DAXh]h)A vmemmap diet for HugeTLB and Device DAX}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hHugeTLBh]hHugeTLB}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhK ubh paragraph)}(hHThis section is to explain how HugeTLB Vmemmap Optimization (HVO) works.h]hHThis section is to explain how HugeTLB Vmemmap Optimization (HVO) works.}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK hhhhubh)}(hThe ``struct page`` structures are used to describe a physical page frame. By default, there is a one-to-one mapping from a page frame to its corresponding ``struct page``.h](hThe }(hhhhhNhNubhliteral)}(h``struct page``h]h struct page}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhhubh structures are used to describe a physical page frame. By default, there is a one-to-one mapping from a page frame to its corresponding }(hhhhhNhNubj)}(h``struct page``h]h struct page}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhhubh.}(hhhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK hhhhubh)}(hXHugeTLB pages consist of multiple base page size pages and is supported by many architectures. See Documentation/admin-guide/mm/hugetlbpage.rst for more details. On the x86-64 architecture, HugeTLB pages of size 2MB and 1GB are currently supported. Since the base page size on x86 is 4KB, a 2MB HugeTLB page consists of 512 base pages and a 1GB HugeTLB page consists of 262144 base pages. For each base page, there is a corresponding ``struct page``.h](hXHugeTLB pages consist of multiple base page size pages and is supported by many architectures. See Documentation/admin-guide/mm/hugetlbpage.rst for more details. On the x86-64 architecture, HugeTLB pages of size 2MB and 1GB are currently supported. Since the base page size on x86 is 4KB, a 2MB HugeTLB page consists of 512 base pages and a 1GB HugeTLB page consists of 262144 base pages. For each base page, there is a corresponding }(hj2hhhNhNubj)}(h``struct page``h]h struct page}(hj:hhhNhNubah}(h]h ]h"]h$]h&]uh1jhj2ubh.}(hj2hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hX6Within the HugeTLB subsystem, only the first 4 ``struct page`` are used to contain unique information about a HugeTLB page. ``__NR_USED_SUBPAGE`` provides this upper limit. The only 'useful' information in the remaining ``struct page`` is the compound_info field, and this field is the same for all tail pages.h](h/Within the HugeTLB subsystem, only the first 4 }(hjRhhhNhNubj)}(h``struct page``h]h struct page}(hjZhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjRubh> are used to contain unique information about a HugeTLB page. }(hjRhhhNhNubj)}(h``__NR_USED_SUBPAGE``h]h__NR_USED_SUBPAGE}(hjlhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjRubhO provides this upper limit. The only ‘useful’ information in the remaining }(hjRhhhNhNubj)}(h``struct page``h]h struct page}(hj~hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjRubhK is the compound_info field, and this field is the same for all tail pages.}(hjRhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hvBy removing redundant ``struct page`` for HugeTLB pages, memory can be returned to the buddy allocator for other uses.h](hBy removing redundant }(hjhhhNhNubj)}(h``struct page``h]h struct page}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhQ for HugeTLB pages, memory can be returned to the buddy allocator for other uses.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hX$Different architectures support different HugeTLB pages. For example, the following table is the HugeTLB page size supported by x86 and arm64 architectures. Because arm64 supports 4k, 16k, and 64k base pages and supports contiguous entries, so it supports many kinds of sizes of HugeTLB page.h]hX$Different architectures support different HugeTLB pages. For example, the following table is the HugeTLB page size supported by x86 and arm64 architectures. Because arm64 supports 4k, 16k, and 64k base pages and supports contiguous entries, so it supports many kinds of sizes of HugeTLB page.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK hhhhubhtable)}(hhh]htgroup)}(hhh](hcolspec)}(hhh]h}(h]h ]h"]h$]h&]colwidthKuh1jhjubj)}(hhh]h}(h]h ]h"]h$]h&]colwidthK uh1jhjubj)}(hhh]h}(h]h ]h"]h$]h&]colwidthK uh1jhjubj)}(hhh]h}(h]h ]h"]h$]h&]colwidthK uh1jhjubj)}(hhh]h}(h]h ]h"]h$]h&]colwidthK uh1jhjubj)}(hhh]h}(h]h ]h"]h$]h&]colwidthK uh1jhjubhtbody)}(hhh](hrow)}(hhh](hentry)}(hhh]h)}(h Architectureh]h Architecture}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK'hjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(h Page Sizeh]h Page Size}(hj2hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK'hj/ubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(hHugeTLB Page Sizeh]hHugeTLB Page Size}(hjIhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK'hjFubah}(h]h ]h"]h$]h&]morecolsKuh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh](j)}(hhh]h)}(hx86-64h]hx86-64}(hjjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK)hjgubah}(h]h ]h"]h$]h&]uh1jhjdubj)}(hhh]h)}(h4KBh]h4KB}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK)hj~ubah}(h]h ]h"]h$]h&]uh1jhjdubj)}(hhh]h)}(h2MBh]h2MB}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK)hjubah}(h]h ]h"]h$]h&]uh1jhjdubj)}(hhh]h)}(h1GBh]h1GB}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK)hjubah}(h]h ]h"]h$]h&]uh1jhjdubj)}(hhh]h}(h]h ]h"]h$]h&]uh1jhjdubj)}(hhh]h}(h]h ]h"]h$]h&]uh1jhjdubeh}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh](j)}(hhh]h)}(harm64h]harm64}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK-hjubah}(h]h ]h"]h$]h&]morerowsKuh1jhjubj)}(hhh]h)}(h4KBh]h4KB}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK+hjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(h64KBh]h64KB}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK+hj ubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(h2MBh]h2MB}(hj'hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK+hj$ubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(h32MBh]h32MB}(hj>hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK+hj;ubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(h1GBh]h1GB}(hjUhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK+hjRubah}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh](j)}(hhh]h)}(h16KBh]h16KB}(hjuhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK-hjrubah}(h]h ]h"]h$]h&]uh1jhjoubj)}(hhh]h)}(h2MBh]h2MB}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK-hjubah}(h]h ]h"]h$]h&]uh1jhjoubj)}(hhh]h)}(h32MBh]h32MB}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK-hjubah}(h]h ]h"]h$]h&]uh1jhjoubj)}(hhh]h)}(h1GBh]h1GB}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK-hjubah}(h]h ]h"]h$]h&]uh1jhjoubj)}(hhh]h}(h]h ]h"]h$]h&]uh1jhjoubeh}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh](j)}(hhh]h)}(h64KBh]h64KB}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK/hjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(h2MBh]h2MB}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK/hjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(h512MBh]h512MB}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK/hjubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h)}(h16GBh]h16GB}(hj(hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK/hj%ubah}(h]h ]h"]h$]h&]uh1jhjubj)}(hhh]h}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1jhjubeh}(h]h ]h"]h$]h&]uh1j hjubeh}(h]h ]h"]h$]h&]colsKuh1jhjubah}(h]h ]h"]h$]h&]uh1jhhhhhhhNubh)}(hsWhen the system boot up, every HugeTLB page has more than one ``struct page`` structs which size is (unit: pages)::h](h>When the system boot up, every HugeTLB page has more than one }(hj^hhhNhNubj)}(h``struct page``h]h struct page}(hjfhhhNhNubah}(h]h ]h"]h$]h&]uh1jhj^ubh% structs which size is (unit: pages):}(hj^hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK2hhhhubh literal_block)}(hHstruct_size = HugeTLB_Size / PAGE_SIZE * sizeof(struct page) / PAGE_SIZEh]hHstruct_size = HugeTLB_Size / PAGE_SIZE * sizeof(struct page) / PAGE_SIZE}hjsbah}(h]h ]h"]h$]h&]hhuh1j~hhhK5hhhhubh)}(hWhere HugeTLB_Size is the size of the HugeTLB page. We know that the size of the HugeTLB page is always n times PAGE_SIZE. So we can get the following relationship::h]hWhere HugeTLB_Size is the size of the HugeTLB page. We know that the size of the HugeTLB page is always n times PAGE_SIZE. So we can get the following relationship:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK7hhhhubj)}(hHugeTLB_Size = n * PAGE_SIZEh]hHugeTLB_Size = n * PAGE_SIZE}hjsbah}(h]h ]h"]h$]h&]hhuh1j~hhhK;hhhhubh)}(hThen::h]hThen:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK=hhhhubj)}(h{struct_size = n * PAGE_SIZE / PAGE_SIZE * sizeof(struct page) / PAGE_SIZE = n * sizeof(struct page) / PAGE_SIZEh]h{struct_size = n * PAGE_SIZE / PAGE_SIZE * sizeof(struct page) / PAGE_SIZE = n * sizeof(struct page) / PAGE_SIZE}hjsbah}(h]h ]h"]h$]h&]hhuh1j~hhhK?hhhhubh)}(hBWe can use huge mapping at the pud/pmd level for the HugeTLB page.h]hBWe can use huge mapping at the pud/pmd level for the HugeTLB page.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKBhhhhubh)}(h5For the HugeTLB page of the pmd level mapping, then::h]h4For the HugeTLB page of the pmd level mapping, then:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKDhhhhubj)}(hstruct_size = n * sizeof(struct page) / PAGE_SIZE = PAGE_SIZE / sizeof(pte_t) * sizeof(struct page) / PAGE_SIZE = sizeof(struct page) / sizeof(pte_t) = 64 / 8 = 8 (pages)h]hstruct_size = n * sizeof(struct page) / PAGE_SIZE = PAGE_SIZE / sizeof(pte_t) * sizeof(struct page) / PAGE_SIZE = sizeof(struct page) / sizeof(pte_t) = 64 / 8 = 8 (pages)}hjsbah}(h]h ]h"]h$]h&]hhuh1j~hhhKFhhhhubh)}(hnWhere n is how many pte entries which one page can contains. So the value of n is (PAGE_SIZE / sizeof(pte_t)).h]hnWhere n is how many pte entries which one page can contains. So the value of n is (PAGE_SIZE / sizeof(pte_t)).}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKLhhhhubh)}(hXThis optimization only supports 64-bit system, so the value of sizeof(pte_t) is 8. And this optimization also applicable only when the size of ``struct page`` is a power of two. In most cases, the size of ``struct page`` is 64 bytes (e.g. x86-64 and arm64). So if we use pmd level mapping for a HugeTLB page, the size of ``struct page`` structs of it is 8 page frames which size depends on the size of the base page.h](hThis optimization only supports 64-bit system, so the value of sizeof(pte_t) is 8. And this optimization also applicable only when the size of }(hjhhhNhNubj)}(h``struct page``h]h struct page}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh/ is a power of two. In most cases, the size of }(hjhhhNhNubj)}(h``struct page``h]h struct page}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhe is 64 bytes (e.g. x86-64 and arm64). So if we use pmd level mapping for a HugeTLB page, the size of }(hjhhhNhNubj)}(h``struct page``h]h struct page}(hj*hhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubhP structs of it is 8 page frames which size depends on the size of the base page.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKOhhhhubh)}(h5For the HugeTLB page of the pud level mapping, then::h]h4For the HugeTLB page of the pud level mapping, then:}(hjBhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKVhhhhubj)}(hstruct_size = PAGE_SIZE / sizeof(pmd_t) * struct_size(pmd) = PAGE_SIZE / 8 * 8 (pages) = PAGE_SIZE (pages)h]hstruct_size = PAGE_SIZE / sizeof(pmd_t) * struct_size(pmd) = PAGE_SIZE / 8 * 8 (pages) = PAGE_SIZE (pages)}hjPsbah}(h]h ]h"]h$]h&]hhuh1j~hhhKXhhhhubh)}(hqWhere the struct_size(pmd) is the size of the ``struct page`` structs of a HugeTLB page of the pmd level mapping.h](h.Where the struct_size(pmd) is the size of the }(hj^hhhNhNubj)}(h``struct page``h]h struct page}(hjfhhhNhNubah}(h]h ]h"]h$]h&]uh1jhj^ubh4 structs of a HugeTLB page of the pmd level mapping.}(hj^hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK\hhhhubh)}(heE.g.: A 2MB HugeTLB page on x86_64 consists in 8 page frames while 1GB HugeTLB page consists in 4096.h]heE.g.: A 2MB HugeTLB page on x86_64 consists in 8 page frames while 1GB HugeTLB page consists in 4096.}(hj~hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK_hhhhubh)}(hNext, we take the pmd level mapping of the HugeTLB page as an example to show the internal implementation of this optimization. There are 8 pages ``struct page`` structs associated with a HugeTLB page which is pmd mapped.h](hNext, we take the pmd level mapping of the HugeTLB page as an example to show the internal implementation of this optimization. There are 8 pages }(hjhhhNhNubj)}(h``struct page``h]h struct page}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh< structs associated with a HugeTLB page which is pmd mapped.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKbhhhhubh)}(h-Here is how things look before optimization::h]h,Here is how things look before optimization:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKfhhhhubj)}(hX HugeTLB struct pages(8 pages) page frame(8 pages) +-----------+ ---virt_to_page---> +-----------+ mapping to +-----------+ | | | 0 | -------------> | 0 | | | +-----------+ +-----------+ | | | 1 | -------------> | 1 | | | +-----------+ +-----------+ | | | 2 | -------------> | 2 | | | +-----------+ +-----------+ | | | 3 | -------------> | 3 | | | +-----------+ +-----------+ | | | 4 | -------------> | 4 | | PMD | +-----------+ +-----------+ | level | | 5 | -------------> | 5 | | mapping | +-----------+ +-----------+ | | | 6 | -------------> | 6 | | | +-----------+ +-----------+ | | | 7 | -------------> | 7 | | | +-----------+ +-----------+ | | | | | | +-----------+h]hX HugeTLB struct pages(8 pages) page frame(8 pages) +-----------+ ---virt_to_page---> +-----------+ mapping to +-----------+ | | | 0 | -------------> | 0 | | | +-----------+ +-----------+ | | | 1 | -------------> | 1 | | | +-----------+ +-----------+ | | | 2 | -------------> | 2 | | | +-----------+ +-----------+ | | | 3 | -------------> | 3 | | | +-----------+ +-----------+ | | | 4 | -------------> | 4 | | PMD | +-----------+ +-----------+ | level | | 5 | -------------> | 5 | | mapping | +-----------+ +-----------+ | | | 6 | -------------> | 6 | | | +-----------+ +-----------+ | | | 7 | -------------> | 7 | | | +-----------+ +-----------+ | | | | | | +-----------+}hjsbah}(h]h ]h"]h$]h&]hhuh1j~hhhKhhhhhubh)}(hThe first page of ``struct page`` (page 0) associated with the HugeTLB page contains the 4 ``struct page`` necessary to describe the HugeTLB. The remaining pages of ``struct page`` (page 1 to page 7) are tail pages.h](hThe first page of }(hjhhhNhNubj)}(h``struct page``h]h struct page}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh: (page 0) associated with the HugeTLB page contains the 4 }(hjhhhNhNubj)}(h``struct page``h]h struct page}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh; necessary to describe the HugeTLB. The remaining pages of }(hjhhhNhNubj)}(h``struct page``h]h struct page}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh# (page 1 to page 7) are tail pages.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hXZThe optimization is only applied when the size of the struct page is a power of 2. In this case, all tail pages of the same order are identical. See compound_head(). This allows us to remap the tail pages of the vmemmap to a shared, read-only page. The head page is also remapped to a new page. This allows the original vmemmap pages to be freed.h]hXZThe optimization is only applied when the size of the struct page is a power of 2. In this case, all tail pages of the same order are identical. See compound_head(). This allows us to remap the tail pages of the vmemmap to a shared, read-only page. The head page is also remapped to a new page. This allows the original vmemmap pages to be freed.}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(h)Here is how things look after remapping::h]h(Here is how things look after remapping:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubj)}(hXT HugeTLB struct pages(8 pages) page frame (new) +-----------+ ---virt_to_page---> +-----------+ mapping to +----------------+ | | | 0 | -------------> | 0 | | | +-----------+ +----------------+ | | | 1 | ------┐ | | +-----------+ | | | | 2 | ------┼ +----------------------------+ | | +-----------+ | | A single, per-zone page | | | | 3 | ------┼------> | frame shared among all | | | +-----------+ | | hugepages of the same size | | | | 4 | ------┼ +----------------------------+ | | +-----------+ | | | | 5 | ------┼ | PMD | +-----------+ | | level | | 6 | ------┼ | mapping | +-----------+ | | | | 7 | ------┘ | | +-----------+ | | | | | | +-----------+h]hXT HugeTLB struct pages(8 pages) page frame (new) +-----------+ ---virt_to_page---> +-----------+ mapping to +----------------+ | | | 0 | -------------> | 0 | | | +-----------+ +----------------+ | | | 1 | ------┐ | | +-----------+ | | | | 2 | ------┼ +----------------------------+ | | +-----------+ | | A single, per-zone page | | | | 3 | ------┼------> | frame shared among all | | | +-----------+ | | hugepages of the same size | | | | 4 | ------┼ +----------------------------+ | | +-----------+ | | | | 5 | ------┼ | PMD | +-----------+ | | level | | 6 | ------┼ | mapping | +-----------+ | | | | 7 | ------┘ | | +-----------+ | | | | | | +-----------+}hj(sbah}(h]h ]h"]h$]h&]hhuh1j~hhhKhhhhubh)}(hWhen a HugeTLB is freed to the buddy system, we should allocate 7 pages for vmemmap pages and restore the previous mapping relationship.h]hWhen a HugeTLB is freed to the buddy system, we should allocate 7 pages for vmemmap pages and restore the previous mapping relationship.}(hj6hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hFor the HugeTLB page of the pud level mapping. It is similar to the former. We also can use this approach to free (PAGE_SIZE - 1) vmemmap pages.h]hFor the HugeTLB page of the pud level mapping. It is similar to the former. We also can use this approach to free (PAGE_SIZE - 1) vmemmap pages.}(hjDhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hXApart from the HugeTLB page of the pmd/pud level mapping, some architectures (e.g. aarch64) provides a contiguous bit in the translation table entries that hints to the MMU to indicate that it is one of a contiguous set of entries that can be cached in a single TLB entry.h]hXApart from the HugeTLB page of the pmd/pud level mapping, some architectures (e.g. aarch64) provides a contiguous bit in the translation table entries that hints to the MMU to indicate that it is one of a contiguous set of entries that can be cached in a single TLB entry.}(hjRhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hThe contiguous bit is used to increase the mapping size at the pmd and pte (last) level. So this type of HugeTLB page can be optimized only when its size of the ``struct page`` structs is greater than **1** page.h](hThe contiguous bit is used to increase the mapping size at the pmd and pte (last) level. So this type of HugeTLB page can be optimized only when its size of the }(hj`hhhNhNubj)}(h``struct page``h]h struct page}(hjhhhhNhNubah}(h]h ]h"]h$]h&]uh1jhj`ubh structs is greater than }(hj`hhhNhNubhstrong)}(h**1**h]h1}(hj|hhhNhNubah}(h]h ]h"]h$]h&]uh1jzhj`ubh page.}(hj`hhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhhhhubeh}(h]hugetlbah ]h"]hugetlbah$]h&]uh1hhhhhhhhK ubh)}(hhh](h)}(h Device DAXh]h Device DAX}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hThe device-dax interface uses the same tail deduplication technique explained in the previous chapter, except when used with the vmemmap in the device (altmap).h]hThe device-dax interface uses the same tail deduplication technique explained in the previous chapter, except when used with the vmemmap in the device (altmap).}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hThe following page sizes are supported in DAX: PAGE_SIZE (4K on x86_64), PMD_SIZE (2M on x86_64) and PUD_SIZE (1G on x86_64). For powerpc equivalent details see Documentation/arch/powerpc/vmemmap_dedup.rsth]hThe following page sizes are supported in DAX: PAGE_SIZE (4K on x86_64), PMD_SIZE (2M on x86_64) and PUD_SIZE (1G on x86_64). For powerpc equivalent details see Documentation/arch/powerpc/vmemmap_dedup.rst}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(h2The differences with HugeTLB are relatively minor.h]h2The differences with HugeTLB are relatively minor.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(h[It only use 3 ``struct page`` for storing all information as opposed to 4 on HugeTLB pages.h](hIt only use 3 }(hjhhhNhNubj)}(h``struct page``h]h struct page}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjubh> for storing all information as opposed to 4 on HugeTLB pages.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hXqThere's no remapping of vmemmap given that device-dax memory is not part of System RAM ranges initialized at boot. Thus the tail page deduplication happens at a later stage when we populate the sections. HugeTLB reuses the the head vmemmap page representing, whereas device-dax reuses the tail vmemmap page. This results in only half of the savings compared to HugeTLB.h]hXsThere’s no remapping of vmemmap given that device-dax memory is not part of System RAM ranges initialized at boot. Thus the tail page deduplication happens at a later stage when we populate the sections. HugeTLB reuses the the head vmemmap page representing, whereas device-dax reuses the tail vmemmap page. This results in only half of the savings compared to HugeTLB.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(h1Deduplicated tail pages are not mapped read-only.h]h1Deduplicated tail pages are not mapped read-only.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hLHere's how things look like on device-dax after the sections are populated::h]hMHere’s how things look like on device-dax after the sections are populated:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(hX,+-----------+ ---virt_to_page---> +-----------+ mapping to +-----------+ | | | 0 | -------------> | 0 | | | +-----------+ +-----------+ | | | 1 | -------------> | 1 | | | +-----------+ +-----------+ | | | 2 | ----------------^ ^ ^ ^ ^ ^ | | +-----------+ | | | | | | | | 3 | ------------------+ | | | | | | +-----------+ | | | | | | | 4 | --------------------+ | | | | PMD | +-----------+ | | | | level | | 5 | ----------------------+ | | | mapping | +-----------+ | | | | | 6 | ------------------------+ | | | +-----------+ | | | | 7 | --------------------------+ | | +-----------+ | | | | | | +-----------+h]hX,+-----------+ ---virt_to_page---> +-----------+ mapping to +-----------+ | | | 0 | -------------> | 0 | | | +-----------+ +-----------+ | | | 1 | -------------> | 1 | | | +-----------+ +-----------+ | | | 2 | ----------------^ ^ ^ ^ ^ ^ | | +-----------+ | | | | | | | | 3 | ------------------+ | | | | | | +-----------+ | | | | | | | 4 | --------------------+ | | | | PMD | +-----------+ | | | | level | | 5 | ----------------------+ | | | mapping | +-----------+ | | | | | 6 | ------------------------+ | | | +-----------+ | | | | 7 | --------------------------+ | | +-----------+ | | | | | | +-----------+}hj!sbah}(h]h ]h"]h$]h&]hhuh1j~hhhKhjhhubeh}(h] device-daxah ]h"] device daxah$]h&]uh1hhhhhhhhKubeh}(h])a-vmemmap-diet-for-hugetlb-and-device-daxah ]h"])a vmemmap diet for hugetlb and device daxah$]h&]uh1hhhhhhhhKubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksjfootnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerjaerror_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourcehnj _destinationN _config_files]7/var/lib/git/docbuild/linux/Documentation/docutils.confafile_insertion_enabled raw_enabledKline_length_limitM'pep_referencesN pep_base_urlhttps://peps.python.org/pep_file_url_templatepep-%04drfc_referencesN rfc_base_url&https://datatracker.ietf.org/doc/html/ tab_widthKtrim_footnote_reference_spacesyntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xform image_loadinglinkembed_stylesheetcloak_email_addressessection_self_linkenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}refids}nameids}(j<j9jjj4j1u nametypes}(j<jj4uh}(j9hjhj1ju footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}Rparse_messages]transform_messages] transformerN include_log] decorationNhhub.