I want to allocate memory on the hugepages being used by a Linux machine. I see that there are two ways to do this, using mmap and madvise.
That is, using the MAP_HUGETLB flag with the mmap call -
base_ptr_ = mmap(NULL, memory_size_, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0);
And the MADV_HUGEPAGE flag with the madvise call -
madvise(base_ptr_, memory_size_, MADV_HUGEPAGE);
Could someone explain the difference between the two?