title: Memory allocation in Tomcat
body: <p>Following advice, I've just added the following line to the catalina.bat file in my installation of tomcat 6.0.26:</p>
  <blockquote>
  <p>set JAVA_OPTS=%JAVA_OPTS% -Xms128m -Xmx512m -XX:MaxPermSize=128m</p>
  </blockquote>
  <p>I know that settings:</p>
  <blockquote>
  <p>Xms128m -Xmx512m</p>
  </blockquote>
  <p>Control the initial heap size and what it can exppand to. But what exactly is:</p>
  <p>-XX:MaxPermSize=128m</p>
  <p>Word from Tomcat themselves:</p>
  <blockquote>
  <p>Following advice found elsewhere on the internet</p>
  </blockquote>
  <p>Always to be taken with large chunks of salt.</p>
  <blockquote>
  <p>set JAVA_OPTS=%JAVA_OPTS% -Xms128m -Xmx512m -XX:MaxPermSize=128m</p>
  </blockquote>
  <p>You would be better off using CATALINA_OPTS, since setting JAVA_OPTS pointlessly affects the shutdown script as well as the startup one.</p>
  <blockquote>
  <p>I know that settings:
  Xms128m -Xmx512m</p>
  <p>Control the initial heap size and what it can expand to.</p>
  </blockquote>
  <p>In a server environment, you normally want Xms and Xmx set to the same value to avoid heap thrashing.  The exact size is completely dependent on what your webapps need.</p>
  <blockquote>
  <p>But what exactly is:
  -XX:MaxPermSize=128m</p>
  </blockquote>
  <p>It's the amount of space to which the so-called permanent generation can expand.  PermGen holds primarily instances of java.lang.Class, so it only needs to be specified if you have a large number of classes in your environment.</p>
  <blockquote>
  <p>Should it be set to an addition of the other settings, or the other
  settings to an addition of it?</p>
  </blockquote>
  <p>What does that question mean?  PermGen size is completely independent of the heap size.</p>
  <p>Make sure you have enough RAM available on the system to support the Xmx + PermGen + a_lot_of_other_stuff.  Monitor the system to make sure you're not getting into paging.</p>