title: Why does calling mmap() with large size not fail?
body: <p>I try to use <code>mmap()</code> to manipulate virtual memory. I want to reserve and commit a region of memory. I tested this code:</p>
  
  <pre><code>const unsigned long gygabyte = 1024 * 1024 * 1024;
  const unsigned long gygabyteCount = 2;
  const unsigned long maxCapacity = gygabyteCount * gygabyte;
  
  int main()
  {
      char* pMemory;
  
      pMemory = (char*)mmap(NULL, maxCapacity, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
      if ( mprotect(pMemory, maxCapacity, PROT_READ | PROT_WRITE) != 0 )
      {
          cout &lt;&lt; "Memory Allocation has failed" &lt;&lt; endl;
      }
      usleep(-1);
  
      return 0;
  }
  </code></pre>
  
  <p>I ran several copies of my program (say 6) from a terminal. I didn't ever see "Memory Allocation has failed" in any one. I'm running on 64-bit Ubuntu with 4GB RAM. Can anyone tell me something about this?</p>