Swami PR
Swami PR

Reputation: 871

Java Virtual Machine Heap Tuning Parameters

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?

Upvotes: 0

Views: 624

Answers (3)

Peter Lawrey
Peter Lawrey

Reputation: 533790

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.

Upvotes: 1

R.Moeller
R.Moeller

Reputation: 3446

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)

Upvotes: 1

Nizzo
Nizzo

Reputation: 356

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.

Upvotes: 1

Related Questions