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