title: Cassandra generates “java.lang.OutOfMemoryError: Java heap space” error on startup
body: <p>I upgraded my system from 13.04 to 13.10 and I could not start Cassandra anymore, getting an out of memory error, so the heap was getting full even though all I was doing at that point was start the server.</p>
  
  <p>I went in and increased the maximum heap size with -Xmx1992m (the default) to -Xms2500m.</p>
  
  <p>I am wondering why would it be required to do such a thing? Could it be that the memory decreased a little bit between running Linux kernel 3.5.0 and moving to kernel 3.11.0 and could that impact Cassandra? (i.e. say I "lost" 200M, now it was allocating 1992Mb instead of 2192Mb with the previous kernel, could that be??)</p>
  
  <p>My concern here is that any time I upgrade I could run in a problem like this unless I force the maximum heap size to a fixed number (instead of letting the script determine the Mb to use dynamically.) Plus, I just cannot continue to increase the limit forever. My RAM is limited... (obviously.)</p>
  
  <p>On startup Cassandra shows the following (broken on 3 lines to make it easier to read here):</p>
  
  <pre><code>xss =  -ea -javaagent:bin/../lib/jamm-0.2.5.jar -XX:+UseThreadPriorities
         -XX:ThreadPriorityPolicy=42 -Xms1994M -Xmx2500M -Xmn400M
         -XX:+HeapDumpOnOutOfMemoryError -Xss256k
  </code></pre>
  
  <hr>
  
  <p>Update:</p>
  
  <p>Argh! It was still starting OpenVMS because the $JAVA_HOME variable that points to /usr/lib/jvm/default-java (it is defined in /etc/environment):</p>
  
  <pre><code>JAVA_HOME=/usr/lib/jvm/default-java
  </code></pre>
  
  <p>And somehow it was setup back to OpenVMS in there. Although I changed the /etc/alternatives/java softlink, and thus <code>java -version</code> in my command line was "working fine" (returning what I'd expect) the Cassandra startup script makes use of the <code>$JAVA_HOME</code> variable!</p>
  
  <p>So I checked the list of available VMs with:</p>
  
  <pre><code>ls -l /usr/lib/jvm
  
  lrwxrwxrwx 1 root root   24 Apr 27  2012 default-java -&gt; java-1.7.0-openjdk-amd64
  drwxr-xr-x 4 root root 4096 Feb 23 17:54 java-1.5.0-gcj-4.8-amd64
  lrwxrwxrwx 1 root root   20 Sep  2  2012 java-1.6.0-openjdk-amd64 -&gt; java-6-openjdk-amd64
  lrwxrwxrwx 1 root root   20 Jul  3  2013 java-1.7.0-openjdk-amd64 -&gt; java-7-openjdk-amd64
  drwxr-xr-x 5 root root 4096 Oct  7  2012 java-6-openjdk-amd64
  drwxr-xr-x 3 root root 4096 Oct  7  2012 java-6-openjdk-common
  drwxr-xr-x 5 root root 4096 Sep 21 20:06 java-7-openjdk-amd64
  drwxr-xr-x 8 root root 4096 Sep 18 21:18 java-7-oracle
  </code></pre>
  
  <p>And ran the following two commands to get Oracle to run:</p>
  
  <pre><code>sudo rm /usr/lib/jvm/default-java
  sudo ln -s java-7-oracle /usr/lib/jvm/default-java
  </code></pre>
  
  <p>However, that did <strong>not</strong> change the fact that I still need to have a large upper limit in terms of memory.</p>