c++g++centos7mmaphuge-pages

MAP_HUGE_1GB and MAP_HUGE_2MB missing?


I am on CentOS 7 with kernel version 3.10.0-1160.15.2.el7.x86_64.

When I tried to use MAP_HUGE_1GB and MAP_HUGE_2MB flags, g++-9.3.1 complained:

error: ‘MAP_HUGE_1GB’ was not declared in this scope; did you mean ‘MAP_HUGETLB’?

Then, I found this post, the answer suggested that I need to "#define _GNU_SOURCE before #include <sys/mman.h> because this is a nonstandard flag".

However, defining _GNU_SOURCE causes warning: "_GNU_SOURCE" redefined but g++ still complains those 2 flags aren't declared.

Then, I found this post, and it suggests that _GNU_SOURCE defined as libstdc++ is used.

Now, I am confused how to use MAP_HUGE_1GB and MAP_HUGE_2MB flags.

Thanks!


Solution

  • Glibc didn't define either MAP_HUGE_1GB or MAP_HUGE_2MB in any of its headers until version 2.40 (specifically, commit 176671f60429 ("linux: add definitions for hugetlb page size encodings")), and CentOS 7 only has version 2.17 of glibc. Since CentOS 7 is EOL anyway, your best option is to upgrade to a newer distro with a new enough version of glibc. Failing that, if you have the kernel-headers package installed, you can get those constants by doing #include <linux/mman.h>.