1

I want to test huge memory page allocation on Linux. Just to have another method up in the sleeve. But my test simply fails to compile.

pa = mmap(0, 1024*1024*2, PROT_READ, MAP_PRIVATE|MAP_HUGETLB, -1, 0)

Produces:

error: use of undeclared identifier 'MAP_HUGETLB'

Ideally I wish to mmap a file. But anonimous memory will also do.

The output from hugeadm --pool-list:

  Size      Minimum  Current  Maximum  Default
2097152     1024     1024     1024        *
1073741824  0        0        0

The question is, how could I allocate memory, backed by huge pages?

user14063792468
  • 839
  • 12
  • 28

1 Answers1

2

You have to #define _GNU_SOURCE before #include <sys/mman.h> because this is a nonstandard flag.

S.S. Anne
  • 15,171
  • 8
  • 38
  • 76
  • 1
    Thank you, this explains it all. By the way.. Can you farther advice me? Ideally I would like to `mmap` a file. And as of today, my system do not allow me to `mmap` with both `fd` and `MAP_HUGETLB` flags. Any way to read a file with hugepages? Just to test and forget about it, I know there will be not much, if any, gains. – user14063792468 Dec 31 '19 at 00:04
  • @ЯрославМашко Here's some relevant documentation: https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt (it seems as if you have to have a filesystem mounted with hugepages to be able to use `MAP_HUGETLB`) – S.S. Anne Dec 31 '19 at 00:08