title: Using mmap and madvise for huge pages
body: <p>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 <code>mmap</code> and <code>madvise</code>. </p>
  
  <p>That is, using the <code>MAP_HUGETLB</code> flag with the <code>mmap</code> call -</p>
  
  <pre><code>base_ptr_ = mmap(NULL, memory_size_, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0);
  </code></pre>
  
  <p>And the <code>MADV_HUGEPAGE</code> flag with the <code>madvise</code> call - </p>
  
  <pre><code>madvise(base_ptr_, memory_size_, MADV_HUGEPAGE);
  </code></pre>
  
  <p>Could someone explain the difference between the two?</p>