title: Java: what determines the maximum max heap size possible in a linux machine
body: <p>I have two linux machines (both are VMs), one having 12GB memory and other having 8GB memory.</p>
  
  <p>I tried to start the same java program on both machines, with maximum max heap size possible (using -Xmx flag). Following are the results I got.</p>
  
  <ul>
  <li>12GB machine: 9460MB</li>
  <li>8GB machine: 4790MB</li>
  </ul>
  
  <p>If I specify a max heap size beyond above limits, I get below error.</p>
  
  <pre><code>Error occurred during initialization of VM
  Could not allocate metaspace: 1073741824 bytes
  </code></pre>
  
  <p>I checked the free memory in two systems (using <code>free</code> command), and I got following.</p>
  
  <ul>
  <li>12GB machine: approximately 3GB free.</li>
  <li>8GB machine: approximately 4GB free.</li>
  </ul>
  
  <p>My question is, what determines the maximum max heap size a java program can be started with, which would not result in above mentioned error? (System had sufficient memory to allocate <code>1073741824</code> bytes of memory when the program gave above error)</p>