blob: 1cc0bc78d10e525d541352ea189c9c925bb85991 [file] [log] [blame]
Mike Rapoport148723f2018-03-21 21:22:23 +02001.. _hugetlbpage:
2
3=============
4HugeTLB Pages
5=============
6
7Overview
8========
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
10The intent of this file is to give a brief summary of hugetlbpage support in
11the Linux kernel. This support is built on top of multiple page size support
Masanari Iidac0d73052014-11-07 00:31:15 +090012that is provided by most modern architectures. For example, x86 CPUs normally
13support 4K and 2M (1G if architecturally supported) page sizes, ia64
Linus Torvalds1da177e2005-04-16 15:20:36 -070014architecture supports multiple page sizes 4K, 8K, 64K, 256K, 1M, 4M, 16M,
15256M and ppc64 supports 4K and 16M. A TLB is a cache of virtual-to-physical
16translations. Typically this is a very scarce resource on processor.
17Operating systems try to make best use of limited number of TLB resources.
18This optimization is more critical now as bigger and bigger physical memories
19(several GBs) are more readily available.
20
21Users can use the huge page support in Linux kernel by either using the mmap
Lee Schermerhorn267b4c22009-12-14 17:58:30 -080022system call or standard SYSV shared memory system calls (shmget, shmat).
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Muli Ben-Yehuda5c7ad512005-11-07 00:59:42 -080024First the Linux kernel needs to be built with the CONFIG_HUGETLBFS
25(present under "File systems") and CONFIG_HUGETLB_PAGE (selected
26automatically when CONFIG_HUGETLBFS is selected) configuration
27options.
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Mike Rapoport148723f2018-03-21 21:22:23 +020029The ``/proc/meminfo`` file provides information about the total number of
Lee Schermerhorn267b4c22009-12-14 17:58:30 -080030persistent hugetlb pages in the kernel's huge page pool. It also displays
Roman Gushchinfcb2b0c2018-01-31 16:16:22 -080031default huge page size and information about the number of free, reserved
32and surplus huge pages in the pool of huge pages of default size.
33The huge page size is needed for generating the proper alignment and
34size of the arguments to system calls that map huge page regions.
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Mike Rapoport148723f2018-03-21 21:22:23 +020036The output of ``cat /proc/meminfo`` will include lines like::
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Mike Rapoport148723f2018-03-21 21:22:23 +020038 HugePages_Total: uuu
39 HugePages_Free: vvv
40 HugePages_Rsvd: www
41 HugePages_Surp: xxx
42 Hugepagesize: yyy kB
43 Hugetlb: zzz kB
Randy Dunlap5e122272006-04-18 22:21:51 -070044
45where:
Mike Rapoport148723f2018-03-21 21:22:23 +020046
47HugePages_Total
48 is the size of the pool of huge pages.
49HugePages_Free
50 is the number of huge pages in the pool that are not yet
51 allocated.
52HugePages_Rsvd
53 is short for "reserved," and is the number of huge pages for
54 which a commitment to allocate from the pool has been made,
55 but no allocation has yet been made. Reserved huge pages
56 guarantee that an application will be able to allocate a
57 huge page from the pool of huge pages at fault time.
58HugePages_Surp
59 is short for "surplus," and is the number of huge pages in
60 the pool above the value in ``/proc/sys/vm/nr_hugepages``. The
61 maximum number of surplus huge pages is controlled by
62 ``/proc/sys/vm/nr_overcommit_hugepages``.
63Hugepagesize
64 is the default hugepage size (in Kb).
65Hugetlb
66 is the total amount of memory (in kB), consumed by huge
67 pages of all sizes.
68 If huge pages of different sizes are in use, this number
69 will exceed HugePages_Total \* Hugepagesize. To get more
70 detailed information, please, refer to
71 ``/sys/kernel/mm/hugepages`` (described below).
Roman Gushchinfcb2b0c2018-01-31 16:16:22 -080072
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Mike Rapoport148723f2018-03-21 21:22:23 +020074``/proc/filesystems`` should also show a filesystem of type "hugetlbfs"
75configured in the kernel.
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Mike Rapoport148723f2018-03-21 21:22:23 +020077``/proc/sys/vm/nr_hugepages`` indicates the current number of "persistent" huge
Lee Schermerhorn267b4c22009-12-14 17:58:30 -080078pages in the kernel's huge page pool. "Persistent" huge pages will be
79returned to the huge page pool when freed by a task. A user with root
80privileges can dynamically allocate more or free some persistent huge pages
Mike Rapoport148723f2018-03-21 21:22:23 +020081by increasing or decreasing the value of ``nr_hugepages``.
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Lee Schermerhorn267b4c22009-12-14 17:58:30 -080083Pages that are used as huge pages are reserved inside the kernel and cannot
84be used for other purposes. Huge pages cannot be swapped out under
85memory pressure.
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Lee Schermerhorn267b4c22009-12-14 17:58:30 -080087Once a number of huge pages have been pre-allocated to the kernel huge page
88pool, a user with appropriate privilege can use either the mmap system call
89or shared memory system calls to use the huge pages. See the discussion of
Mike Rapoportfde79172018-04-18 11:07:44 +030090:ref:`Using Huge Pages <using_huge_pages>`, below.
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Lee Schermerhorn267b4c22009-12-14 17:58:30 -080092The administrator can allocate persistent huge pages on the kernel boot
93command line by specifying the "hugepages=N" parameter, where 'N' = the
94number of huge pages requested. This is the most reliable method of
95allocating huge pages as memory has not yet become fragmented.
Lee Schermerhorn41a25e72009-09-21 17:01:24 -070096
Lee Schermerhorn267b4c22009-12-14 17:58:30 -080097Some platforms support multiple huge page sizes. To allocate huge pages
Lucas De Marchi25985ed2011-03-30 22:57:33 -030098of a specific size, one must precede the huge pages boot command parameters
Lee Schermerhorn41a25e72009-09-21 17:01:24 -070099with a huge page size selection parameter "hugepagesz=<size>". <size> must
100be specified in bytes with optional scale suffix [kKmMgG]. The default huge
101page size may be selected with the "default_hugepagesz=<size>" boot parameter.
102
Mike Rapoport148723f2018-03-21 21:22:23 +0200103When multiple huge page sizes are supported, ``/proc/sys/vm/nr_hugepages``
Lee Schermerhorn267b4c22009-12-14 17:58:30 -0800104indicates the current number of pre-allocated huge pages of the default size.
105Thus, one can use the following command to dynamically allocate/deallocate
Mike Rapoport148723f2018-03-21 21:22:23 +0200106default sized persistent huge pages::
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108 echo 20 > /proc/sys/vm/nr_hugepages
109
Lee Schermerhorn267b4c22009-12-14 17:58:30 -0800110This command will try to adjust the number of default sized huge pages in the
111huge page pool to 20, allocating or freeing huge pages, as required.
112
Lee Schermerhorn41a25e72009-09-21 17:01:24 -0700113On a NUMA platform, the kernel will attempt to distribute the huge page pool
Lee Schermerhorn267b4c22009-12-14 17:58:30 -0800114over all the set of allowed nodes specified by the NUMA memory policy of the
Mike Rapoport148723f2018-03-21 21:22:23 +0200115task that modifies ``nr_hugepages``. The default for the allowed nodes--when the
Lee Schermerhorn9b5e5d02009-12-14 17:58:32 -0800116task has default memory policy--is all on-line nodes with memory. Allowed
117nodes with insufficient available, contiguous memory for a huge page will be
Mike Rapoportfde79172018-04-18 11:07:44 +0300118silently skipped when allocating persistent huge pages. See the
119:ref:`discussion below <mem_policy_and_hp_alloc>`
120of the interaction of task memory policy, cpusets and per node attributes
Lee Schermerhorn9b5e5d02009-12-14 17:58:32 -0800121with the allocation and freeing of persistent huge pages.
Nishanth Aravamudand5dbac82007-12-17 16:20:25 -0800122
Lee Schermerhorn41a25e72009-09-21 17:01:24 -0700123The success or failure of huge page allocation depends on the amount of
Lee Schermerhorn267b4c22009-12-14 17:58:30 -0800124physically contiguous memory that is present in system at the time of the
Lee Schermerhorn41a25e72009-09-21 17:01:24 -0700125allocation attempt. If the kernel is unable to allocate huge pages from
126some nodes in a NUMA system, it will attempt to make up the difference by
127allocating extra pages on other nodes with sufficient available contiguous
128memory, if any.
129
Lee Schermerhorn267b4c22009-12-14 17:58:30 -0800130System administrators may want to put this command in one of the local rc
131init files. This will enable the kernel to allocate huge pages early in
132the boot process when the possibility of getting physical contiguous pages
133is still very high. Administrators can verify the number of huge pages
134actually allocated by checking the sysctl or meminfo. To check the per node
Mike Rapoport148723f2018-03-21 21:22:23 +0200135distribution of huge pages in a NUMA system, use::
Lee Schermerhorn41a25e72009-09-21 17:01:24 -0700136
137 cat /sys/devices/system/node/node*/meminfo | fgrep Huge
138
Mike Rapoport148723f2018-03-21 21:22:23 +0200139``/proc/sys/vm/nr_overcommit_hugepages`` specifies how large the pool of
140huge pages can grow, if more huge pages than ``/proc/sys/vm/nr_hugepages`` are
Lee Schermerhorn41a25e72009-09-21 17:01:24 -0700141requested by applications. Writing any non-zero value into this file
Lee Schermerhorn267b4c22009-12-14 17:58:30 -0800142indicates that the hugetlb subsystem is allowed to try to obtain that
143number of "surplus" huge pages from the kernel's normal page pool, when the
144persistent huge page pool is exhausted. As these surplus huge pages become
145unused, they are freed back to the kernel's normal page pool.
Nishanth Aravamudand5dbac82007-12-17 16:20:25 -0800146
Mike Rapoport148723f2018-03-21 21:22:23 +0200147When increasing the huge page pool size via ``nr_hugepages``, any existing
148surplus pages will first be promoted to persistent huge pages. Then, additional
Lee Schermerhorn41a25e72009-09-21 17:01:24 -0700149huge pages will be allocated, if necessary and if possible, to fulfill
Lee Schermerhorn267b4c22009-12-14 17:58:30 -0800150the new persistent huge page pool size.
Lee Schermerhorn41a25e72009-09-21 17:01:24 -0700151
Lee Schermerhorn267b4c22009-12-14 17:58:30 -0800152The administrator may shrink the pool of persistent huge pages for
Mike Rapoport148723f2018-03-21 21:22:23 +0200153the default huge page size by setting the ``nr_hugepages`` sysctl to a
Lee Schermerhorn41a25e72009-09-21 17:01:24 -0700154smaller value. The kernel will attempt to balance the freeing of huge pages
Mike Rapoport148723f2018-03-21 21:22:23 +0200155across all nodes in the memory policy of the task modifying ``nr_hugepages``.
Lee Schermerhorn267b4c22009-12-14 17:58:30 -0800156Any free huge pages on the selected nodes will be freed back to the kernel's
157normal page pool.
Lee Schermerhorn41a25e72009-09-21 17:01:24 -0700158
Mike Rapoport148723f2018-03-21 21:22:23 +0200159Caveat: Shrinking the persistent huge page pool via ``nr_hugepages`` such that
Lee Schermerhorn267b4c22009-12-14 17:58:30 -0800160it becomes less than the number of huge pages in use will convert the balance
161of the in-use huge pages to surplus huge pages. This will occur even if
Mike Rapoportfde79172018-04-18 11:07:44 +0300162the number of surplus pages would exceed the overcommit value. As long as
Mike Rapoport148723f2018-03-21 21:22:23 +0200163this condition holds--that is, until ``nr_hugepages+nr_overcommit_hugepages`` is
Lee Schermerhorn267b4c22009-12-14 17:58:30 -0800164increased sufficiently, or the surplus huge pages go out of use and are freed--
165no more surplus huge pages will be allowed to be allocated.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Lee Schermerhorn41a25e72009-09-21 17:01:24 -0700167With support for multiple huge page pools at run-time available, much of
Mike Rapoport148723f2018-03-21 21:22:23 +0200168the huge page userspace interface in ``/proc/sys/vm`` has been duplicated in
169sysfs.
170The ``/proc`` interfaces discussed above have been retained for backwards
171compatibility. The root huge page control directory in sysfs is::
Nishanth Aravamudana3437872008-07-23 21:27:44 -0700172
173 /sys/kernel/mm/hugepages
174
Lee Schermerhorn41a25e72009-09-21 17:01:24 -0700175For each huge page size supported by the running kernel, a subdirectory
Mike Rapoport148723f2018-03-21 21:22:23 +0200176will exist, of the form::
Nishanth Aravamudana3437872008-07-23 21:27:44 -0700177
178 hugepages-${size}kB
179
Mike Rapoport148723f2018-03-21 21:22:23 +0200180Inside each of these directories, the same set of files will exist::
Nishanth Aravamudana3437872008-07-23 21:27:44 -0700181
182 nr_hugepages
Lee Schermerhorn267b4c22009-12-14 17:58:30 -0800183 nr_hugepages_mempolicy
Nishanth Aravamudana3437872008-07-23 21:27:44 -0700184 nr_overcommit_hugepages
185 free_hugepages
186 resv_hugepages
187 surplus_hugepages
188
Lee Schermerhorn41a25e72009-09-21 17:01:24 -0700189which function as described above for the default huge page-sized case.
Nishanth Aravamudana3437872008-07-23 21:27:44 -0700190
Mike Rapoportfde79172018-04-18 11:07:44 +0300191.. _mem_policy_and_hp_alloc:
Lee Schermerhorn267b4c22009-12-14 17:58:30 -0800192
193Interaction of Task Memory Policy with Huge Page Allocation/Freeing
Davidlohr Bueso15610c82013-09-11 14:21:48 -0700194===================================================================
Lee Schermerhorn267b4c22009-12-14 17:58:30 -0800195
Mike Rapoport148723f2018-03-21 21:22:23 +0200196Whether huge pages are allocated and freed via the ``/proc`` interface or
197the ``/sysfs`` interface using the ``nr_hugepages_mempolicy`` attribute, the
198NUMA nodes from which huge pages are allocated or freed are controlled by the
199NUMA memory policy of the task that modifies the ``nr_hugepages_mempolicy``
200sysctl or attribute. When the ``nr_hugepages`` attribute is used, mempolicy
Lee Schermerhorn267b4c22009-12-14 17:58:30 -0800201is ignored.
202
203The recommended method to allocate or free huge pages to/from the kernel
Mike Rapoport148723f2018-03-21 21:22:23 +0200204huge page pool, using the ``nr_hugepages`` example above, is::
Lee Schermerhorn267b4c22009-12-14 17:58:30 -0800205
206 numactl --interleave <node-list> echo 20 \
207 >/proc/sys/vm/nr_hugepages_mempolicy
208
Mike Rapoport148723f2018-03-21 21:22:23 +0200209or, more succinctly::
Lee Schermerhorn267b4c22009-12-14 17:58:30 -0800210
211 numactl -m <node-list> echo 20 >/proc/sys/vm/nr_hugepages_mempolicy
212
Mike Rapoport148723f2018-03-21 21:22:23 +0200213This will allocate or free ``abs(20 - nr_hugepages)`` to or from the nodes
Lee Schermerhorn267b4c22009-12-14 17:58:30 -0800214specified in <node-list>, depending on whether number of persistent huge pages
215is initially less than or greater than 20, respectively. No huge pages will be
216allocated nor freed on any node not included in the specified <node-list>.
217
Mike Rapoport148723f2018-03-21 21:22:23 +0200218When adjusting the persistent hugepage count via ``nr_hugepages_mempolicy``, any
Lee Schermerhorn267b4c22009-12-14 17:58:30 -0800219memory policy mode--bind, preferred, local or interleave--may be used. The
220resulting effect on persistent huge page allocation is as follows:
221
Mike Rapoporte27a20f2018-04-18 11:07:50 +0300222#. Regardless of mempolicy mode [see
Mike Rapoport3ecf53e2018-05-08 10:02:10 +0300223 :ref:`Documentation/admin-guide/mm/numa_memory_policy.rst <numa_memory_policy>`],
Lee Schermerhorn267b4c22009-12-14 17:58:30 -0800224 persistent huge pages will be distributed across the node or nodes
225 specified in the mempolicy as if "interleave" had been specified.
226 However, if a node in the policy does not contain sufficient contiguous
227 memory for a huge page, the allocation will not "fallback" to the nearest
228 neighbor node with sufficient contiguous memory. To do this would cause
229 undesirable imbalance in the distribution of the huge page pool, or
230 possibly, allocation of persistent huge pages on nodes not allowed by
231 the task's memory policy.
232
Mike Rapoport148723f2018-03-21 21:22:23 +0200233#. One or more nodes may be specified with the bind or interleave policy.
Lee Schermerhorn267b4c22009-12-14 17:58:30 -0800234 If more than one node is specified with the preferred policy, only the
235 lowest numeric id will be used. Local policy will select the node where
236 the task is running at the time the nodes_allowed mask is constructed.
237 For local policy to be deterministic, the task must be bound to a cpu or
238 cpus in a single node. Otherwise, the task could be migrated to some
239 other node at any time after launch and the resulting node will be
240 indeterminate. Thus, local policy is not very useful for this purpose.
241 Any of the other mempolicy modes may be used to specify a single node.
242
Mike Rapoport148723f2018-03-21 21:22:23 +0200243#. The nodes allowed mask will be derived from any non-default task mempolicy,
Lee Schermerhorn267b4c22009-12-14 17:58:30 -0800244 whether this policy was set explicitly by the task itself or one of its
245 ancestors, such as numactl. This means that if the task is invoked from a
246 shell with non-default policy, that policy will be used. One can specify a
247 node list of "all" with numactl --interleave or --membind [-m] to achieve
248 interleaving over all nodes in the system or cpuset.
249
Mike Rapoport148723f2018-03-21 21:22:23 +0200250#. Any task mempolicy specified--e.g., using numactl--will be constrained by
Lee Schermerhorn267b4c22009-12-14 17:58:30 -0800251 the resource limits of any cpuset in which the task runs. Thus, there will
252 be no way for a task with non-default policy running in a cpuset with a
253 subset of the system nodes to allocate huge pages outside the cpuset
254 without first moving to a cpuset that contains all of the desired nodes.
255
Mike Rapoport148723f2018-03-21 21:22:23 +0200256#. Boot-time huge page allocation attempts to distribute the requested number
Lee Schermerhorn9b5e5d02009-12-14 17:58:32 -0800257 of huge pages over all on-lines nodes with memory.
Lee Schermerhorn267b4c22009-12-14 17:58:30 -0800258
259Per Node Hugepages Attributes
Davidlohr Bueso15610c82013-09-11 14:21:48 -0700260=============================
Lee Schermerhorn267b4c22009-12-14 17:58:30 -0800261
262A subset of the contents of the root huge page control directory in sysfs,
Lee Schermerhorn4faf8d92009-12-14 17:58:35 -0800263described above, will be replicated under each the system device of each
Mike Rapoport148723f2018-03-21 21:22:23 +0200264NUMA node with memory in::
Lee Schermerhorn267b4c22009-12-14 17:58:30 -0800265
266 /sys/devices/system/node/node[0-9]*/hugepages/
267
268Under this directory, the subdirectory for each supported huge page size
Mike Rapoport148723f2018-03-21 21:22:23 +0200269contains the following attribute files::
Lee Schermerhorn267b4c22009-12-14 17:58:30 -0800270
271 nr_hugepages
272 free_hugepages
273 surplus_hugepages
274
Mike Rapoport148723f2018-03-21 21:22:23 +0200275The free\_' and surplus\_' attribute files are read-only. They return the number
Lee Schermerhorn267b4c22009-12-14 17:58:30 -0800276of free and surplus [overcommitted] huge pages, respectively, on the parent
277node.
278
Mike Rapoport148723f2018-03-21 21:22:23 +0200279The ``nr_hugepages`` attribute returns the total number of huge pages on the
Lee Schermerhorn267b4c22009-12-14 17:58:30 -0800280specified node. When this attribute is written, the number of persistent huge
281pages on the parent node will be adjusted to the specified value, if sufficient
282resources exist, regardless of the task's mempolicy or cpuset constraints.
283
284Note that the number of overcommit and reserve pages remain global quantities,
285as we don't know until fault time, when the faulting task's mempolicy is
286applied, from which node the huge page allocation will be attempted.
287
Mike Rapoportfde79172018-04-18 11:07:44 +0300288.. _using_huge_pages:
Lee Schermerhorn267b4c22009-12-14 17:58:30 -0800289
290Using Huge Pages
Davidlohr Bueso15610c82013-09-11 14:21:48 -0700291================
Lee Schermerhorn267b4c22009-12-14 17:58:30 -0800292
Lee Schermerhorn41a25e72009-09-21 17:01:24 -0700293If the user applications are going to request huge pages using mmap system
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294call, then it is required that system administrator mount a file system of
Mike Rapoport148723f2018-03-21 21:22:23 +0200295type hugetlbfs::
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
Randy Dunlape73a75f2007-07-15 23:40:52 -0700297 mount -t hugetlbfs \
Mike Kravetz8c9b9702015-04-15 16:13:45 -0700298 -o uid=<value>,gid=<value>,mode=<value>,pagesize=<value>,size=<value>,\
299 min_size=<value>,nr_inodes=<value> none /mnt/huge
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
301This command mounts a (pseudo) filesystem of type hugetlbfs on the directory
Mike Rapoportfde79172018-04-18 11:07:44 +0300302``/mnt/huge``. Any file created on ``/mnt/huge`` uses huge pages.
Mike Rapoport148723f2018-03-21 21:22:23 +0200303
304The ``uid`` and ``gid`` options sets the owner and group of the root of the
305file system. By default the ``uid`` and ``gid`` of the current process
306are taken.
307
308The ``mode`` option sets the mode of root of file system to value & 01777.
309This value is given in octal. By default the value 0755 is picked.
310
311If the platform supports multiple huge page sizes, the ``pagesize`` option can
312be used to specify the huge page size and associated pool. ``pagesize``
313is specified in bytes. If ``pagesize`` is not specified the platform's
314default huge page size and associated pool will be used.
315
316The ``size`` option sets the maximum value of memory (huge pages) allowed
317for that filesystem (``/mnt/huge``). The ``size`` option can be specified
318in bytes, or as a percentage of the specified huge page pool (``nr_hugepages``).
319The size is rounded down to HPAGE_SIZE boundary.
320
321The ``min_size`` option sets the minimum value of memory (huge pages) allowed
322for the filesystem. ``min_size`` can be specified in the same way as ``size``,
323either bytes or a percentage of the huge page pool.
324At mount time, the number of huge pages specified by ``min_size`` are reserved
325for use by the filesystem.
326If there are not enough free huge pages available, the mount will fail.
327As huge pages are allocated to the filesystem and freed, the reserve count
328is adjusted so that the sum of allocated and reserved huge pages is always
329at least ``min_size``.
330
331The option ``nr_inodes`` sets the maximum number of inodes that ``/mnt/huge``
332can use.
333
334If the ``size``, ``min_size`` or ``nr_inodes`` option is not provided on
335command line then no limits are set.
336
337For ``pagesize``, ``size``, ``min_size`` and ``nr_inodes`` options, you can
338use [G|g]/[M|m]/[K|k] to represent giga/mega/kilo.
339For example, size=2K has the same meaning as size=2048.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
Nishanth Aravamudand5dbac82007-12-17 16:20:25 -0800341While read system calls are supported on files that reside on hugetlb
342file systems, write system calls are not.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
Randy Dunlap21a26d42006-04-10 22:53:04 -0700344Regular chown, chgrp, and chmod commands (with right permissions) could be
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345used to change the file attributes on hugetlbfs.
346
David Rientjes80d6b942015-04-15 16:14:26 -0700347Also, it is important to note that no such mount command is required if
Eric B Munson94bf5ce2009-09-21 17:03:48 -0700348applications are going to use only shmat/shmget system calls or mmap with
Mike Rapoport148723f2018-03-21 21:22:23 +0200349MAP_HUGETLB. For an example of how to use mmap with MAP_HUGETLB see
350:ref:`map_hugetlb <map_hugetlb>` below.
David Rientjes80d6b942015-04-15 16:14:26 -0700351
Mike Rapoportfde79172018-04-18 11:07:44 +0300352Users who wish to use hugetlb memory via shared memory segment should be
353members of a supplementary group and system admin needs to configure that gid
Mike Rapoport148723f2018-03-21 21:22:23 +0200354into ``/proc/sys/vm/hugetlb_shm_group``. It is possible for same or different
David Rientjes80d6b942015-04-15 16:14:26 -0700355applications to use any combination of mmaps and shm* calls, though the mount of
356filesystem will be required for using mmap calls without MAP_HUGETLB.
357
358Syscalls that operate on memory backed by hugetlb pages only have their lengths
359aligned to the native page size of the processor; they will normally fail with
360errno set to EINVAL or exclude hugetlb pages that extend beyond the length if
361not hugepage aligned. For example, munmap(2) will fail if memory is backed by
362a hugetlb page and the length is smaller than the hugepage size.
363
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
Davidlohr Bueso15610c82013-09-11 14:21:48 -0700365Examples
366========
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
Mike Rapoport148723f2018-03-21 21:22:23 +0200368.. _map_hugetlb:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Mike Rapoport148723f2018-03-21 21:22:23 +0200370``map_hugetlb``
371 see tools/testing/selftests/vm/map_hugetlb.c
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
Mike Rapoport148723f2018-03-21 21:22:23 +0200373``hugepage-shm``
374 see tools/testing/selftests/vm/hugepage-shm.c
Zhouping Liud46f3d82012-08-21 16:15:57 -0700375
Mike Rapoport148723f2018-03-21 21:22:23 +0200376``hugepage-mmap``
377 see tools/testing/selftests/vm/hugepage-mmap.c
378
379The `libhugetlbfs`_ library provides a wide range of userspace tools
380to help with huge page usability, environment setup, and control.
381
382.. _libhugetlbfs: https://github.com/libhugetlbfs/libhugetlbfs