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]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}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhubh 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 }(hhhhhNhNubh)}(h``struct page``h]h struct page}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhubh.}(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 }(hjhhhNhNubh)}(h``struct page``h]h struct page}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh.}(hjhhhNhNubeh}(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_head field, and this field is the same for all tail pages.h](h/Within the HugeTLB subsystem, only the first 4 }(hj>hhhNhNubh)}(h``struct page``h]h struct page}(hjFhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj>ubh> are used to contain unique information about a HugeTLB page. }(hj>hhhNhNubh)}(h``__NR_USED_SUBPAGE``h]h__NR_USED_SUBPAGE}(hjXhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj>ubhO provides this upper limit. The only ‘useful’ information in the remaining }(hj>hhhNhNubh)}(h``struct page``h]h struct page}(hjjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj>ubhK is the compound_head field, and this field is the same for all tail pages.}(hj>hhhNhNubeh}(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 }(hjhhhNhNubh)}(h``struct page``h]h struct page}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubhQ 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}(hjhh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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&]uh1jhjubeh}(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 }(hjJhhhNhNubh)}(h``struct page``h]h struct page}(hjRhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjJubh% structs which size is (unit: pages):}(hjJhhhNhNubeh}(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}hjlsbah}(h]h ]h"]h$]h&]hhuh1jjhhhK5hhhhubh)}(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:}(hjzhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK7hhhhubjk)}(hHugeTLB_Size = n * PAGE_SIZEh]hHugeTLB_Size = n * PAGE_SIZE}hjsbah}(h]h ]h"]h$]h&]hhuh1jjhhhK;hhhhubh)}(hThen::h]hThen:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK=hhhhubjk)}(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&]hhuh1jjhhhK?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&]uh1hhhhKDhhhhubjk)}(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&]hhuh1jjhhhKFhhhhubh)}(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 }(hjhhhNhNubh)}(h``struct page``h]h struct page}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh/ is a power of two. In most cases, the size of }(hjhhhNhNubh)}(h``struct page``h]h struct page}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubhe is 64 bytes (e.g. x86-64 and arm64). So if we use pmd level mapping for a HugeTLB page, the size of }(hjhhhNhNubh)}(h``struct page``h]h struct page}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubhP 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:}(hj.hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKVhhhhubjk)}(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)}hj<sbah}(h]h ]h"]h$]h&]hhuh1jjhhhKXhhhhubh)}(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 }(hjJhhhNhNubh)}(h``struct page``h]h struct page}(hjRhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjJubh4 structs of a HugeTLB page of the pmd level mapping.}(hjJhhhNhNubeh}(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.}(hjjhhhNhNubah}(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 }(hjxhhhNhNubh)}(h``struct page``h]h struct page}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjxubh< structs associated with a HugeTLB page which is pmd mapped.}(hjxhhhNhNubeh}(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&]uh1hhhhKfhhhhubjk)}(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&]hhuh1jjhhhKhhhhhubh)}(hXThe value of page->compound_head is the same for all tail pages. The first page of ``struct page`` (page 0) associated with the HugeTLB page contains the 4 ``struct page`` necessary to describe the HugeTLB. The only use of the remaining pages of ``struct page`` (page 1 to page 7) is to point to page->compound_head. Therefore, we can remap pages 1 to 7 to page 0. Only 1 page of ``struct page`` will be used for each HugeTLB page. This will allow us to free the remaining 7 pages to the buddy allocator.h](hSThe value of page->compound_head is the same for all tail pages. The first page of }(hjhhhNhNubh)}(h``struct page``h]h struct page}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh: (page 0) associated with the HugeTLB page contains the 4 }(hjhhhNhNubh)}(h``struct page``h]h struct page}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubhK necessary to describe the HugeTLB. The only use of the remaining pages of }(hjhhhNhNubh)}(h``struct page``h]h struct page}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubhw (page 1 to page 7) is to point to page->compound_head. Therefore, we can remap pages 1 to 7 to page 0. Only 1 page of }(hjhhhNhNubh)}(h``struct page``h]h struct page}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubhm will be used for each HugeTLB page. This will allow us to free the remaining 7 pages to the buddy allocator.}(hjhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(h)Here is how things look after remapping::h]h(Here is how things look after remapping:}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhhhhubjk)}(hX HugeTLB struct pages(8 pages) page frame(8 pages) +-----------+ ---virt_to_page---> +-----------+ mapping to +-----------+ | | | 0 | -------------> | 0 | | | +-----------+ +-----------+ | | | 1 | ---------------^ ^ ^ ^ ^ ^ ^ | | +-----------+ | | | | | | | | | 2 | -----------------+ | | | | | | | +-----------+ | | | | | | | | 3 | -------------------+ | | | | | | +-----------+ | | | | | | | 4 | ---------------------+ | | | | PMD | +-----------+ | | | | level | | 5 | -----------------------+ | | | mapping | +-----------+ | | | | | 6 | -------------------------+ | | | +-----------+ | | | | 7 | ---------------------------+ | | +-----------+ | | | | | | +-----------+h]hX HugeTLB struct pages(8 pages) page frame(8 pages) +-----------+ ---virt_to_page---> +-----------+ mapping to +-----------+ | | | 0 | -------------> | 0 | | | +-----------+ +-----------+ | | | 1 | ---------------^ ^ ^ ^ ^ ^ ^ | | +-----------+ | | | | | | | | | 2 | -----------------+ | | | | | | | +-----------+ | | | | | | | | 3 | -------------------+ | | | | | | +-----------+ | | | | | | | 4 | ---------------------+ | | | | PMD | +-----------+ | | | | level | | 5 | -----------------------+ | | | mapping | +-----------+ | | | | | 6 | -------------------------+ | | | +-----------+ | | | | 7 | ---------------------------+ | | +-----------+ | | | | | | +-----------+}hjsbah}(h]h ]h"]h$]h&]hhuh1jjhhhKhhhhubh)}(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.}(hj&hhhNhNubah}(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.}(hj4hhhNhNubah}(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.}(hjBhhhNhNubah}(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 }(hjPhhhNhNubh)}(h``struct page``h]h struct page}(hjXhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjPubh structs is greater than }(hjPhhhNhNubhstrong)}(h**1**h]h1}(hjlhhhNhNubah}(h]h ]h"]h$]h&]uh1jjhjPubh page.}(hjPhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(hXNotice: The head vmemmap page is not freed to the buddy allocator and all tail vmemmap pages are mapped to the head vmemmap page frame. So we can see more than one ``struct page`` struct with ``PG_head`` (e.g. 8 per 2 MB HugeTLB page) associated with each HugeTLB page. The ``compound_head()`` can handle this correctly. There is only **one** head ``struct page``, the tail ``struct page`` with ``PG_head`` are fake head ``struct page``. We need an approach to distinguish between those two different types of ``struct page`` so that ``compound_head()`` can return the real head ``struct page`` when the parameter is the tail ``struct page`` but with ``PG_head``.h](hNotice: The head vmemmap page is not freed to the buddy allocator and all tail vmemmap pages are mapped to the head vmemmap page frame. So we can see more than one }(hjhhhNhNubh)}(h``struct page``h]h struct page}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh struct with }(hjhhhNhNubh)}(h ``PG_head``h]hPG_head}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubhG (e.g. 8 per 2 MB HugeTLB page) associated with each HugeTLB page. The }(hjhhhNhNubh)}(h``compound_head()``h]hcompound_head()}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh* can handle this correctly. There is only }(hjhhhNhNubjk)}(h**one**h]hone}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jjhjubh head }(hjhhhNhNubh)}(h``struct page``h]h struct page}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh , the tail }(hjhhhNhNubh)}(h``struct page``h]h struct page}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh with }(hjhhhNhNubh)}(h ``PG_head``h]hPG_head}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh are fake head }(hjhhhNhNubh)}(h``struct page``h]h struct page}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubhK. We need an approach to distinguish between those two different types of }(hjhhhNhNubh)}(h``struct page``h]h struct page}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh so that }(hjhhhNhNubh)}(h``compound_head()``h]hcompound_head()}(hj.hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh can return the real head }(hjhhhNhNubh)}(h``struct page``h]h struct page}(hj@hhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh when the parameter is the tail }(hjhhhNhNubh)}(h``struct page``h]h struct page}(hjRhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh but with }(hjhhhNhNubh)}(h ``PG_head``h]hPG_head}(hjdhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh.}(hjhhhNhNubeh}(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 }(hjhhhNhNubh)}(h``struct page``h]h struct page}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjubh> 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&]uh1hhhhKhjhhubjk)}(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&]hhuh1jjhhhKhjhhubeh}(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_handlerjIerror_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourceh _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$j!jj~jju nametypes}(j$jjuh}(j!hj~hjju 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.