Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) .. _hugetlbpage:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) =============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) HugeTLB Pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) =============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) Overview
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) ========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) The intent of this file is to give a brief summary of hugetlbpage support in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) the Linux kernel.  This support is built on top of multiple page size support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) that is provided by most modern architectures.  For example, x86 CPUs normally
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) support 4K and 2M (1G if architecturally supported) page sizes, ia64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) architecture supports multiple page sizes 4K, 8K, 64K, 256K, 1M, 4M, 16M,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 256M and ppc64 supports 4K and 16M.  A TLB is a cache of virtual-to-physical
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) translations.  Typically this is a very scarce resource on processor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) Operating systems try to make best use of limited number of TLB resources.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) This optimization is more critical now as bigger and bigger physical memories
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) (several GBs) are more readily available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) Users can use the huge page support in Linux kernel by either using the mmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) system call or standard SYSV shared memory system calls (shmget, shmat).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) First the Linux kernel needs to be built with the CONFIG_HUGETLBFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) (present under "File systems") and CONFIG_HUGETLB_PAGE (selected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) automatically when CONFIG_HUGETLBFS is selected) configuration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) options.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) The ``/proc/meminfo`` file provides information about the total number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) persistent hugetlb pages in the kernel's huge page pool.  It also displays
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) default huge page size and information about the number of free, reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) and surplus huge pages in the pool of huge pages of default size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) The huge page size is needed for generating the proper alignment and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) size of the arguments to system calls that map huge page regions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) The output of ``cat /proc/meminfo`` will include lines like::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	HugePages_Total: uuu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	HugePages_Free:  vvv
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	HugePages_Rsvd:  www
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	HugePages_Surp:  xxx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	Hugepagesize:    yyy kB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	Hugetlb:         zzz kB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) where:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) HugePages_Total
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	is the size of the pool of huge pages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) HugePages_Free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	is the number of huge pages in the pool that are not yet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)         allocated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) HugePages_Rsvd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	is short for "reserved," and is the number of huge pages for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)         which a commitment to allocate from the pool has been made,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)         but no allocation has yet been made.  Reserved huge pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)         guarantee that an application will be able to allocate a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)         huge page from the pool of huge pages at fault time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) HugePages_Surp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	is short for "surplus," and is the number of huge pages in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)         the pool above the value in ``/proc/sys/vm/nr_hugepages``. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)         maximum number of surplus huge pages is controlled by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)         ``/proc/sys/vm/nr_overcommit_hugepages``.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) Hugepagesize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	is the default hugepage size (in Kb).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) Hugetlb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)         is the total amount of memory (in kB), consumed by huge
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67)         pages of all sizes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68)         If huge pages of different sizes are in use, this number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)         will exceed HugePages_Total \* Hugepagesize. To get more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)         detailed information, please, refer to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)         ``/sys/kernel/mm/hugepages`` (described below).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) ``/proc/filesystems`` should also show a filesystem of type "hugetlbfs"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) configured in the kernel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) ``/proc/sys/vm/nr_hugepages`` indicates the current number of "persistent" huge
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) pages in the kernel's huge page pool.  "Persistent" huge pages will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) returned to the huge page pool when freed by a task.  A user with root
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) privileges can dynamically allocate more or free some persistent huge pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) by increasing or decreasing the value of ``nr_hugepages``.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) Pages that are used as huge pages are reserved inside the kernel and cannot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) be used for other purposes.  Huge pages cannot be swapped out under
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) memory pressure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) Once a number of huge pages have been pre-allocated to the kernel huge page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) pool, a user with appropriate privilege can use either the mmap system call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) or shared memory system calls to use the huge pages.  See the discussion of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) :ref:`Using Huge Pages <using_huge_pages>`, below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) The administrator can allocate persistent huge pages on the kernel boot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) command line by specifying the "hugepages=N" parameter, where 'N' = the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) number of huge pages requested.  This is the most reliable method of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) allocating huge pages as memory has not yet become fragmented.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) Some platforms support multiple huge page sizes.  To allocate huge pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) of a specific size, one must precede the huge pages boot command parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) with a huge page size selection parameter "hugepagesz=<size>".  <size> must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) be specified in bytes with optional scale suffix [kKmMgG].  The default huge
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) page size may be selected with the "default_hugepagesz=<size>" boot parameter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) Hugetlb boot command line parameter semantics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) hugepagesz
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	Specify a huge page size.  Used in conjunction with hugepages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	parameter to preallocate a number of huge pages of the specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	size.  Hence, hugepagesz and hugepages are typically specified in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	pairs such as::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		hugepagesz=2M hugepages=512
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	hugepagesz can only be specified once on the command line for a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	specific huge page size.  Valid huge page sizes are architecture
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	dependent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) hugepages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	Specify the number of huge pages to preallocate.  This typically
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	follows a valid hugepagesz or default_hugepagesz parameter.  However,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	if hugepages is the first or only hugetlb command line parameter it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	implicitly specifies the number of huge pages of default size to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	allocate.  If the number of huge pages of default size is implicitly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	specified, it can not be overwritten by a hugepagesz,hugepages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	parameter pair for the default size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	For example, on an architecture with 2M default huge page size::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		hugepages=256 hugepagesz=2M hugepages=512
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	will result in 256 2M huge pages being allocated and a warning message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	indicating that the hugepages=512 parameter is ignored.  If a hugepages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	parameter is preceded by an invalid hugepagesz parameter, it will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	be ignored.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) default_hugepagesz
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	Specify the default huge page size.  This parameter can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	only be specified once on the command line.  default_hugepagesz can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	optionally be followed by the hugepages parameter to preallocate a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	specific number of huge pages of default size.  The number of default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	sized huge pages to preallocate can also be implicitly specified as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	mentioned in the hugepages section above.  Therefore, on an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	architecture with 2M default huge page size::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		hugepages=256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		default_hugepagesz=2M hugepages=256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		hugepages=256 default_hugepagesz=2M
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	will all result in 256 2M huge pages being allocated.  Valid default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	huge page size is architecture dependent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) When multiple huge page sizes are supported, ``/proc/sys/vm/nr_hugepages``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) indicates the current number of pre-allocated huge pages of the default size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) Thus, one can use the following command to dynamically allocate/deallocate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) default sized persistent huge pages::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	echo 20 > /proc/sys/vm/nr_hugepages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) This command will try to adjust the number of default sized huge pages in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) huge page pool to 20, allocating or freeing huge pages, as required.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) On a NUMA platform, the kernel will attempt to distribute the huge page pool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) over all the set of allowed nodes specified by the NUMA memory policy of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) task that modifies ``nr_hugepages``. The default for the allowed nodes--when the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) task has default memory policy--is all on-line nodes with memory.  Allowed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) nodes with insufficient available, contiguous memory for a huge page will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) silently skipped when allocating persistent huge pages.  See the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) :ref:`discussion below <mem_policy_and_hp_alloc>`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) of the interaction of task memory policy, cpusets and per node attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) with the allocation and freeing of persistent huge pages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) The success or failure of huge page allocation depends on the amount of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) physically contiguous memory that is present in system at the time of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) allocation attempt.  If the kernel is unable to allocate huge pages from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) some nodes in a NUMA system, it will attempt to make up the difference by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) allocating extra pages on other nodes with sufficient available contiguous
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) memory, if any.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) System administrators may want to put this command in one of the local rc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) init files.  This will enable the kernel to allocate huge pages early in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) the boot process when the possibility of getting physical contiguous pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) is still very high.  Administrators can verify the number of huge pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) actually allocated by checking the sysctl or meminfo.  To check the per node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) distribution of huge pages in a NUMA system, use::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	cat /sys/devices/system/node/node*/meminfo | fgrep Huge
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) ``/proc/sys/vm/nr_overcommit_hugepages`` specifies how large the pool of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) huge pages can grow, if more huge pages than ``/proc/sys/vm/nr_hugepages`` are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) requested by applications.  Writing any non-zero value into this file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) indicates that the hugetlb subsystem is allowed to try to obtain that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) number of "surplus" huge pages from the kernel's normal page pool, when the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) persistent huge page pool is exhausted. As these surplus huge pages become
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) unused, they are freed back to the kernel's normal page pool.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) When increasing the huge page pool size via ``nr_hugepages``, any existing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) surplus pages will first be promoted to persistent huge pages.  Then, additional
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) huge pages will be allocated, if necessary and if possible, to fulfill
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) the new persistent huge page pool size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) The administrator may shrink the pool of persistent huge pages for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) the default huge page size by setting the ``nr_hugepages`` sysctl to a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) smaller value.  The kernel will attempt to balance the freeing of huge pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) across all nodes in the memory policy of the task modifying ``nr_hugepages``.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) Any free huge pages on the selected nodes will be freed back to the kernel's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) normal page pool.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) Caveat: Shrinking the persistent huge page pool via ``nr_hugepages`` such that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) it becomes less than the number of huge pages in use will convert the balance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) of the in-use huge pages to surplus huge pages.  This will occur even if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) the number of surplus pages would exceed the overcommit value.  As long as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) this condition holds--that is, until ``nr_hugepages+nr_overcommit_hugepages`` is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) increased sufficiently, or the surplus huge pages go out of use and are freed--
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) no more surplus huge pages will be allowed to be allocated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) With support for multiple huge page pools at run-time available, much of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) the huge page userspace interface in ``/proc/sys/vm`` has been duplicated in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) sysfs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) The ``/proc`` interfaces discussed above have been retained for backwards
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) compatibility. The root huge page control directory in sysfs is::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	/sys/kernel/mm/hugepages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) For each huge page size supported by the running kernel, a subdirectory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) will exist, of the form::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	hugepages-${size}kB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) Inside each of these directories, the same set of files will exist::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	nr_hugepages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	nr_hugepages_mempolicy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	nr_overcommit_hugepages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	free_hugepages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	resv_hugepages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	surplus_hugepages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) which function as described above for the default huge page-sized case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) .. _mem_policy_and_hp_alloc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) Interaction of Task Memory Policy with Huge Page Allocation/Freeing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) ===================================================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) Whether huge pages are allocated and freed via the ``/proc`` interface or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) the ``/sysfs`` interface using the ``nr_hugepages_mempolicy`` attribute, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) NUMA nodes from which huge pages are allocated or freed are controlled by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) NUMA memory policy of the task that modifies the ``nr_hugepages_mempolicy``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) sysctl or attribute.  When the ``nr_hugepages`` attribute is used, mempolicy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) is ignored.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) The recommended method to allocate or free huge pages to/from the kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) huge page pool, using the ``nr_hugepages`` example above, is::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)     numactl --interleave <node-list> echo 20 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 				>/proc/sys/vm/nr_hugepages_mempolicy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) or, more succinctly::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)     numactl -m <node-list> echo 20 >/proc/sys/vm/nr_hugepages_mempolicy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) This will allocate or free ``abs(20 - nr_hugepages)`` to or from the nodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) specified in <node-list>, depending on whether number of persistent huge pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) is initially less than or greater than 20, respectively.  No huge pages will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) allocated nor freed on any node not included in the specified <node-list>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) When adjusting the persistent hugepage count via ``nr_hugepages_mempolicy``, any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) memory policy mode--bind, preferred, local or interleave--may be used.  The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) resulting effect on persistent huge page allocation is as follows:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) #. Regardless of mempolicy mode [see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)    :ref:`Documentation/admin-guide/mm/numa_memory_policy.rst <numa_memory_policy>`],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)    persistent huge pages will be distributed across the node or nodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)    specified in the mempolicy as if "interleave" had been specified.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)    However, if a node in the policy does not contain sufficient contiguous
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)    memory for a huge page, the allocation will not "fallback" to the nearest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)    neighbor node with sufficient contiguous memory.  To do this would cause
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)    undesirable imbalance in the distribution of the huge page pool, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)    possibly, allocation of persistent huge pages on nodes not allowed by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)    the task's memory policy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) #. One or more nodes may be specified with the bind or interleave policy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)    If more than one node is specified with the preferred policy, only the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)    lowest numeric id will be used.  Local policy will select the node where
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)    the task is running at the time the nodes_allowed mask is constructed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)    For local policy to be deterministic, the task must be bound to a cpu or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)    cpus in a single node.  Otherwise, the task could be migrated to some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)    other node at any time after launch and the resulting node will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)    indeterminate.  Thus, local policy is not very useful for this purpose.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)    Any of the other mempolicy modes may be used to specify a single node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) #. The nodes allowed mask will be derived from any non-default task mempolicy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)    whether this policy was set explicitly by the task itself or one of its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)    ancestors, such as numactl.  This means that if the task is invoked from a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)    shell with non-default policy, that policy will be used.  One can specify a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)    node list of "all" with numactl --interleave or --membind [-m] to achieve
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)    interleaving over all nodes in the system or cpuset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) #. Any task mempolicy specified--e.g., using numactl--will be constrained by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)    the resource limits of any cpuset in which the task runs.  Thus, there will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)    be no way for a task with non-default policy running in a cpuset with a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)    subset of the system nodes to allocate huge pages outside the cpuset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)    without first moving to a cpuset that contains all of the desired nodes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) #. Boot-time huge page allocation attempts to distribute the requested number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)    of huge pages over all on-lines nodes with memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) Per Node Hugepages Attributes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) =============================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) A subset of the contents of the root huge page control directory in sysfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) described above, will be replicated under each the system device of each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) NUMA node with memory in::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	/sys/devices/system/node/node[0-9]*/hugepages/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) Under this directory, the subdirectory for each supported huge page size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) contains the following attribute files::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	nr_hugepages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	free_hugepages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	surplus_hugepages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) The free\_' and surplus\_' attribute files are read-only.  They return the number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) of free and surplus [overcommitted] huge pages, respectively, on the parent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) The ``nr_hugepages`` attribute returns the total number of huge pages on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) specified node.  When this attribute is written, the number of persistent huge
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) pages on the parent node will be adjusted to the specified value, if sufficient
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) resources exist, regardless of the task's mempolicy or cpuset constraints.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) Note that the number of overcommit and reserve pages remain global quantities,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) as we don't know until fault time, when the faulting task's mempolicy is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) applied, from which node the huge page allocation will be attempted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) .. _using_huge_pages:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) Using Huge Pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) ================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) If the user applications are going to request huge pages using mmap system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) call, then it is required that system administrator mount a file system of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) type hugetlbfs::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)   mount -t hugetlbfs \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	-o uid=<value>,gid=<value>,mode=<value>,pagesize=<value>,size=<value>,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	min_size=<value>,nr_inodes=<value> none /mnt/huge
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) This command mounts a (pseudo) filesystem of type hugetlbfs on the directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) ``/mnt/huge``.  Any file created on ``/mnt/huge`` uses huge pages.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) The ``uid`` and ``gid`` options sets the owner and group of the root of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) file system.  By default the ``uid`` and ``gid`` of the current process
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) are taken.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) The ``mode`` option sets the mode of root of file system to value & 01777.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) This value is given in octal. By default the value 0755 is picked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) If the platform supports multiple huge page sizes, the ``pagesize`` option can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) be used to specify the huge page size and associated pool. ``pagesize``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) is specified in bytes. If ``pagesize`` is not specified the platform's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) default huge page size and associated pool will be used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) The ``size`` option sets the maximum value of memory (huge pages) allowed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) for that filesystem (``/mnt/huge``). The ``size`` option can be specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) in bytes, or as a percentage of the specified huge page pool (``nr_hugepages``).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) The size is rounded down to HPAGE_SIZE boundary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) The ``min_size`` option sets the minimum value of memory (huge pages) allowed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) for the filesystem. ``min_size`` can be specified in the same way as ``size``,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) either bytes or a percentage of the huge page pool.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) At mount time, the number of huge pages specified by ``min_size`` are reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) for use by the filesystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) If there are not enough free huge pages available, the mount will fail.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) As huge pages are allocated to the filesystem and freed, the reserve count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) is adjusted so that the sum of allocated and reserved huge pages is always
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) at least ``min_size``.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) The option ``nr_inodes`` sets the maximum number of inodes that ``/mnt/huge``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) can use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) If the ``size``, ``min_size`` or ``nr_inodes`` option is not provided on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) command line then no limits are set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) For ``pagesize``, ``size``, ``min_size`` and ``nr_inodes`` options, you can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) use [G|g]/[M|m]/[K|k] to represent giga/mega/kilo.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) For example, size=2K has the same meaning as size=2048.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) While read system calls are supported on files that reside on hugetlb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) file systems, write system calls are not.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) Regular chown, chgrp, and chmod commands (with right permissions) could be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) used to change the file attributes on hugetlbfs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) Also, it is important to note that no such mount command is required if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) applications are going to use only shmat/shmget system calls or mmap with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) MAP_HUGETLB.  For an example of how to use mmap with MAP_HUGETLB see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) :ref:`map_hugetlb <map_hugetlb>` below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) Users who wish to use hugetlb memory via shared memory segment should be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) members of a supplementary group and system admin needs to configure that gid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) into ``/proc/sys/vm/hugetlb_shm_group``.  It is possible for same or different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) applications to use any combination of mmaps and shm* calls, though the mount of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) filesystem will be required for using mmap calls without MAP_HUGETLB.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) Syscalls that operate on memory backed by hugetlb pages only have their lengths
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) aligned to the native page size of the processor; they will normally fail with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) errno set to EINVAL or exclude hugetlb pages that extend beyond the length if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) not hugepage aligned.  For example, munmap(2) will fail if memory is backed by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) a hugetlb page and the length is smaller than the hugepage size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) Examples
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) ========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) .. _map_hugetlb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) ``map_hugetlb``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	see tools/testing/selftests/vm/map_hugetlb.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) ``hugepage-shm``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	see tools/testing/selftests/vm/hugepage-shm.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) ``hugepage-mmap``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	see tools/testing/selftests/vm/hugepage-mmap.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) The `libhugetlbfs`_  library provides a wide range of userspace tools
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) to help with huge page usability, environment setup, and control.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) .. _libhugetlbfs: https://github.com/libhugetlbfs/libhugetlbfs