0

I have an application which will use 300 million size of hash maps. For that I initialized the JVM with initial and maximum heap size of 16 GB i.e. (java -Xms16384M -Xmx16384M) but I am getting java OutOfMemoryError. my machine is having 32 GB RAM with RedHat Linux operating system installed. I observed that JVM is using only 25% of RAM from "top" command in Linux i.e 8GB even though i set it for 16GB it is using only 8GB.

I want to know that if JVM is limiting the RAM?

How to configure JVM to use complete min and max heap size given?

3
  • Can you post the exact error message and the complete java call? Commented Dec 15, 2011 at 15:04
  • I would use -ms16g -mx16g but that should do the same thing. Can you try a small test program which shows you are getting OOME before you have run out of memory? Commented Dec 15, 2011 at 15:05
  • Is this a heap OOM or a permgen OOM? The distinction is very important! Commented Dec 15, 2011 at 15:14

3 Answers 3

1

Can you try this program?

System.out.println("Max memory "+Runtime.getRuntime().maxMemory()/100 /1000+" MB."); int mb = 0; try { List<byte[]> bytes = new ArrayList<>(); while (true) { bytes.add(new byte[1000 * 1000]); mb++; } } catch (OutOfMemoryError expected) { } System.out.println("OOME after " + mb + " MB allocated"); 

what does it print for your settings? For -mx8g I get

Max memory 7635 MB. OOME after 7025 MB allocated 

For -mx12g I get

Max memory 11453 MB. OOME after 10012 MB allocated 

and with -mx12g -XX:MaxNewSize=512m I get

Max memory 12705 MB. OOME after 12863 MB allocated 
Sign up to request clarification or add additional context in comments.

Comments

0

Can you post the exception stack trace? If the figures you posted are correct, you might be possibly running out of permanent memory (permagen errors) in which case you also need to add -XX:PermSize and/or -XX:MaxPermSize flags. Which JVM version are you using?

Comments

0

The garbage collector needs some of the heap too (almost half of it if most of your stuff is in the young generation which is handled by a copying collection); that memory will be kept untouched to be used by the GC.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.