title: Is there a limit on memory allocated using huge pages?
body: <p>I am allocating memory using "huge pages(1MB size)" and using mmap. After allocating 4 GB of memory ,mmap returns fail. </p>
  
  <pre><code>mmap(NULL, memsize, PROT_READ | PROT_WRITE,MAP_PRIVATE | MAP_ANONYMOUS |MAP_POPULATE | MAP_HUGETLB, -1, 0);
  </code></pre>
  
  <p>here memsize = 1GB</p>
  
  <p>I am calling above statement in a loop. Upto 4 iterations it is fine. In 5th iteration mmap is failed. </p>
  
  <pre><code>mmap(NULL, memsize, PROT_READ | PROT_WRITE,MAP_PRIVATE | MAP_ANONYMOUS |MAP_POPULATE , -1, 0);
  </code></pre>
  
  <p>Above statement (without hugepages) works perfectly for any number of iterations. Am I missing any information related to hugepages?
  I tried "MAP_NORESERVE" flag also as mentioned in <a href="https://stackoverflow.com/questions/4803152/mmap-fails-when-length-is-larger-than-4gb">mmap fail after 4GB</a>. </p>
  
  <p>Any sort of information will be greatly appreciated. Thank you.</p>