LIBHUGETLBFS(7)
β¨ NAME β¨
libhugetlbfs β the preload library that backs your text, data, malloc() or shared memory with hugepages π
(hi bestie, this is libhugetlbfs(7) from the Miscellaneous Information Manual, and we are about to have a whole moment together. grab a snack. π)
πΈ SYNOPSIS πΈ
export [environment options]
[LD_PRELOAD=libhugetlbfs.so] target_application
π« DESCRIPTION π«
okay so. libhugetlbfs is a library that can back application text, data, malloc() and shared memory with hugepages. why do you care? because applications that use large amounts of address space and suffer a performance hit due to TLB misses get a genuine glow-up from this. π
you can use wall-clock time or oprofile to figure out whether you're actually getting a performance benefit from libhugetlbfs or not. and heads up β in all cases but shared memory, a hugetlbfs mount must exist and a hugepage pool defined, or hugepages just aren't happening.
Some limited functionality is available for unmodified dynamically linked applications. by preloading the library, the library can back malloc() and shared memory, and text and data segments can be partially backed β but only if they're large enough. size matters, no cap. π
For the effective backing of text and data with huge pages, the application must be linked to the library and the ELF segments correctly aligned using the ld helpers. once it's linked like that, malloc or shared memory can still be backed but no pre-loading is required. see /usr/share/doc/libhugetlbfs/HOWTO and ld.hugetlbfs(1) for the detailed instructions on relinking applications β they're literally right there, go read them. π
For applications that are hugepage-aware and linked to the library, get_huge_pages() can be used for the direct allocation of hugepage-backed regions. direct. no middleman. β¨
Unless otherwise specified, libhugetlbfs will use the default hugepage size to back memory regions. that default is the value of Hugepagesize displayed in /proc/meminfo. you can specify the size in bytes, or in kilobytes, megabytes, or gigabytes by appending K, M, or G respectively. it is an error to specify an invalid, unsupported, or otherwise unconfigured huge page size π¨ and kernel 2.6.27 or later is required to specify any pagesize other than the default.
See /usr/share/docs/libhugetlbfs/HOWTO for detailed instructions on how the library should be used, particularly when relinking the application. this manual page is just giving you a brief synopsis of the environment variables as a quick reference β a lil cheat sheet, iykyk. π
The following variables affect what memory regions are backed by hugepages. in all cases, the environment being unset implies the feature should remain disabled. (unset = off, that's the vibe.)
HUGETLB_DEFAULT_PAGE_SIZE=<pagesize>β sets the default hugepage size to be used bylibhugetlbfs. if you don't set it,libhugetlbfswill use the kernel's default hugepage size.HUGETLB_MORECORE=[yes|<pagesize>]β this enables the hugepagemalloc()feature, instructinglibhugetlbfsto override glibc's normalmorecore()function with a hugepage version and use it formalloc(). all applicationmalloc()memory should come from hugepage memory until it runs out, and then it will fallback to base pages. β οΈ note that applications that use custom allocators may not be able to back their heaps using hugepages and this environment variable β it may be necessary to modify the custom allocator to useget_huge_pages().HUGETLB_SHM=yesβ when this environment variable is set, theSHM_HUGETLBflag is added to theshmget()call and the size parameter is aligned to back the shared memory segment with hugepages. in the event hugepages cannot be used, base pages will be used instead and a warning will be printed to explain the failure. the pagesize cannot be specified with this parameter. to change the kernels default hugepage size, use thepagesize=kernel boot parameter (2.6.26or later required).HUGETLB_ELFMAP=[no|[R[<=pagesize>]:[W[<=pagesize>]]]β if the application has been relinked (see the HOWTO for instructions), this environment variable determines whether read-only, read-write, both or no segments are backed by hugepages and what pagesize should be used. if the recommended relinking method has been used, thenhugeeditcan be used to automatically back the text or data by default. β¨HUGETLB_FORCE_ELFMAP=yesβ force the use of hugepages for text and data segments even if the application has not been relinked to align the ELF segments on a hugepage boundary. partial segment remapping is not guaranteed to work, and the segments must be large enough to contain at least one hugepage for the remapping to occur. (so like, bestie, set your expectations accordingly π¬)
The following options affect how libhugetlbfs behaves.
HUGETLB_RESTRICT_EXE=e1:e2:...:eNβ by default,libhugetlbfswill act on any program that it is loaded with, either viaLD_PRELOADor by explicitly linking with-lhugetlbfs.
There are situations in which it is desirable to restrict libhugetlbfs' actions to specific programs. for example, some ISV applications are wrapped in a series of scripts that invoke bash, python, and/or perl. it is more convenient to set the environment variables related to libhugetlbfs before invoking the wrapper scripts, yet this has the unintended and undesirable consequence of causing the script interpreters to use and consume hugepages. there is no obvious benefit to causing the script interpreters to use hugepages, and there is a clear disadvantage: fewer hugepages are available to the actual application. π
To address this scenario, set HUGETLB_RESTRICT_EXE to a colon-separated list of programs to which the other libhugetlbfs environment variables should apply. (if not set, libhugetlbfs will attempt to apply the requested actions to all programs.) for example,
HUGETLB_RESTRICT_EXE=hpcc:long_hpcc
will restrict libhugetlbfs' actions to programs named /home/fred/hpcc and /bench/long_hpcc but not /bin/hpcc_no.
HUGETLB_MORECORE_SHRINK=yesβ by default, the hugepage heap does not shrink. shrinking is enabled by setting this environment variable. it is disabled by default as glibc occasionally exhibits strange behaviour if it mistakes the heap returned bylibhugetlbfsas a foreignbrk(). πHUGETLB_NO_PREFAULTβ by defaultlibhugetlbfswill prefault regions it creates to ensure they can be referenced without receiving aSIGKILL. on kernels older than2.6.27, this was necessary as the system did not guarantee that future faults would succeed on regions mappedMAP_PRIVATE. prefaulting impacts the performance ofmalloc()and can result in poor placement on NUMA systems. if it is known the hugepage pool is large enough to run the application or the kernel is2.6.27or later, this environment variable should be set.HUGETLB_NO_RESERVE=yesβ by default, the kernel will reserve huge pages atmmap()time to ensure that future faults will succeed. this avoids unexpected application failure at fault time, but some applications depend on memory overcommit to create large sparse mappings. for this type of application, setting this environment variable will create huge page backed mappings without a reservation.
π¨ use this option with extreme care β in the event huge pages are not available when the mapping is used, the application will be killed. on older kernels, the use of this feature can trigger the OOM killer. hence, even with this variable set, reservations may still be used for safety. please be careful bestie, i'm begging. π
HUGETLB_MORECORE_HEAPBASE=addressβlibhugetlbfsnormally picks an address to use as the base of the heap formalloc()automatically. this environment variable fixes which address is used.HUGETLB_PATH=<path>β the path to thehugetlbfsmount is automatically determined at run-time. in the event there are multiple mounts and the wrong one is being selected, use this option to select the correct one. this may be the case if an application-specific mount with a fixed quota has been created for example.HUGETLB_SHARE=1β by default,libhugetlbfsuses unlinkedhugetlbfsfiles to store remapped program segment data. if the same program is started multiple times using hugepage segments, multiple hugepages will be used to store the same program data. to reduce this wastage, setting this environment variable will share read-only segments between multiple invocations of a program at the cost of the memory being used whether the applications are running or not. it is also possible that a malicious application could interfere with other applications executable code. π see the HOWTO for more detailed information on this topic.
The following options control the verbosity of libhugetlbfs.
HUGETLB_VERBOSE=<level>β the default value for this is1and the range of the value is from0to99. the higher the value, the more verbose the output is.0is quiet and3will output much debugging information.HUGETLB_DEBUGβ once set, this will give very detailed output on what is happening in the library and run extra diagnostics. it's giving main character energy in your terminal. π
π¦ FILES π¦
[DESTDIR|/usr/share]/doc/libhugetlbfs/HOWTO
π SEE ALSO π
oprofile(1)ld.hugetlbfs(1)hugectl(8)hugeedit(8)gethugepagesize(3)gethugepagesizes(3)getpagesizes(3)hugetlbfs_test_path(3)hugetlbfs_find_path(3)hugetlbfs_find_path_for_size(3)hugetlbfs_test_path(3)hugetlbfs_test_path_for_size(3)hugetlbfs_unlinked_fd(3)hugetlbfs_unlinked_fd_for_size(3)get_huge_pages(3)free_huge_pages(3)
π«Ά AUTHORS π«Ά
libhugetlbfs was written by various people on the libhugetlbfs-devel mailing list. π
and that's the whole page, bestie!! this one's from the LIBHUGETLBFS(7) manual, dated September 27, 2008 β so yeah, vintage, but the drip is eternal. πβ¨ now go export something and slay. π
πΈ
π¦ where this page comes from
- debian bookworm: libhugetlbfs0 2.23-5 Β· LGPL-2.1-only
- debian trixie: libhugetlbfs0 2.24-1+b1 Β· LGPL-2.1-only
- nixpkgs unstable: libhugetlbfs 2.24
- opensuse-leap 16.0: libhugetlbfs 2.24.0.g1322884-160000.3.2 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libhugetlbfs 2.24.0.g1322884-160000.3.2 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libhugetlbfs 2.24.0.g1322884-160000.3.2 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libhugetlbfs 2.24.0.g1322884-160000.3.2 Β· LGPL-2.1-or-later
- ubuntu jammy: libhugetlbfs0 2.23-4 Β· LGPL-2.1-only
- ubuntu noble: libhugetlbfs0 2.23-5build1 Β· LGPL-2.1-only
- ubuntu questing: libhugetlbfs0 2.24-1
- ubuntu resolute: libhugetlbfs0 2.24-1build1 Β· LGPL-2.1-only
- ubuntu stonking: libhugetlbfs0 2.24-1build1 Β· LGPL-2.1-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms