On Linux, there are two basic ways of creating a region of memory backed by huge pages. The first is to use shmget() with the SHM_HUGETLB flag set but this can leak memory if the application fails to clean up memory properly. The second is to mmap() a file created on a hugetlbfs mount but this requires a lot of boring boilerplate code. Things are more painful than they should be and this lead to whinging.
As the necessary code existed in libhugetlbfs to discover the mount and create a file, two APIs were created called get_huge_pages() for use when implementing custom allocators and get_hugepage_regions() when used as drop-in replacement for malloc() of large buffers. These are available and documented with manual pages in
libhugetlbfs 2.1-pre5 with a final release expected in the near future.
I put together this
document describing how to alter STREAM to use malloc with small pages, malloc with large pages and the two direct hugepage allocation APIs now supported in libhugetlbfs. It should make life easier for anyone writing a hugepage-aware application that cannot use the automatic support in libhugetlbfs for whatever reason.