0

What would be the effect of setting only -Xms without setting a -Xmx for eg. java -Xms 2048m ? Does setting a high lower value for -Xms mean lesser Heap Fragmentation?

3 Answers 3

1

Setting -Xms to the estimated heap requirement of your application will speed up start of your application (of course Xms must be <= Xmx). Reason is the VM will spend some effort doing Full GC before it grows, so there might be several Full GC's until the VM figures out the real memory requirement of your app. It doesn't help with fragmentation (which can occur with CMS only anyway)

Sign up to request clarification or add additional context in comments.

Comments

1

For clarity I would recommend you always define ms and mx (unless the defaults are sufficient). I think the result may differ depending on the JVM, but I believe Oracle's will throw an error if -Xms exceeds the default -Xmx setting.

As far as heap fragmentation, I think that depends on the app and tuning of the JVM. It will vary depending on the JVM you're using, what garbage collector you're using, etc.

Comments

1

While I agree with Nizzo in most respects (+1 BTW), I am in the minority which believes that you should only set values which you know will be useful, the less values you set the better and in this vain, only set -Xms if you know because you measured the JVM will grow to that size anyway. You can just set the maximum, if it needs to be set, and less the JVM work out the right size to use.

I think part of the confusion is that -Xms -Xmx are always set in performance benchmarks. This is because the work load is known and the JVM has been tuned to the max. This doesn't make it a good practice for normal application usage IMHO.

The JVM reserves the maximum heap size as address space on start up (which is a problem on 32-bit Windows which has a small and fragmented memory space)

BTW Unless you are using CMS and are concerned about fragmentation in tenured space, none of the other spaces or GCs get fragmented.

1 Comment

+1 using inappropriate xms settings will be worse than letting the JVM handle the heap size automatically. In particular if xms=xmx the JVM can't optimise the size of the heap any more.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.