I'm working on a program which needs to detect at runtime whether the system it's running on supports hugepages, and if so, what sizes are available. Ideally I'd like this to work for any POSIX platform, but a Linux-specific solution would be a start.

POSIX supports sysconf(_SC_PAGESIZE) to get the default page size on the platform, but doesn't seem to similarly support asking for any hugepage sizes. I could also potentially check by trying to mmap MAP_HUGE_2MB or MAP_HUGE_1GB arguments, but that would be slow, and in the case of 1GB huge pages, incredibly wasteful (and it could easily fail due to a lack of available memory).

  • 1
    Maybe Linux only, but madvise has MADV_HUGEPAGE that may help. It also has the file path /sys/kernel/mm/transparent_hugepage/ that gives information. This article may also help you: access.redhat.com/solutions/46111 – Patrick Mevzek May 12 '17 at 20:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.