Skip to main content

Is setting -Xmx==-Xms still considered harmful?

Posted by kcpeppe on December 19, 2011 at 5:40 AM PST

One of the old bits of tuning advice given when Java memory management was not as tall as it it today was to set max heap to min heap. After all, we don't really want the JVM messing around with memory when it should really be getting on with things. Fast forward a few years and the adaptive memory management picture has matured considerably. So much so that setting -Xmx == to -Xms would now be considered bad practice. Unfortunately, those of us that are rallying against the tide created by those who practice "tuning by folklore", have had our voices drowned out by the countless admin manuals that say, setup, step 12, in the console window set max heap to 2048m and min heap to 2048m, the overwhelming noise in the blog-o-sphere parroting this advice. As I've written before in this blog, setting max heap to min heap is a way to turn off the JVMs ability to adapt to changing conditions in your Java application's run time. But, maybe no more.

Those working on the long awaited G1 have just published a change request stating;

"The idea is to give G1 some room to allow it to use its heuristics for calculating the young gen size even when the heap size is fixed.

CR:
7113021 G1: automatically enable young gen size auto-tuning when -Xms==-Xmx"

This is what I like about the JVM.. if we can't change people's ideas about how to tune the JVM, we'll just change the JVM to match people's ideas of.. how to tune the JVM.

As far as I know, this will apply only the the G1 collector. So the best advice currently available for those needing/wanting adaptive GC is to use a Parallel Collector where -Xms is set to the maximum amount of heap you'd like to use and -Xmx is set higher to provide a wee bit of headroom just incase business picks up.