4 Replies Latest reply: Jun 5, 2012 5:01 AM by gimbal2 RSS

    Unsanely high default value for maximum heap size ?


      I think I do not understand correctly how maximum heap size is computed by the JVM when option -Xmx is not specified.

      I run java 1.6.0_31 on a machine with 24 cpu cores, 200 GB of physical memory and 16 GB of swap. The system is Linux with a strict overcommit policy and the commit limit is 205 GB

      I noticed that all my java processes (launched without any -Xmx option) had huge amounts of virtual memory allocated to them (around 30 GB per java process), even for trivial java processes with very little processing.

      This was not an issue until I had to launch more java processes in parallel ; as each JVM commits 30GB, my committed memory quickly reaches the commit limit and I cannot launch anymore JVMs (java command fails with: "Could not reserve enough space for object heap")

      To investigate the problem, I wrote the very simple program:

      class Prog {
      public static void main(String[] args) throws InterruptedException
      long maxBytes = Runtime.getRuntime().maxMemory();
      System.out.println("Max memory: " + maxBytes / 1024 / 1024 + "M");

      And on my machine I executed:

      pierre@devhost:~> java Prog
      Max memory: 29127M
      pierre@devhost:~> java -Xmx20000M Prog
      Max memory: 17777M
      pierre@devhost:~> java -Xmx40000M Prog
      Max memory: 35555M
      pierre@devhost:~> java -Xmx10000M Prog
      Max memory: 8888M

      Now my (approximative) conclusions are:
      - maxMemory value is somehow related to the maximum heap size
      - when launching java without any -Xmx option, the maximum heap size is around 30GB, which is aproximately the virtual memory allocated to my java process
      - I can solve my problem by setting a lower value for maximum heap size with -Xmx

      The questions that remain are:
      - How come heap size and thus virtual memory used are so big by default ?
      - Isn't this a problem for anyone using java in a shared environment ?
      - The documentation at http://docs.oracle.com/javase/6/docs/technotes/guides/vm/gc-ergonomics.html suggests that this default maximum heap size should be capped to 1 GB whereas in my case it obviously isn't. I couldn't find more recent links. Has this changed with Java 6 ? What is the new limit ? With which release exactly was this new default limit introduced ?
      - Is there a cleaner solution for me than to use -Xmx to lower maximum heap size on all my java processes ?

      Thats it!

      Thanks in advance,