~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/Documentation/admin-guide/mm/transhuge.rst

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /Documentation/admin-guide/mm/transhuge.rst (Version linux-6.12-rc7) and /Documentation/admin-guide/mm/transhuge.rst (Version linux-6.4.16)


  1 ============================                        1 ============================
  2 Transparent Hugepage Support                        2 Transparent Hugepage Support
  3 ============================                        3 ============================
  4                                                     4 
  5 Objective                                           5 Objective
  6 =========                                           6 =========
  7                                                     7 
  8 Performance critical computing applications de      8 Performance critical computing applications dealing with large memory
  9 working sets are already running on top of lib      9 working sets are already running on top of libhugetlbfs and in turn
 10 hugetlbfs. Transparent HugePage Support (THP)      10 hugetlbfs. Transparent HugePage Support (THP) is an alternative mean of
 11 using huge pages for the backing of virtual me     11 using huge pages for the backing of virtual memory with huge pages
 12 that supports the automatic promotion and demo     12 that supports the automatic promotion and demotion of page sizes and
 13 without the shortcomings of hugetlbfs.             13 without the shortcomings of hugetlbfs.
 14                                                    14 
 15 Currently THP only works for anonymous memory      15 Currently THP only works for anonymous memory mappings and tmpfs/shmem.
 16 But in the future it can expand to other files     16 But in the future it can expand to other filesystems.
 17                                                    17 
 18 .. note::                                          18 .. note::
 19    in the examples below we presume that the b     19    in the examples below we presume that the basic page size is 4K and
 20    the huge page size is 2M, although the actu     20    the huge page size is 2M, although the actual numbers may vary
 21    depending on the CPU architecture.              21    depending on the CPU architecture.
 22                                                    22 
 23 The reason applications are running faster is      23 The reason applications are running faster is because of two
 24 factors. The first factor is almost completely     24 factors. The first factor is almost completely irrelevant and it's not
 25 of significant interest because it'll also hav     25 of significant interest because it'll also have the downside of
 26 requiring larger clear-page copy-page in page      26 requiring larger clear-page copy-page in page faults which is a
 27 potentially negative effect. The first factor      27 potentially negative effect. The first factor consists in taking a
 28 single page fault for each 2M virtual region t     28 single page fault for each 2M virtual region touched by userland (so
 29 reducing the enter/exit kernel frequency by a      29 reducing the enter/exit kernel frequency by a 512 times factor). This
 30 only matters the first time the memory is acce     30 only matters the first time the memory is accessed for the lifetime of
 31 a memory mapping. The second long lasting and      31 a memory mapping. The second long lasting and much more important
 32 factor will affect all subsequent accesses to      32 factor will affect all subsequent accesses to the memory for the whole
 33 runtime of the application. The second factor      33 runtime of the application. The second factor consist of two
 34 components:                                        34 components:
 35                                                    35 
 36 1) the TLB miss will run faster (especially wi     36 1) the TLB miss will run faster (especially with virtualization using
 37    nested pagetables but almost always also on     37    nested pagetables but almost always also on bare metal without
 38    virtualization)                                 38    virtualization)
 39                                                    39 
 40 2) a single TLB entry will be mapping a much l     40 2) a single TLB entry will be mapping a much larger amount of virtual
 41    memory in turn reducing the number of TLB m     41    memory in turn reducing the number of TLB misses. With
 42    virtualization and nested pagetables the TL     42    virtualization and nested pagetables the TLB can be mapped of
 43    larger size only if both KVM and the Linux      43    larger size only if both KVM and the Linux guest are using
 44    hugepages but a significant speedup already     44    hugepages but a significant speedup already happens if only one of
 45    the two is using hugepages just because of      45    the two is using hugepages just because of the fact the TLB miss is
 46    going to run faster.                            46    going to run faster.
 47                                                    47 
 48 Modern kernels support "multi-size THP" (mTHP) << 
 49 ability to allocate memory in blocks that are  << 
 50 but smaller than traditional PMD-size (as desc << 
 51 increments of a power-of-2 number of pages. mT << 
 52 memory (for example 16K, 32K, 64K, etc). These << 
 53 PTE-mapped, but in many cases can still provid << 
 54 those outlined above: Page faults are signific << 
 55 factor of e.g. 4, 8, 16, etc), but latency spi << 
 56 prominent because the size of each page isn't  << 
 57 variant and there is less memory to clear in e << 
 58 architectures also employ TLB compression mech << 
 59 entries in when a set of PTEs are virtually an << 
 60 and approporiately aligned. In this case, TLB  << 
 61 often.                                         << 
 62                                                << 
 63 THP can be enabled system wide or restricted t     48 THP can be enabled system wide or restricted to certain tasks or even
 64 memory ranges inside task's address space. Unl     49 memory ranges inside task's address space. Unless THP is completely
 65 disabled, there is ``khugepaged`` daemon that      50 disabled, there is ``khugepaged`` daemon that scans memory and
 66 collapses sequences of basic pages into PMD-si !!  51 collapses sequences of basic pages into huge pages.
 67                                                    52 
 68 The THP behaviour is controlled via :ref:`sysf     53 The THP behaviour is controlled via :ref:`sysfs <thp_sysfs>`
 69 interface and using madvise(2) and prctl(2) sy     54 interface and using madvise(2) and prctl(2) system calls.
 70                                                    55 
 71 Transparent Hugepage Support maximizes the use     56 Transparent Hugepage Support maximizes the usefulness of free memory
 72 if compared to the reservation approach of hug     57 if compared to the reservation approach of hugetlbfs by allowing all
 73 unused memory to be used as cache or other mov     58 unused memory to be used as cache or other movable (or even unmovable
 74 entities). It doesn't require reservation to p     59 entities). It doesn't require reservation to prevent hugepage
 75 allocation failures to be noticeable from user     60 allocation failures to be noticeable from userland. It allows paging
 76 and all other advanced VM features to be avail     61 and all other advanced VM features to be available on the
 77 hugepages. It requires no modifications for ap     62 hugepages. It requires no modifications for applications to take
 78 advantage of it.                                   63 advantage of it.
 79                                                    64 
 80 Applications however can be further optimized      65 Applications however can be further optimized to take advantage of
 81 this feature, like for example they've been op     66 this feature, like for example they've been optimized before to avoid
 82 a flood of mmap system calls for every malloc(     67 a flood of mmap system calls for every malloc(4k). Optimizing userland
 83 is by far not mandatory and khugepaged already     68 is by far not mandatory and khugepaged already can take care of long
 84 lived page allocations even for hugepage unawa     69 lived page allocations even for hugepage unaware applications that
 85 deals with large amounts of memory.                70 deals with large amounts of memory.
 86                                                    71 
 87 In certain cases when hugepages are enabled sy     72 In certain cases when hugepages are enabled system wide, application
 88 may end up allocating more memory resources. A     73 may end up allocating more memory resources. An application may mmap a
 89 large region but only touch 1 byte of it, in t     74 large region but only touch 1 byte of it, in that case a 2M page might
 90 be allocated instead of a 4k page for no good.     75 be allocated instead of a 4k page for no good. This is why it's
 91 possible to disable hugepages system-wide and      76 possible to disable hugepages system-wide and to only have them inside
 92 MADV_HUGEPAGE madvise regions.                     77 MADV_HUGEPAGE madvise regions.
 93                                                    78 
 94 Embedded systems should enable hugepages only      79 Embedded systems should enable hugepages only inside madvise regions
 95 to eliminate any risk of wasting any precious      80 to eliminate any risk of wasting any precious byte of memory and to
 96 only run faster.                                   81 only run faster.
 97                                                    82 
 98 Applications that gets a lot of benefit from h     83 Applications that gets a lot of benefit from hugepages and that don't
 99 risk to lose memory by using hugepages, should     84 risk to lose memory by using hugepages, should use
100 madvise(MADV_HUGEPAGE) on their critical mmapp     85 madvise(MADV_HUGEPAGE) on their critical mmapped regions.
101                                                    86 
102 .. _thp_sysfs:                                     87 .. _thp_sysfs:
103                                                    88 
104 sysfs                                              89 sysfs
105 =====                                              90 =====
106                                                    91 
107 Global THP controls                                92 Global THP controls
108 -------------------                                93 -------------------
109                                                    94 
110 Transparent Hugepage Support for anonymous mem     95 Transparent Hugepage Support for anonymous memory can be entirely disabled
111 (mostly for debugging purposes) or only enable     96 (mostly for debugging purposes) or only enabled inside MADV_HUGEPAGE
112 regions (to avoid the risk of consuming more m     97 regions (to avoid the risk of consuming more memory resources) or enabled
113 system wide. This can be achieved per-supporte !!  98 system wide. This can be achieved with one of::
114                                                << 
115         echo always >/sys/kernel/mm/transparen << 
116         echo madvise >/sys/kernel/mm/transpare << 
117         echo never >/sys/kernel/mm/transparent << 
118                                                << 
119 where <size> is the hugepage size being addres << 
120 for which vary by system.                      << 
121                                                << 
122 For example::                                  << 
123                                                << 
124         echo always >/sys/kernel/mm/transparen << 
125                                                << 
126 Alternatively it is possible to specify that a << 
127 will inherit the top-level "enabled" value::   << 
128                                                << 
129         echo inherit >/sys/kernel/mm/transpare << 
130                                                << 
131 For example::                                  << 
132                                                << 
133         echo inherit >/sys/kernel/mm/transpare << 
134                                                << 
135 The top-level setting (for use with "inherit") << 
136 one of the following commands::                << 
137                                                    99 
138         echo always >/sys/kernel/mm/transparen    100         echo always >/sys/kernel/mm/transparent_hugepage/enabled
139         echo madvise >/sys/kernel/mm/transpare    101         echo madvise >/sys/kernel/mm/transparent_hugepage/enabled
140         echo never >/sys/kernel/mm/transparent    102         echo never >/sys/kernel/mm/transparent_hugepage/enabled
141                                                   103 
142 By default, PMD-sized hugepages have enabled=" << 
143 hugepage sizes have enabled="never". If enabli << 
144 sizes, the kernel will select the most appropr << 
145 given allocation.                              << 
146                                                << 
147 It's also possible to limit defrag efforts in     104 It's also possible to limit defrag efforts in the VM to generate
148 anonymous hugepages in case they're not immedi    105 anonymous hugepages in case they're not immediately free to madvise
149 regions or to never try to defrag memory and s    106 regions or to never try to defrag memory and simply fallback to regular
150 pages unless hugepages are immediately availab    107 pages unless hugepages are immediately available. Clearly if we spend CPU
151 time to defrag memory, we would expect to gain    108 time to defrag memory, we would expect to gain even more by the fact we
152 use hugepages later instead of regular pages.     109 use hugepages later instead of regular pages. This isn't always
153 guaranteed, but it may be more likely in case     110 guaranteed, but it may be more likely in case the allocation is for a
154 MADV_HUGEPAGE region.                             111 MADV_HUGEPAGE region.
155                                                   112 
156 ::                                                113 ::
157                                                   114 
158         echo always >/sys/kernel/mm/transparen    115         echo always >/sys/kernel/mm/transparent_hugepage/defrag
159         echo defer >/sys/kernel/mm/transparent    116         echo defer >/sys/kernel/mm/transparent_hugepage/defrag
160         echo defer+madvise >/sys/kernel/mm/tra    117         echo defer+madvise >/sys/kernel/mm/transparent_hugepage/defrag
161         echo madvise >/sys/kernel/mm/transpare    118         echo madvise >/sys/kernel/mm/transparent_hugepage/defrag
162         echo never >/sys/kernel/mm/transparent    119         echo never >/sys/kernel/mm/transparent_hugepage/defrag
163                                                   120 
164 always                                            121 always
165         means that an application requesting T    122         means that an application requesting THP will stall on
166         allocation failure and directly reclai    123         allocation failure and directly reclaim pages and compact
167         memory in an effort to allocate a THP     124         memory in an effort to allocate a THP immediately. This may be
168         desirable for virtual machines that be    125         desirable for virtual machines that benefit heavily from THP
169         use and are willing to delay the VM st    126         use and are willing to delay the VM start to utilise them.
170                                                   127 
171 defer                                             128 defer
172         means that an application will wake ks    129         means that an application will wake kswapd in the background
173         to reclaim pages and wake kcompactd to    130         to reclaim pages and wake kcompactd to compact memory so that
174         THP is available in the near future. I    131         THP is available in the near future. It's the responsibility
175         of khugepaged to then install the THP     132         of khugepaged to then install the THP pages later.
176                                                   133 
177 defer+madvise                                     134 defer+madvise
178         will enter direct reclaim and compacti    135         will enter direct reclaim and compaction like ``always``, but
179         only for regions that have used madvis    136         only for regions that have used madvise(MADV_HUGEPAGE); all
180         other regions will wake kswapd in the     137         other regions will wake kswapd in the background to reclaim
181         pages and wake kcompactd to compact me    138         pages and wake kcompactd to compact memory so that THP is
182         available in the near future.             139         available in the near future.
183                                                   140 
184 madvise                                           141 madvise
185         will enter direct reclaim like ``alway    142         will enter direct reclaim like ``always`` but only for regions
186         that are have used madvise(MADV_HUGEPA    143         that are have used madvise(MADV_HUGEPAGE). This is the default
187         behaviour.                                144         behaviour.
188                                                   145 
189 never                                             146 never
190         should be self-explanatory.               147         should be self-explanatory.
191                                                   148 
192 By default kernel tries to use huge, PMD-mappa !! 149 By default kernel tries to use huge zero page on read page fault to
193 page fault to anonymous mapping. It's possible !! 150 anonymous mapping. It's possible to disable huge zero page by writing 0
194 page by writing 0 or enable it back by writing !! 151 or enable it back by writing 1::
195                                                   152 
196         echo 0 >/sys/kernel/mm/transparent_hug    153         echo 0 >/sys/kernel/mm/transparent_hugepage/use_zero_page
197         echo 1 >/sys/kernel/mm/transparent_hug    154         echo 1 >/sys/kernel/mm/transparent_hugepage/use_zero_page
198                                                   155 
199 Some userspace (such as a test program, or an  !! 156 Some userspace (such as a test program, or an optimized memory allocation
200 allocation library) may want to know the size  !! 157 library) may want to know the size (in bytes) of a transparent hugepage::
201 PMD-mappable transparent hugepage::            << 
202                                                   158 
203         cat /sys/kernel/mm/transparent_hugepag    159         cat /sys/kernel/mm/transparent_hugepage/hpage_pmd_size
204                                                   160 
205 All THPs at fault and collapse time will be ad !! 161 khugepaged will be automatically started when
206 and will therefore be split under memory presu !! 162 transparent_hugepage/enabled is set to "always" or "madvise, and it'll
207 "underused". A THP is underused if the number  !! 163 be automatically shutdown if it's set to "never".
208 the THP is above max_ptes_none (see below). It << 
209 this behaviour by writing 0 to shrink_underuse << 
210 1 to it::                                      << 
211                                                << 
212         echo 0 > /sys/kernel/mm/transparent_hu << 
213         echo 1 > /sys/kernel/mm/transparent_hu << 
214                                                << 
215 khugepaged will be automatically started when  << 
216 (either of the per-size anon control or the to << 
217 to "always" or "madvise"), and it'll be automa << 
218 PMD-sized THP is disabled (when both the per-s << 
219 top-level control are "never")                 << 
220                                                   164 
221 Khugepaged controls                               165 Khugepaged controls
222 -------------------                               166 -------------------
223                                                   167 
224 .. note::                                      << 
225    khugepaged currently only searches for oppo << 
226    PMD-sized THP and no attempt is made to col << 
227    sizes.                                      << 
228                                                << 
229 khugepaged runs usually at low frequency so wh    168 khugepaged runs usually at low frequency so while one may not want to
230 invoke defrag algorithms synchronously during     169 invoke defrag algorithms synchronously during the page faults, it
231 should be worth invoking defrag at least in kh    170 should be worth invoking defrag at least in khugepaged. However it's
232 also possible to disable defrag in khugepaged     171 also possible to disable defrag in khugepaged by writing 0 or enable
233 defrag in khugepaged by writing 1::               172 defrag in khugepaged by writing 1::
234                                                   173 
235         echo 0 >/sys/kernel/mm/transparent_hug    174         echo 0 >/sys/kernel/mm/transparent_hugepage/khugepaged/defrag
236         echo 1 >/sys/kernel/mm/transparent_hug    175         echo 1 >/sys/kernel/mm/transparent_hugepage/khugepaged/defrag
237                                                   176 
238 You can also control how many pages khugepaged    177 You can also control how many pages khugepaged should scan at each
239 pass::                                            178 pass::
240                                                   179 
241         /sys/kernel/mm/transparent_hugepage/kh    180         /sys/kernel/mm/transparent_hugepage/khugepaged/pages_to_scan
242                                                   181 
243 and how many milliseconds to wait in khugepage    182 and how many milliseconds to wait in khugepaged between each pass (you
244 can set this to 0 to run khugepaged at 100% ut    183 can set this to 0 to run khugepaged at 100% utilization of one core)::
245                                                   184 
246         /sys/kernel/mm/transparent_hugepage/kh    185         /sys/kernel/mm/transparent_hugepage/khugepaged/scan_sleep_millisecs
247                                                   186 
248 and how many milliseconds to wait in khugepage    187 and how many milliseconds to wait in khugepaged if there's an hugepage
249 allocation failure to throttle the next alloca    188 allocation failure to throttle the next allocation attempt::
250                                                   189 
251         /sys/kernel/mm/transparent_hugepage/kh    190         /sys/kernel/mm/transparent_hugepage/khugepaged/alloc_sleep_millisecs
252                                                   191 
253 The khugepaged progress can be seen in the num    192 The khugepaged progress can be seen in the number of pages collapsed (note
254 that this counter may not be an exact count of    193 that this counter may not be an exact count of the number of pages
255 collapsed, since "collapsed" could mean multip    194 collapsed, since "collapsed" could mean multiple things: (1) A PTE mapping
256 being replaced by a PMD mapping, or (2) All 4K    195 being replaced by a PMD mapping, or (2) All 4K physical pages replaced by
257 one 2M hugepage. Each may happen independently    196 one 2M hugepage. Each may happen independently, or together, depending on
258 the type of memory and the failures that occur    197 the type of memory and the failures that occur. As such, this value should
259 be interpreted roughly as a sign of progress,     198 be interpreted roughly as a sign of progress, and counters in /proc/vmstat
260 consulted for more accurate accounting)::         199 consulted for more accurate accounting)::
261                                                   200 
262         /sys/kernel/mm/transparent_hugepage/kh    201         /sys/kernel/mm/transparent_hugepage/khugepaged/pages_collapsed
263                                                   202 
264 for each pass::                                   203 for each pass::
265                                                   204 
266         /sys/kernel/mm/transparent_hugepage/kh    205         /sys/kernel/mm/transparent_hugepage/khugepaged/full_scans
267                                                   206 
268 ``max_ptes_none`` specifies how many extra sma    207 ``max_ptes_none`` specifies how many extra small pages (that are
269 not already mapped) can be allocated when coll    208 not already mapped) can be allocated when collapsing a group
270 of small pages into one large page::              209 of small pages into one large page::
271                                                   210 
272         /sys/kernel/mm/transparent_hugepage/kh    211         /sys/kernel/mm/transparent_hugepage/khugepaged/max_ptes_none
273                                                   212 
274 A higher value leads to use additional memory     213 A higher value leads to use additional memory for programs.
275 A lower value leads to gain less thp performan    214 A lower value leads to gain less thp performance. Value of
276 max_ptes_none can waste cpu time very little,     215 max_ptes_none can waste cpu time very little, you can
277 ignore it.                                        216 ignore it.
278                                                   217 
279 ``max_ptes_swap`` specifies how many pages can    218 ``max_ptes_swap`` specifies how many pages can be brought in from
280 swap when collapsing a group of pages into a t    219 swap when collapsing a group of pages into a transparent huge page::
281                                                   220 
282         /sys/kernel/mm/transparent_hugepage/kh    221         /sys/kernel/mm/transparent_hugepage/khugepaged/max_ptes_swap
283                                                   222 
284 A higher value can cause excessive swap IO and    223 A higher value can cause excessive swap IO and waste
285 memory. A lower value can prevent THPs from be    224 memory. A lower value can prevent THPs from being
286 collapsed, resulting fewer pages being collaps    225 collapsed, resulting fewer pages being collapsed into
287 THPs, and lower memory access performance.        226 THPs, and lower memory access performance.
288                                                   227 
289 ``max_ptes_shared`` specifies how many pages c    228 ``max_ptes_shared`` specifies how many pages can be shared across multiple
290 processes. khugepaged might treat pages of THP !! 229 processes. Exceeding the number would block the collapse::
291 that THP is shared. Exceeding the number would << 
292                                                   230 
293         /sys/kernel/mm/transparent_hugepage/kh    231         /sys/kernel/mm/transparent_hugepage/khugepaged/max_ptes_shared
294                                                   232 
295 A higher value may increase memory footprint f    233 A higher value may increase memory footprint for some workloads.
296                                                   234 
297 Boot parameters                                !! 235 Boot parameter
298 ===============                                !! 236 ==============
299                                                   237 
300 You can change the sysfs boot time default for !! 238 You can change the sysfs boot time defaults of Transparent Hugepage
301 control by passing the parameter ``transparent !! 239 Support by passing the parameter ``transparent_hugepage=always`` or
302 ``transparent_hugepage=madvise`` or ``transpar !! 240 ``transparent_hugepage=madvise`` or ``transparent_hugepage=never``
303 kernel command line.                           !! 241 to the kernel command line.
304                                                << 
305 Alternatively, each supported anonymous THP si << 
306 passing ``thp_anon=<size>[KMG],<size>[KMG]:<st << 
307 where ``<size>`` is the THP size (must be a po << 
308 supported anonymous THP)  and ``<state>`` is o << 
309 ``never`` or ``inherit``.                      << 
310                                                << 
311 For example, the following will set 16K, 32K,  << 
312 set 128K, 512K to ``inherit``, set 256K to ``m << 
313 to ``never``::                                 << 
314                                                << 
315         thp_anon=16K-64K:always;128K,512K:inhe << 
316                                                << 
317 ``thp_anon=`` may be specified multiple times  << 
318 required. If ``thp_anon=`` is specified at lea << 
319 not explicitly configured on the command line  << 
320 ``never``.                                     << 
321                                                << 
322 ``transparent_hugepage`` setting only affects  << 
323 ``thp_anon`` is not specified, PMD_ORDER THP w << 
324 However, if a valid ``thp_anon`` setting is pr << 
325 PMD_ORDER THP policy will be overridden. If th << 
326 is not defined within a valid ``thp_anon``, it << 
327 ``never``.                                     << 
328                                                   242 
329 Hugepages in tmpfs/shmem                          243 Hugepages in tmpfs/shmem
330 ========================                          244 ========================
331                                                   245 
332 You can control hugepage allocation policy in     246 You can control hugepage allocation policy in tmpfs with mount option
333 ``huge=``. It can have following values:          247 ``huge=``. It can have following values:
334                                                   248 
335 always                                            249 always
336     Attempt to allocate huge pages every time     250     Attempt to allocate huge pages every time we need a new page;
337                                                   251 
338 never                                             252 never
339     Do not allocate huge pages;                   253     Do not allocate huge pages;
340                                                   254 
341 within_size                                       255 within_size
342     Only allocate huge page if it will be full    256     Only allocate huge page if it will be fully within i_size.
343     Also respect fadvise()/madvise() hints;       257     Also respect fadvise()/madvise() hints;
344                                                   258 
345 advise                                            259 advise
346     Only allocate huge pages if requested with    260     Only allocate huge pages if requested with fadvise()/madvise();
347                                                   261 
348 The default policy is ``never``.                  262 The default policy is ``never``.
349                                                   263 
350 ``mount -o remount,huge= /mountpoint`` works f    264 ``mount -o remount,huge= /mountpoint`` works fine after mount: remounting
351 ``huge=never`` will not attempt to break up hu    265 ``huge=never`` will not attempt to break up huge pages at all, just stop more
352 from being allocated.                             266 from being allocated.
353                                                   267 
354 There's also sysfs knob to control hugepage al    268 There's also sysfs knob to control hugepage allocation policy for internal
355 shmem mount: /sys/kernel/mm/transparent_hugepa    269 shmem mount: /sys/kernel/mm/transparent_hugepage/shmem_enabled. The mount
356 is used for SysV SHM, memfds, shared anonymous    270 is used for SysV SHM, memfds, shared anonymous mmaps (of /dev/zero or
357 MAP_ANONYMOUS), GPU drivers' DRM objects, Ashm    271 MAP_ANONYMOUS), GPU drivers' DRM objects, Ashmem.
358                                                   272 
359 In addition to policies listed above, shmem_en    273 In addition to policies listed above, shmem_enabled allows two further
360 values:                                           274 values:
361                                                   275 
362 deny                                              276 deny
363     For use in emergencies, to force the huge     277     For use in emergencies, to force the huge option off from
364     all mounts;                                   278     all mounts;
365 force                                             279 force
366     Force the huge option on for all - very us    280     Force the huge option on for all - very useful for testing;
367                                                   281 
368 Shmem can also use "multi-size THP" (mTHP) by  << 
369 control mTHP allocation:                       << 
370 '/sys/kernel/mm/transparent_hugepage/hugepages << 
371 and its value for each mTHP is essentially con << 
372 setting.  An 'inherit' option is added to ensu << 
373 global settings.  Conversely, the options 'for << 
374 which are rather testing artifacts from the ol << 
375                                                << 
376 always                                         << 
377     Attempt to allocate <size> huge pages ever << 
378                                                << 
379 inherit                                        << 
380     Inherit the top-level "shmem_enabled" valu << 
381     have enabled="inherit" and all other hugep << 
382                                                << 
383 never                                          << 
384     Do not allocate <size> huge pages;         << 
385                                                << 
386 within_size                                    << 
387     Only allocate <size> huge page if it will  << 
388     Also respect fadvise()/madvise() hints;    << 
389                                                << 
390 advise                                         << 
391     Only allocate <size> huge pages if request << 
392                                                << 
393 Need of application restart                       282 Need of application restart
394 ===========================                       283 ===========================
395                                                   284 
396 The transparent_hugepage/enabled and           !! 285 The transparent_hugepage/enabled values and tmpfs mount option only affect
397 transparent_hugepage/hugepages-<size>kB/enable !! 286 future behavior. So to make them effective you need to restart any
398 option only affect future behavior. So to make !! 287 application that could have been using hugepages. This also applies to the
399 to restart any application that could have bee !! 288 regions registered in khugepaged.
400 also applies to the regions registered in khug << 
401                                                   289 
402 Monitoring usage                                  290 Monitoring usage
403 ================                                  291 ================
404                                                   292 
405 The number of PMD-sized anonymous transparent  !! 293 The number of anonymous transparent huge pages currently used by the
406 system is available by reading the AnonHugePag    294 system is available by reading the AnonHugePages field in ``/proc/meminfo``.
407 To identify what applications are using PMD-si !! 295 To identify what applications are using anonymous transparent huge pages,
408 pages, it is necessary to read ``/proc/PID/sma !! 296 it is necessary to read ``/proc/PID/smaps`` and count the AnonHugePages fields
409 fields for each mapping. (Note that AnonHugePa !! 297 for each mapping.
410 PMD-sized THP for historical reasons and shoul << 
411 AnonHugePmdMapped).                            << 
412                                                   298 
413 The number of file transparent huge pages mapp    299 The number of file transparent huge pages mapped to userspace is available
414 by reading ShmemPmdMapped and ShmemHugePages f    300 by reading ShmemPmdMapped and ShmemHugePages fields in ``/proc/meminfo``.
415 To identify what applications are mapping file    301 To identify what applications are mapping file transparent huge pages, it
416 is necessary to read ``/proc/PID/smaps`` and c    302 is necessary to read ``/proc/PID/smaps`` and count the FileHugeMapped fields
417 for each mapping.                                 303 for each mapping.
418                                                   304 
419 Note that reading the smaps file is expensive     305 Note that reading the smaps file is expensive and reading it
420 frequently will incur overhead.                   306 frequently will incur overhead.
421                                                   307 
422 There are a number of counters in ``/proc/vmst    308 There are a number of counters in ``/proc/vmstat`` that may be used to
423 monitor how successfully the system is providi    309 monitor how successfully the system is providing huge pages for use.
424                                                   310 
425 thp_fault_alloc                                   311 thp_fault_alloc
426         is incremented every time a huge page     312         is incremented every time a huge page is successfully
427         allocated and charged to handle a page !! 313         allocated to handle a page fault.
428                                                   314 
429 thp_collapse_alloc                                315 thp_collapse_alloc
430         is incremented by khugepaged when it h    316         is incremented by khugepaged when it has found
431         a range of pages to collapse into one     317         a range of pages to collapse into one huge page and has
432         successfully allocated a new huge page    318         successfully allocated a new huge page to store the data.
433                                                   319 
434 thp_fault_fallback                                320 thp_fault_fallback
435         is incremented if a page fault fails t !! 321         is incremented if a page fault fails to allocate
436         a huge page and instead falls back to     322         a huge page and instead falls back to using small pages.
437                                                   323 
438 thp_fault_fallback_charge                         324 thp_fault_fallback_charge
439         is incremented if a page fault fails t    325         is incremented if a page fault fails to charge a huge page and
440         instead falls back to using small page    326         instead falls back to using small pages even though the
441         allocation was successful.                327         allocation was successful.
442                                                   328 
443 thp_collapse_alloc_failed                         329 thp_collapse_alloc_failed
444         is incremented if khugepaged found a r    330         is incremented if khugepaged found a range
445         of pages that should be collapsed into    331         of pages that should be collapsed into one huge page but failed
446         the allocation.                           332         the allocation.
447                                                   333 
448 thp_file_alloc                                    334 thp_file_alloc
449         is incremented every time a shmem huge !! 335         is incremented every time a file huge page is successfully
450         allocated (Note that despite being nam !! 336         allocated.
451         measures only shmem).                  << 
452                                                   337 
453 thp_file_fallback                                 338 thp_file_fallback
454         is incremented if a shmem huge page is !! 339         is incremented if a file huge page is attempted to be allocated
455         but fails and instead falls back to us !! 340         but fails and instead falls back to using small pages.
456         despite being named after "file", the  << 
457                                                   341 
458 thp_file_fallback_charge                          342 thp_file_fallback_charge
459         is incremented if a shmem huge page ca !! 343         is incremented if a file huge page cannot be charged and instead
460         falls back to using small pages even t    344         falls back to using small pages even though the allocation was
461         successful. (Note that despite being n !! 345         successful.
462         counter measures only shmem).          << 
463                                                   346 
464 thp_file_mapped                                   347 thp_file_mapped
465         is incremented every time a file or sh !! 348         is incremented every time a file huge page is mapped into
466         user address space.                       349         user address space.
467                                                   350 
468 thp_split_page                                    351 thp_split_page
469         is incremented every time a huge page     352         is incremented every time a huge page is split into base
470         pages. This can happen for a variety o    353         pages. This can happen for a variety of reasons but a common
471         reason is that a huge page is old and     354         reason is that a huge page is old and is being reclaimed.
472         This action implies splitting all PMD     355         This action implies splitting all PMD the page mapped with.
473                                                   356 
474 thp_split_page_failed                             357 thp_split_page_failed
475         is incremented if kernel fails to spli    358         is incremented if kernel fails to split huge
476         page. This can happen if the page was     359         page. This can happen if the page was pinned by somebody.
477                                                   360 
478 thp_deferred_split_page                           361 thp_deferred_split_page
479         is incremented when a huge page is put    362         is incremented when a huge page is put onto split
480         queue. This happens when a huge page i    363         queue. This happens when a huge page is partially unmapped and
481         splitting it would free up some memory    364         splitting it would free up some memory. Pages on split queue are
482         going to be split under memory pressur    365         going to be split under memory pressure.
483                                                   366 
484 thp_underused_split_page                       << 
485         is incremented when a huge page on the << 
486         because it was underused. A THP is und << 
487         zero pages in the THP is above a certa << 
488         (/sys/kernel/mm/transparent_hugepage/k << 
489                                                << 
490 thp_split_pmd                                     367 thp_split_pmd
491         is incremented every time a PMD split     368         is incremented every time a PMD split into table of PTEs.
492         This can happen, for instance, when ap    369         This can happen, for instance, when application calls mprotect() or
493         munmap() on part of huge page. It does    370         munmap() on part of huge page. It doesn't split huge page, only
494         page table entry.                         371         page table entry.
495                                                   372 
496 thp_zero_page_alloc                               373 thp_zero_page_alloc
497         is incremented every time a huge zero     374         is incremented every time a huge zero page used for thp is
498         successfully allocated. Note, it doesn    375         successfully allocated. Note, it doesn't count every map of
499         the huge zero page, only its allocatio    376         the huge zero page, only its allocation.
500                                                   377 
501 thp_zero_page_alloc_failed                        378 thp_zero_page_alloc_failed
502         is incremented if kernel fails to allo    379         is incremented if kernel fails to allocate
503         huge zero page and falls back to using    380         huge zero page and falls back to using small pages.
504                                                   381 
505 thp_swpout                                        382 thp_swpout
506         is incremented every time a huge page     383         is incremented every time a huge page is swapout in one
507         piece without splitting.                  384         piece without splitting.
508                                                   385 
509 thp_swpout_fallback                               386 thp_swpout_fallback
510         is incremented if a huge page has to b    387         is incremented if a huge page has to be split before swapout.
511         Usually because failed to allocate som    388         Usually because failed to allocate some continuous swap space
512         for the huge page.                        389         for the huge page.
513                                                   390 
514 In /sys/kernel/mm/transparent_hugepage/hugepag << 
515 also individual counters for each huge page si << 
516 monitor the system's effectiveness in providin << 
517 counter has its own corresponding file.        << 
518                                                << 
519 anon_fault_alloc                               << 
520         is incremented every time a huge page  << 
521         allocated and charged to handle a page << 
522                                                << 
523 anon_fault_fallback                            << 
524         is incremented if a page fault fails t << 
525         a huge page and instead falls back to  << 
526         lower orders or small pages.           << 
527                                                << 
528 anon_fault_fallback_charge                     << 
529         is incremented if a page fault fails t << 
530         instead falls back to using huge pages << 
531         small pages even though the allocation << 
532                                                << 
533 swpout                                         << 
534         is incremented every time a huge page  << 
535         piece without splitting.               << 
536                                                << 
537 swpout_fallback                                << 
538         is incremented if a huge page has to b << 
539         Usually because failed to allocate som << 
540         for the huge page.                     << 
541                                                << 
542 shmem_alloc                                    << 
543         is incremented every time a shmem huge << 
544         allocated.                             << 
545                                                << 
546 shmem_fallback                                 << 
547         is incremented if a shmem huge page is << 
548         but fails and instead falls back to us << 
549                                                << 
550 shmem_fallback_charge                          << 
551         is incremented if a shmem huge page ca << 
552         falls back to using small pages even t << 
553         successful.                            << 
554                                                << 
555 split                                          << 
556         is incremented every time a huge page  << 
557         smaller orders. This can happen for a  << 
558         common reason is that a huge page is o << 
559                                                << 
560 split_failed                                   << 
561         is incremented if kernel fails to spli << 
562         page. This can happen if the page was  << 
563                                                << 
564 split_deferred                                 << 
565         is incremented when a huge page is put << 
566         This happens when a huge page is parti << 
567         it would free up some memory. Pages on << 
568         be split under memory pressure, if spl << 
569                                                << 
570 nr_anon                                        << 
571        the number of anonymous THP we have in  << 
572        might be currently entirely mapped or h << 
573        subpages.                               << 
574                                                << 
575 nr_anon_partially_mapped                       << 
576        the number of anonymous THP which are l << 
577        wasting memory, and have been queued fo << 
578        Note that in corner some cases (e.g., f << 
579        an anonymous THP as "partially mapped"  << 
580        is not actually partially mapped anymor << 
581                                                << 
582 As the system ages, allocating huge pages may     391 As the system ages, allocating huge pages may be expensive as the
583 system uses memory compaction to copy data aro    392 system uses memory compaction to copy data around memory to free a
584 huge page for use. There are some counters in     393 huge page for use. There are some counters in ``/proc/vmstat`` to help
585 monitor this overhead.                            394 monitor this overhead.
586                                                   395 
587 compact_stall                                     396 compact_stall
588         is incremented every time a process st    397         is incremented every time a process stalls to run
589         memory compaction so that a huge page     398         memory compaction so that a huge page is free for use.
590                                                   399 
591 compact_success                                   400 compact_success
592         is incremented if the system compacted    401         is incremented if the system compacted memory and
593         freed a huge page for use.                402         freed a huge page for use.
594                                                   403 
595 compact_fail                                      404 compact_fail
596         is incremented if the system tries to     405         is incremented if the system tries to compact memory
597         but failed.                               406         but failed.
598                                                   407 
599 It is possible to establish how long the stall    408 It is possible to establish how long the stalls were using the function
600 tracer to record how long was spent in __alloc    409 tracer to record how long was spent in __alloc_pages() and
601 using the mm_page_alloc tracepoint to identify    410 using the mm_page_alloc tracepoint to identify which allocations were
602 for huge pages.                                   411 for huge pages.
603                                                   412 
604 Optimizing the applications                       413 Optimizing the applications
605 ===========================                       414 ===========================
606                                                   415 
607 To be guaranteed that the kernel will map a TH !! 416 To be guaranteed that the kernel will map a 2M page immediately in any
608 memory region, the mmap region has to be hugep    417 memory region, the mmap region has to be hugepage naturally
609 aligned. posix_memalign() can provide that gua    418 aligned. posix_memalign() can provide that guarantee.
610                                                   419 
611 Hugetlbfs                                         420 Hugetlbfs
612 =========                                         421 =========
613                                                   422 
614 You can use hugetlbfs on a kernel that has tra    423 You can use hugetlbfs on a kernel that has transparent hugepage
615 support enabled just fine as always. No differ    424 support enabled just fine as always. No difference can be noted in
616 hugetlbfs other than there will be less overal    425 hugetlbfs other than there will be less overall fragmentation. All
617 usual features belonging to hugetlbfs are pres    426 usual features belonging to hugetlbfs are preserved and
618 unaffected. libhugetlbfs will also work fine a    427 unaffected. libhugetlbfs will also work fine as usual.
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php