Currently in our testing environment the max and min JVM heap size are set to the same value, basically as much as the dedicated server machine will allow for our application. Is this the best configuration for performance or would giving the JVM a range be better?
Java – Is it good to set the max and min JVM heap size the same
javajvm
Related Topic
- Java – Maximum Java heap size of a 32-bit JVM on a 64-bit OS
- Java – how to choose the jvm heap size
- Java – the default maximum heap size for Sun’s JVM from Java SE 6
- Java webstart max-heap-size causes JVM cannot be started
- Java – Can the JVM max heap size be dynamic
- Java – How is the default max Java heap size determined
- Java – What are the -Xms and -Xmx parameters when starting JVM
Best Answer
Peter 's answer is correct in that
-Xms
is allocated at startup and it will grow up to-Xmx
(max heap size) but it's a little misleading in how he has worded his answer. (Sorry Peter I know you know this stuff cold).Setting ms == mx effectively turns off this behavior. While this used to be a good idea in older JVMs, it is no longer the case. Growing and shrinking the heap allows the JVM to adapt to increases in pressure on memory yet reduce pause time by shrinking the heap when memory pressure is reduced. Sometimes this behavior doesn't give you the performance benefits you'd expect and in those cases it's best to set mx == ms. OOME is thrown when heap is more than
98%
of time is spent collecting and the collections cannot recover more than2%
of that. If you are not at max heaps size then the JVM will simply grow so that you're beyond that boundaries. You cannot have anOutOfMemoryError
on startup unless your heap hits the max heap size and meets the other conditions that define anOutOfMemoryError
.For the comments that have come in since I posted. I don't know what the JMonitor blog entry is showing but this is from the
PSYoung
collector.I could do more digging about but I'd bet I'd find code that serves the same purpose in the
ParNew
andPSOldGen
andCMS Tenured
implementations. In fact it's unlikely that CMS would be able to return memory unless there has been aConcurrent Mode Failure
. In the case of aCMF
the serial collector will run and that should include a compaction after which top of heap would most likely be clean and therefore eligible to be deallocated.