kbuild: Move -Wenum-enum-conversion to W=2
[linux.git] / Documentation / admin-guide / mm / transhuge.rst
blobdff8d5985f0f2e60f4aa1b7a936396dd6002db77
1 ============================
2 Transparent Hugepage Support
3 ============================
5 Objective
6 =========
8 Performance critical computing applications dealing with large memory
9 working sets are already running on top of libhugetlbfs and in turn
10 hugetlbfs. Transparent HugePage Support (THP) is an alternative mean of
11 using huge pages for the backing of virtual memory with huge pages
12 that supports the automatic promotion and demotion of page sizes and
13 without the shortcomings of hugetlbfs.
15 Currently THP only works for anonymous memory mappings and tmpfs/shmem.
16 But in the future it can expand to other filesystems.
18 .. note::
19    in the examples below we presume that the basic page size is 4K and
20    the huge page size is 2M, although the actual numbers may vary
21    depending on the CPU architecture.
23 The reason applications are running faster is because of two
24 factors. The first factor is almost completely irrelevant and it's not
25 of significant interest because it'll also have the downside of
26 requiring larger clear-page copy-page in page faults which is a
27 potentially negative effect. The first factor consists in taking a
28 single page fault for each 2M virtual region touched by userland (so
29 reducing the enter/exit kernel frequency by a 512 times factor). This
30 only matters the first time the memory is accessed for the lifetime of
31 a memory mapping. The second long lasting and much more important
32 factor will affect all subsequent accesses to the memory for the whole
33 runtime of the application. The second factor consist of two
34 components:
36 1) the TLB miss will run faster (especially with virtualization using
37    nested pagetables but almost always also on bare metal without
38    virtualization)
40 2) a single TLB entry will be mapping a much larger amount of virtual
41    memory in turn reducing the number of TLB misses. With
42    virtualization and nested pagetables the TLB can be mapped of
43    larger size only if both KVM and the Linux guest are using
44    hugepages but a significant speedup already happens if only one of
45    the two is using hugepages just because of the fact the TLB miss is
46    going to run faster.
48 Modern kernels support "multi-size THP" (mTHP), which introduces the
49 ability to allocate memory in blocks that are bigger than a base page
50 but smaller than traditional PMD-size (as described above), in
51 increments of a power-of-2 number of pages. mTHP can back anonymous
52 memory (for example 16K, 32K, 64K, etc). These THPs continue to be
53 PTE-mapped, but in many cases can still provide similar benefits to
54 those outlined above: Page faults are significantly reduced (by a
55 factor of e.g. 4, 8, 16, etc), but latency spikes are much less
56 prominent because the size of each page isn't as huge as the PMD-sized
57 variant and there is less memory to clear in each page fault. Some
58 architectures also employ TLB compression mechanisms to squeeze more
59 entries in when a set of PTEs are virtually and physically contiguous
60 and approporiately aligned. In this case, TLB misses will occur less
61 often.
63 THP can be enabled system wide or restricted to certain tasks or even
64 memory ranges inside task's address space. Unless THP is completely
65 disabled, there is ``khugepaged`` daemon that scans memory and
66 collapses sequences of basic pages into PMD-sized huge pages.
68 The THP behaviour is controlled via :ref:`sysfs <thp_sysfs>`
69 interface and using madvise(2) and prctl(2) system calls.
71 Transparent Hugepage Support maximizes the usefulness of free memory
72 if compared to the reservation approach of hugetlbfs by allowing all
73 unused memory to be used as cache or other movable (or even unmovable
74 entities). It doesn't require reservation to prevent hugepage
75 allocation failures to be noticeable from userland. It allows paging
76 and all other advanced VM features to be available on the
77 hugepages. It requires no modifications for applications to take
78 advantage of it.
80 Applications however can be further optimized to take advantage of
81 this feature, like for example they've been optimized before to avoid
82 a flood of mmap system calls for every malloc(4k). Optimizing userland
83 is by far not mandatory and khugepaged already can take care of long
84 lived page allocations even for hugepage unaware applications that
85 deals with large amounts of memory.
87 In certain cases when hugepages are enabled system wide, application
88 may end up allocating more memory resources. An application may mmap a
89 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. This is why it's
91 possible to disable hugepages system-wide and to only have them inside
92 MADV_HUGEPAGE madvise regions.
94 Embedded systems should enable hugepages only inside madvise regions
95 to eliminate any risk of wasting any precious byte of memory and to
96 only run faster.
98 Applications that gets a lot of benefit from hugepages and that don't
99 risk to lose memory by using hugepages, should use
100 madvise(MADV_HUGEPAGE) on their critical mmapped regions.
102 .. _thp_sysfs:
104 sysfs
105 =====
107 Global THP controls
108 -------------------
110 Transparent Hugepage Support for anonymous memory can be entirely disabled
111 (mostly for debugging purposes) or only enabled inside MADV_HUGEPAGE
112 regions (to avoid the risk of consuming more memory resources) or enabled
113 system wide. This can be achieved per-supported-THP-size with one of::
115         echo always >/sys/kernel/mm/transparent_hugepage/hugepages-<size>kB/enabled
116         echo madvise >/sys/kernel/mm/transparent_hugepage/hugepages-<size>kB/enabled
117         echo never >/sys/kernel/mm/transparent_hugepage/hugepages-<size>kB/enabled
119 where <size> is the hugepage size being addressed, the available sizes
120 for which vary by system.
122 For example::
124         echo always >/sys/kernel/mm/transparent_hugepage/hugepages-2048kB/enabled
126 Alternatively it is possible to specify that a given hugepage size
127 will inherit the top-level "enabled" value::
129         echo inherit >/sys/kernel/mm/transparent_hugepage/hugepages-<size>kB/enabled
131 For example::
133         echo inherit >/sys/kernel/mm/transparent_hugepage/hugepages-2048kB/enabled
135 The top-level setting (for use with "inherit") can be set by issuing
136 one of the following commands::
138         echo always >/sys/kernel/mm/transparent_hugepage/enabled
139         echo madvise >/sys/kernel/mm/transparent_hugepage/enabled
140         echo never >/sys/kernel/mm/transparent_hugepage/enabled
142 By default, PMD-sized hugepages have enabled="inherit" and all other
143 hugepage sizes have enabled="never". If enabling multiple hugepage
144 sizes, the kernel will select the most appropriate enabled size for a
145 given allocation.
147 It's also possible to limit defrag efforts in the VM to generate
148 anonymous hugepages in case they're not immediately free to madvise
149 regions or to never try to defrag memory and simply fallback to regular
150 pages unless hugepages are immediately available. Clearly if we spend CPU
151 time to defrag memory, we would expect to gain even more by the fact we
152 use hugepages later instead of regular pages. This isn't always
153 guaranteed, but it may be more likely in case the allocation is for a
154 MADV_HUGEPAGE region.
158         echo always >/sys/kernel/mm/transparent_hugepage/defrag
159         echo defer >/sys/kernel/mm/transparent_hugepage/defrag
160         echo defer+madvise >/sys/kernel/mm/transparent_hugepage/defrag
161         echo madvise >/sys/kernel/mm/transparent_hugepage/defrag
162         echo never >/sys/kernel/mm/transparent_hugepage/defrag
164 always
165         means that an application requesting THP will stall on
166         allocation failure and directly reclaim pages and compact
167         memory in an effort to allocate a THP immediately. This may be
168         desirable for virtual machines that benefit heavily from THP
169         use and are willing to delay the VM start to utilise them.
171 defer
172         means that an application will wake kswapd in the background
173         to reclaim pages and wake kcompactd to compact memory so that
174         THP is available in the near future. It's the responsibility
175         of khugepaged to then install the THP pages later.
177 defer+madvise
178         will enter direct reclaim and compaction like ``always``, but
179         only for regions that have used madvise(MADV_HUGEPAGE); all
180         other regions will wake kswapd in the background to reclaim
181         pages and wake kcompactd to compact memory so that THP is
182         available in the near future.
184 madvise
185         will enter direct reclaim like ``always`` but only for regions
186         that are have used madvise(MADV_HUGEPAGE). This is the default
187         behaviour.
189 never
190         should be self-explanatory.
192 By default kernel tries to use huge, PMD-mappable zero page on read
193 page fault to anonymous mapping. It's possible to disable huge zero
194 page by writing 0 or enable it back by writing 1::
196         echo 0 >/sys/kernel/mm/transparent_hugepage/use_zero_page
197         echo 1 >/sys/kernel/mm/transparent_hugepage/use_zero_page
199 Some userspace (such as a test program, or an optimized memory
200 allocation library) may want to know the size (in bytes) of a
201 PMD-mappable transparent hugepage::
203         cat /sys/kernel/mm/transparent_hugepage/hpage_pmd_size
205 All THPs at fault and collapse time will be added to _deferred_list,
206 and will therefore be split under memory presure if they are considered
207 "underused". A THP is underused if the number of zero-filled pages in
208 the THP is above max_ptes_none (see below). It is possible to disable
209 this behaviour by writing 0 to shrink_underused, and enable it by writing
210 1 to it::
212         echo 0 > /sys/kernel/mm/transparent_hugepage/shrink_underused
213         echo 1 > /sys/kernel/mm/transparent_hugepage/shrink_underused
215 khugepaged will be automatically started when PMD-sized THP is enabled
216 (either of the per-size anon control or the top-level control are set
217 to "always" or "madvise"), and it'll be automatically shutdown when
218 PMD-sized THP is disabled (when both the per-size anon control and the
219 top-level control are "never")
221 Khugepaged controls
222 -------------------
224 .. note::
225    khugepaged currently only searches for opportunities to collapse to
226    PMD-sized THP and no attempt is made to collapse to other THP
227    sizes.
229 khugepaged runs usually at low frequency so while one may not want to
230 invoke defrag algorithms synchronously during the page faults, it
231 should be worth invoking defrag at least in khugepaged. However it's
232 also possible to disable defrag in khugepaged by writing 0 or enable
233 defrag in khugepaged by writing 1::
235         echo 0 >/sys/kernel/mm/transparent_hugepage/khugepaged/defrag
236         echo 1 >/sys/kernel/mm/transparent_hugepage/khugepaged/defrag
238 You can also control how many pages khugepaged should scan at each
239 pass::
241         /sys/kernel/mm/transparent_hugepage/khugepaged/pages_to_scan
243 and how many milliseconds to wait in khugepaged between each pass (you
244 can set this to 0 to run khugepaged at 100% utilization of one core)::
246         /sys/kernel/mm/transparent_hugepage/khugepaged/scan_sleep_millisecs
248 and how many milliseconds to wait in khugepaged if there's an hugepage
249 allocation failure to throttle the next allocation attempt::
251         /sys/kernel/mm/transparent_hugepage/khugepaged/alloc_sleep_millisecs
253 The khugepaged progress can be seen in the number of pages collapsed (note
254 that this counter may not be an exact count of the number of pages
255 collapsed, since "collapsed" could mean multiple things: (1) A PTE mapping
256 being replaced by a PMD mapping, or (2) All 4K physical pages replaced by
257 one 2M hugepage. Each may happen independently, or together, depending on
258 the type of memory and the failures that occur. As such, this value should
259 be interpreted roughly as a sign of progress, and counters in /proc/vmstat
260 consulted for more accurate accounting)::
262         /sys/kernel/mm/transparent_hugepage/khugepaged/pages_collapsed
264 for each pass::
266         /sys/kernel/mm/transparent_hugepage/khugepaged/full_scans
268 ``max_ptes_none`` specifies how many extra small pages (that are
269 not already mapped) can be allocated when collapsing a group
270 of small pages into one large page::
272         /sys/kernel/mm/transparent_hugepage/khugepaged/max_ptes_none
274 A higher value leads to use additional memory for programs.
275 A lower value leads to gain less thp performance. Value of
276 max_ptes_none can waste cpu time very little, you can
277 ignore it.
279 ``max_ptes_swap`` specifies how many pages can be brought in from
280 swap when collapsing a group of pages into a transparent huge page::
282         /sys/kernel/mm/transparent_hugepage/khugepaged/max_ptes_swap
284 A higher value can cause excessive swap IO and waste
285 memory. A lower value can prevent THPs from being
286 collapsed, resulting fewer pages being collapsed into
287 THPs, and lower memory access performance.
289 ``max_ptes_shared`` specifies how many pages can be shared across multiple
290 processes. khugepaged might treat pages of THPs as shared if any page of
291 that THP is shared. Exceeding the number would block the collapse::
293         /sys/kernel/mm/transparent_hugepage/khugepaged/max_ptes_shared
295 A higher value may increase memory footprint for some workloads.
297 Boot parameters
298 ===============
300 You can change the sysfs boot time default for the top-level "enabled"
301 control by passing the parameter ``transparent_hugepage=always`` or
302 ``transparent_hugepage=madvise`` or ``transparent_hugepage=never`` to the
303 kernel command line.
305 Alternatively, each supported anonymous THP size can be controlled by
306 passing ``thp_anon=<size>[KMG],<size>[KMG]:<state>;<size>[KMG]-<size>[KMG]:<state>``,
307 where ``<size>`` is the THP size (must be a power of 2 of PAGE_SIZE and
308 supported anonymous THP)  and ``<state>`` is one of ``always``, ``madvise``,
309 ``never`` or ``inherit``.
311 For example, the following will set 16K, 32K, 64K THP to ``always``,
312 set 128K, 512K to ``inherit``, set 256K to ``madvise`` and 1M, 2M
313 to ``never``::
315         thp_anon=16K-64K:always;128K,512K:inherit;256K:madvise;1M-2M:never
317 ``thp_anon=`` may be specified multiple times to configure all THP sizes as
318 required. If ``thp_anon=`` is specified at least once, any anon THP sizes
319 not explicitly configured on the command line are implicitly set to
320 ``never``.
322 ``transparent_hugepage`` setting only affects the global toggle. If
323 ``thp_anon`` is not specified, PMD_ORDER THP will default to ``inherit``.
324 However, if a valid ``thp_anon`` setting is provided by the user, the
325 PMD_ORDER THP policy will be overridden. If the policy for PMD_ORDER
326 is not defined within a valid ``thp_anon``, its policy will default to
327 ``never``.
329 Similarly to ``transparent_hugepage``, you can control the hugepage
330 allocation policy for the internal shmem mount by using the kernel parameter
331 ``transparent_hugepage_shmem=<policy>``, where ``<policy>`` is one of the
332 seven valid policies for shmem (``always``, ``within_size``, ``advise``,
333 ``never``, ``deny``, and ``force``).
335 Similarly to ``transparent_hugepage_shmem``, you can control the default
336 hugepage allocation policy for the tmpfs mount by using the kernel parameter
337 ``transparent_hugepage_tmpfs=<policy>``, where ``<policy>`` is one of the
338 four valid policies for tmpfs (``always``, ``within_size``, ``advise``,
339 ``never``). The tmpfs mount default policy is ``never``.
341 In the same manner as ``thp_anon`` controls each supported anonymous THP
342 size, ``thp_shmem`` controls each supported shmem THP size. ``thp_shmem``
343 has the same format as ``thp_anon``, but also supports the policy
344 ``within_size``.
346 ``thp_shmem=`` may be specified multiple times to configure all THP sizes
347 as required. If ``thp_shmem=`` is specified at least once, any shmem THP
348 sizes not explicitly configured on the command line are implicitly set to
349 ``never``.
351 ``transparent_hugepage_shmem`` setting only affects the global toggle. If
352 ``thp_shmem`` is not specified, PMD_ORDER hugepage will default to
353 ``inherit``. However, if a valid ``thp_shmem`` setting is provided by the
354 user, the PMD_ORDER hugepage policy will be overridden. If the policy for
355 PMD_ORDER is not defined within a valid ``thp_shmem``, its policy will
356 default to ``never``.
358 Hugepages in tmpfs/shmem
359 ========================
361 Traditionally, tmpfs only supported a single huge page size ("PMD"). Today,
362 it also supports smaller sizes just like anonymous memory, often referred
363 to as "multi-size THP" (mTHP). Huge pages of any size are commonly
364 represented in the kernel as "large folios".
366 While there is fine control over the huge page sizes to use for the internal
367 shmem mount (see below), ordinary tmpfs mounts will make use of all available
368 huge page sizes without any control over the exact sizes, behaving more like
369 other file systems.
371 tmpfs mounts
372 ------------
374 The THP allocation policy for tmpfs mounts can be adjusted using the mount
375 option: ``huge=``. It can have following values:
377 always
378     Attempt to allocate huge pages every time we need a new page;
380 never
381     Do not allocate huge pages;
383 within_size
384     Only allocate huge page if it will be fully within i_size.
385     Also respect madvise() hints;
387 advise
388     Only allocate huge pages if requested with madvise();
390 Remember, that the kernel may use huge pages of all available sizes, and
391 that no fine control as for the internal tmpfs mount is available.
393 The default policy in the past was ``never``, but it can now be adjusted
394 using the kernel parameter ``transparent_hugepage_tmpfs=<policy>``.
396 ``mount -o remount,huge= /mountpoint`` works fine after mount: remounting
397 ``huge=never`` will not attempt to break up huge pages at all, just stop more
398 from being allocated.
400 In addition to policies listed above, the sysfs knob
401 /sys/kernel/mm/transparent_hugepage/shmem_enabled will affect the
402 allocation policy of tmpfs mounts, when set to the following values:
404 deny
405     For use in emergencies, to force the huge option off from
406     all mounts;
407 force
408     Force the huge option on for all - very useful for testing;
410 shmem / internal tmpfs
411 ----------------------
412 The mount internal tmpfs mount is used for SysV SHM, memfds, shared anonymous
413 mmaps (of /dev/zero or MAP_ANONYMOUS), GPU drivers' DRM  objects, Ashmem.
415 To control the THP allocation policy for this internal tmpfs mount, the
416 sysfs knob /sys/kernel/mm/transparent_hugepage/shmem_enabled and the knobs
417 per THP size in
418 '/sys/kernel/mm/transparent_hugepage/hugepages-<size>kB/shmem_enabled'
419 can be used.
421 The global knob has the same semantics as the ``huge=`` mount options
422 for tmpfs mounts, except that the different huge page sizes can be controlled
423 individually, and will only use the setting of the global knob when the
424 per-size knob is set to 'inherit'.
426 The options 'force' and 'deny' are dropped for the individual sizes, which
427 are rather testing artifacts from the old ages.
429 always
430     Attempt to allocate <size> huge pages every time we need a new page;
432 inherit
433     Inherit the top-level "shmem_enabled" value. By default, PMD-sized hugepages
434     have enabled="inherit" and all other hugepage sizes have enabled="never";
436 never
437     Do not allocate <size> huge pages;
439 within_size
440     Only allocate <size> huge page if it will be fully within i_size.
441     Also respect madvise() hints;
443 advise
444     Only allocate <size> huge pages if requested with madvise();
446 Need of application restart
447 ===========================
449 The transparent_hugepage/enabled and
450 transparent_hugepage/hugepages-<size>kB/enabled values and tmpfs mount
451 option only affect future behavior. So to make them effective you need
452 to restart any application that could have been using hugepages. This
453 also applies to the regions registered in khugepaged.
455 Monitoring usage
456 ================
458 The number of PMD-sized anonymous transparent huge pages currently used by the
459 system is available by reading the AnonHugePages field in ``/proc/meminfo``.
460 To identify what applications are using PMD-sized anonymous transparent huge
461 pages, it is necessary to read ``/proc/PID/smaps`` and count the AnonHugePages
462 fields for each mapping. (Note that AnonHugePages only applies to traditional
463 PMD-sized THP for historical reasons and should have been called
464 AnonHugePmdMapped).
466 The number of file transparent huge pages mapped to userspace is available
467 by reading ShmemPmdMapped and ShmemHugePages fields in ``/proc/meminfo``.
468 To identify what applications are mapping file transparent huge pages, it
469 is necessary to read ``/proc/PID/smaps`` and count the FilePmdMapped fields
470 for each mapping.
472 Note that reading the smaps file is expensive and reading it
473 frequently will incur overhead.
475 There are a number of counters in ``/proc/vmstat`` that may be used to
476 monitor how successfully the system is providing huge pages for use.
478 thp_fault_alloc
479         is incremented every time a huge page is successfully
480         allocated and charged to handle a page fault.
482 thp_collapse_alloc
483         is incremented by khugepaged when it has found
484         a range of pages to collapse into one huge page and has
485         successfully allocated a new huge page to store the data.
487 thp_fault_fallback
488         is incremented if a page fault fails to allocate or charge
489         a huge page and instead falls back to using small pages.
491 thp_fault_fallback_charge
492         is incremented if a page fault fails to charge a huge page and
493         instead falls back to using small pages even though the
494         allocation was successful.
496 thp_collapse_alloc_failed
497         is incremented if khugepaged found a range
498         of pages that should be collapsed into one huge page but failed
499         the allocation.
501 thp_file_alloc
502         is incremented every time a shmem huge page is successfully
503         allocated (Note that despite being named after "file", the counter
504         measures only shmem).
506 thp_file_fallback
507         is incremented if a shmem huge page is attempted to be allocated
508         but fails and instead falls back to using small pages. (Note that
509         despite being named after "file", the counter measures only shmem).
511 thp_file_fallback_charge
512         is incremented if a shmem huge page cannot be charged and instead
513         falls back to using small pages even though the allocation was
514         successful. (Note that despite being named after "file", the
515         counter measures only shmem).
517 thp_file_mapped
518         is incremented every time a file or shmem huge page is mapped into
519         user address space.
521 thp_split_page
522         is incremented every time a huge page is split into base
523         pages. This can happen for a variety of reasons but a common
524         reason is that a huge page is old and is being reclaimed.
525         This action implies splitting all PMD the page mapped with.
527 thp_split_page_failed
528         is incremented if kernel fails to split huge
529         page. This can happen if the page was pinned by somebody.
531 thp_deferred_split_page
532         is incremented when a huge page is put onto split
533         queue. This happens when a huge page is partially unmapped and
534         splitting it would free up some memory. Pages on split queue are
535         going to be split under memory pressure.
537 thp_underused_split_page
538         is incremented when a huge page on the split queue was split
539         because it was underused. A THP is underused if the number of
540         zero pages in the THP is above a certain threshold
541         (/sys/kernel/mm/transparent_hugepage/khugepaged/max_ptes_none).
543 thp_split_pmd
544         is incremented every time a PMD split into table of PTEs.
545         This can happen, for instance, when application calls mprotect() or
546         munmap() on part of huge page. It doesn't split huge page, only
547         page table entry.
549 thp_zero_page_alloc
550         is incremented every time a huge zero page used for thp is
551         successfully allocated. Note, it doesn't count every map of
552         the huge zero page, only its allocation.
554 thp_zero_page_alloc_failed
555         is incremented if kernel fails to allocate
556         huge zero page and falls back to using small pages.
558 thp_swpout
559         is incremented every time a huge page is swapout in one
560         piece without splitting.
562 thp_swpout_fallback
563         is incremented if a huge page has to be split before swapout.
564         Usually because failed to allocate some continuous swap space
565         for the huge page.
567 In /sys/kernel/mm/transparent_hugepage/hugepages-<size>kB/stats, There are
568 also individual counters for each huge page size, which can be utilized to
569 monitor the system's effectiveness in providing huge pages for usage. Each
570 counter has its own corresponding file.
572 anon_fault_alloc
573         is incremented every time a huge page is successfully
574         allocated and charged to handle a page fault.
576 anon_fault_fallback
577         is incremented if a page fault fails to allocate or charge
578         a huge page and instead falls back to using huge pages with
579         lower orders or small pages.
581 anon_fault_fallback_charge
582         is incremented if a page fault fails to charge a huge page and
583         instead falls back to using huge pages with lower orders or
584         small pages even though the allocation was successful.
586 zswpout
587         is incremented every time a huge page is swapped out to zswap in one
588         piece without splitting.
590 swpin
591         is incremented every time a huge page is swapped in from a non-zswap
592         swap device in one piece.
594 swpin_fallback
595         is incremented if swapin fails to allocate or charge a huge page
596         and instead falls back to using huge pages with lower orders or
597         small pages.
599 swpin_fallback_charge
600         is incremented if swapin fails to charge a huge page and instead
601         falls back to using  huge pages with lower orders or small pages
602         even though the allocation was successful.
604 swpout
605         is incremented every time a huge page is swapped out to a non-zswap
606         swap device in one piece without splitting.
608 swpout_fallback
609         is incremented if a huge page has to be split before swapout.
610         Usually because failed to allocate some continuous swap space
611         for the huge page.
613 shmem_alloc
614         is incremented every time a shmem huge page is successfully
615         allocated.
617 shmem_fallback
618         is incremented if a shmem huge page is attempted to be allocated
619         but fails and instead falls back to using small pages.
621 shmem_fallback_charge
622         is incremented if a shmem huge page cannot be charged and instead
623         falls back to using small pages even though the allocation was
624         successful.
626 split
627         is incremented every time a huge page is successfully split into
628         smaller orders. This can happen for a variety of reasons but a
629         common reason is that a huge page is old and is being reclaimed.
631 split_failed
632         is incremented if kernel fails to split huge
633         page. This can happen if the page was pinned by somebody.
635 split_deferred
636         is incremented when a huge page is put onto split queue.
637         This happens when a huge page is partially unmapped and splitting
638         it would free up some memory. Pages on split queue are going to
639         be split under memory pressure, if splitting is possible.
641 nr_anon
642        the number of anonymous THP we have in the whole system. These THPs
643        might be currently entirely mapped or have partially unmapped/unused
644        subpages.
646 nr_anon_partially_mapped
647        the number of anonymous THP which are likely partially mapped, possibly
648        wasting memory, and have been queued for deferred memory reclamation.
649        Note that in corner some cases (e.g., failed migration), we might detect
650        an anonymous THP as "partially mapped" and count it here, even though it
651        is not actually partially mapped anymore.
653 As the system ages, allocating huge pages may be expensive as the
654 system uses memory compaction to copy data around memory to free a
655 huge page for use. There are some counters in ``/proc/vmstat`` to help
656 monitor this overhead.
658 compact_stall
659         is incremented every time a process stalls to run
660         memory compaction so that a huge page is free for use.
662 compact_success
663         is incremented if the system compacted memory and
664         freed a huge page for use.
666 compact_fail
667         is incremented if the system tries to compact memory
668         but failed.
670 It is possible to establish how long the stalls were using the function
671 tracer to record how long was spent in __alloc_pages() and
672 using the mm_page_alloc tracepoint to identify which allocations were
673 for huge pages.
675 Optimizing the applications
676 ===========================
678 To be guaranteed that the kernel will map a THP immediately in any
679 memory region, the mmap region has to be hugepage naturally
680 aligned. posix_memalign() can provide that guarantee.
682 Hugetlbfs
683 =========
685 You can use hugetlbfs on a kernel that has transparent hugepage
686 support enabled just fine as always. No difference can be noted in
687 hugetlbfs other than there will be less overall fragmentation. All
688 usual features belonging to hugetlbfs are preserved and
689 unaffected. libhugetlbfs will also work fine as usual.