xref: /openbmc/linux/Documentation/powerpc/vmemmap_dedup.rst (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
1*f2b79c0dSAneesh Kumar K.V.. SPDX-License-Identifier: GPL-2.0
2*f2b79c0dSAneesh Kumar K.V
3*f2b79c0dSAneesh Kumar K.V==========
4*f2b79c0dSAneesh Kumar K.VDevice DAX
5*f2b79c0dSAneesh Kumar K.V==========
6*f2b79c0dSAneesh Kumar K.V
7*f2b79c0dSAneesh Kumar K.VThe device-dax interface uses the tail deduplication technique explained in
8*f2b79c0dSAneesh Kumar K.VDocumentation/mm/vmemmap_dedup.rst
9*f2b79c0dSAneesh Kumar K.V
10*f2b79c0dSAneesh Kumar K.VOn powerpc, vmemmap deduplication is only used with radix MMU translation. Also
11*f2b79c0dSAneesh Kumar K.Vwith a 64K page size, only the devdax namespace with 1G alignment uses vmemmap
12*f2b79c0dSAneesh Kumar K.Vdeduplication.
13*f2b79c0dSAneesh Kumar K.V
14*f2b79c0dSAneesh Kumar K.VWith 2M PMD level mapping, we require 32 struct pages and a single 64K vmemmap
15*f2b79c0dSAneesh Kumar K.Vpage can contain 1024 struct pages (64K/sizeof(struct page)). Hence there is no
16*f2b79c0dSAneesh Kumar K.Vvmemmap deduplication possible.
17*f2b79c0dSAneesh Kumar K.V
18*f2b79c0dSAneesh Kumar K.VWith 1G PUD level mapping, we require 16384 struct pages and a single 64K
19*f2b79c0dSAneesh Kumar K.Vvmemmap page can contain 1024 struct pages (64K/sizeof(struct page)). Hence we
20*f2b79c0dSAneesh Kumar K.Vrequire 16 64K pages in vmemmap to map the struct page for 1G PUD level mapping.
21*f2b79c0dSAneesh Kumar K.V
22*f2b79c0dSAneesh Kumar K.VHere's how things look like on device-dax after the sections are populated::
23*f2b79c0dSAneesh Kumar K.V +-----------+ ---virt_to_page---> +-----------+   mapping to   +-----------+
24*f2b79c0dSAneesh Kumar K.V |           |                     |     0     | -------------> |     0     |
25*f2b79c0dSAneesh Kumar K.V |           |                     +-----------+                +-----------+
26*f2b79c0dSAneesh Kumar K.V |           |                     |     1     | -------------> |     1     |
27*f2b79c0dSAneesh Kumar K.V |           |                     +-----------+                +-----------+
28*f2b79c0dSAneesh Kumar K.V |           |                     |     2     | ----------------^ ^ ^ ^ ^ ^
29*f2b79c0dSAneesh Kumar K.V |           |                     +-----------+                   | | | | |
30*f2b79c0dSAneesh Kumar K.V |           |                     |     3     | ------------------+ | | | |
31*f2b79c0dSAneesh Kumar K.V |           |                     +-----------+                     | | | |
32*f2b79c0dSAneesh Kumar K.V |           |                     |     4     | --------------------+ | | |
33*f2b79c0dSAneesh Kumar K.V |    PUD    |                     +-----------+                       | | |
34*f2b79c0dSAneesh Kumar K.V |   level   |                     |     .     | ----------------------+ | |
35*f2b79c0dSAneesh Kumar K.V |  mapping  |                     +-----------+                         | |
36*f2b79c0dSAneesh Kumar K.V |           |                     |     .     | ------------------------+ |
37*f2b79c0dSAneesh Kumar K.V |           |                     +-----------+                           |
38*f2b79c0dSAneesh Kumar K.V |           |                     |     15    | --------------------------+
39*f2b79c0dSAneesh Kumar K.V |           |                     +-----------+
40*f2b79c0dSAneesh Kumar K.V |           |
41*f2b79c0dSAneesh Kumar K.V |           |
42*f2b79c0dSAneesh Kumar K.V |           |
43*f2b79c0dSAneesh Kumar K.V +-----------+
44*f2b79c0dSAneesh Kumar K.V
45*f2b79c0dSAneesh Kumar K.V
46*f2b79c0dSAneesh Kumar K.VWith 4K page size, 2M PMD level mapping requires 512 struct pages and a single
47*f2b79c0dSAneesh Kumar K.V4K vmemmap page contains 64 struct pages(4K/sizeof(struct page)). Hence we
48*f2b79c0dSAneesh Kumar K.Vrequire 8 4K pages in vmemmap to map the struct page for 2M pmd level mapping.
49*f2b79c0dSAneesh Kumar K.V
50*f2b79c0dSAneesh Kumar K.VHere's how things look like on device-dax after the sections are populated::
51*f2b79c0dSAneesh Kumar K.V
52*f2b79c0dSAneesh Kumar K.V +-----------+ ---virt_to_page---> +-----------+   mapping to   +-----------+
53*f2b79c0dSAneesh Kumar K.V |           |                     |     0     | -------------> |     0     |
54*f2b79c0dSAneesh Kumar K.V |           |                     +-----------+                +-----------+
55*f2b79c0dSAneesh Kumar K.V |           |                     |     1     | -------------> |     1     |
56*f2b79c0dSAneesh Kumar K.V |           |                     +-----------+                +-----------+
57*f2b79c0dSAneesh Kumar K.V |           |                     |     2     | ----------------^ ^ ^ ^ ^ ^
58*f2b79c0dSAneesh Kumar K.V |           |                     +-----------+                   | | | | |
59*f2b79c0dSAneesh Kumar K.V |           |                     |     3     | ------------------+ | | | |
60*f2b79c0dSAneesh Kumar K.V |           |                     +-----------+                     | | | |
61*f2b79c0dSAneesh Kumar K.V |           |                     |     4     | --------------------+ | | |
62*f2b79c0dSAneesh Kumar K.V |    PMD    |                     +-----------+                       | | |
63*f2b79c0dSAneesh Kumar K.V |   level   |                     |     5     | ----------------------+ | |
64*f2b79c0dSAneesh Kumar K.V |  mapping  |                     +-----------+                         | |
65*f2b79c0dSAneesh Kumar K.V |           |                     |     6     | ------------------------+ |
66*f2b79c0dSAneesh Kumar K.V |           |                     +-----------+                           |
67*f2b79c0dSAneesh Kumar K.V |           |                     |     7     | --------------------------+
68*f2b79c0dSAneesh Kumar K.V |           |                     +-----------+
69*f2b79c0dSAneesh Kumar K.V |           |
70*f2b79c0dSAneesh Kumar K.V |           |
71*f2b79c0dSAneesh Kumar K.V |           |
72*f2b79c0dSAneesh Kumar K.V +-----------+
73*f2b79c0dSAneesh Kumar K.V
74*f2b79c0dSAneesh Kumar K.VWith 1G PUD level mapping, we require 262144 struct pages and a single 4K
75*f2b79c0dSAneesh Kumar K.Vvmemmap page can contain 64 struct pages (4K/sizeof(struct page)). Hence we
76*f2b79c0dSAneesh Kumar K.Vrequire 4096 4K pages in vmemmap to map the struct pages for 1G PUD level
77*f2b79c0dSAneesh Kumar K.Vmapping.
78*f2b79c0dSAneesh Kumar K.V
79*f2b79c0dSAneesh Kumar K.VHere's how things look like on device-dax after the sections are populated::
80*f2b79c0dSAneesh Kumar K.V
81*f2b79c0dSAneesh Kumar K.V +-----------+ ---virt_to_page---> +-----------+   mapping to   +-----------+
82*f2b79c0dSAneesh Kumar K.V |           |                     |     0     | -------------> |     0     |
83*f2b79c0dSAneesh Kumar K.V |           |                     +-----------+                +-----------+
84*f2b79c0dSAneesh Kumar K.V |           |                     |     1     | -------------> |     1     |
85*f2b79c0dSAneesh Kumar K.V |           |                     +-----------+                +-----------+
86*f2b79c0dSAneesh Kumar K.V |           |                     |     2     | ----------------^ ^ ^ ^ ^ ^
87*f2b79c0dSAneesh Kumar K.V |           |                     +-----------+                   | | | | |
88*f2b79c0dSAneesh Kumar K.V |           |                     |     3     | ------------------+ | | | |
89*f2b79c0dSAneesh Kumar K.V |           |                     +-----------+                     | | | |
90*f2b79c0dSAneesh Kumar K.V |           |                     |     4     | --------------------+ | | |
91*f2b79c0dSAneesh Kumar K.V |    PUD    |                     +-----------+                       | | |
92*f2b79c0dSAneesh Kumar K.V |   level   |                     |     .     | ----------------------+ | |
93*f2b79c0dSAneesh Kumar K.V |  mapping  |                     +-----------+                         | |
94*f2b79c0dSAneesh Kumar K.V |           |                     |     .     | ------------------------+ |
95*f2b79c0dSAneesh Kumar K.V |           |                     +-----------+                           |
96*f2b79c0dSAneesh Kumar K.V |           |                     |   4095    | --------------------------+
97*f2b79c0dSAneesh Kumar K.V |           |                     +-----------+
98*f2b79c0dSAneesh Kumar K.V |           |
99*f2b79c0dSAneesh Kumar K.V |           |
100*f2b79c0dSAneesh Kumar K.V |           |
101*f2b79c0dSAneesh Kumar K.V +-----------+
102