Java-Monitor Forum > Forum > Java Administration » Should we set -Xms to match -Xmx?
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 07-07-2009, 10:55
kjkoster kjkoster is offline
Forum Operator
Join Date: Jul 2008
Posts: 1,195
Default Should we set -Xms to match -Xmx?

Dear All,

There is a custom among Java administrators to set -Xms to the same value as -Xmx. I have long wondered what the effect of this could be. Hearsay suggests that this keeps the JVM from repeatedly allocating and de-allocating memory, thus reducing the memory allocation overhead. Unfortunately I have been unable to find any measurements that suggest that doing this makes any difference.

As you may or may not know, Java works with fixed size memory pools. The memory for those pools is allocated by requesting chunks or memory from the operating system.

You can see this in action by watching the memory graphs, where the red line indicates the configured maximum memory to use. The green line shows the actual fill level of the memory pool. The blue line is what Java has requested from the operating system so far. It shows how Java requests and returns memory over time.

Well, I have been running with -Xmx set to 1GB for a long time and recently I figured I would experiment with also setting -Xms to the same value and see for myself what happens. In short, setting -Xms does what it says on the box: it sets the initial memory pool sizes to the value. After that, Java just resumes its normal behaviour of allocating memory. This can be seen in the memory graph below.

As you can see, when we specify -Xms to be the same as -Xmx, the blue line immediately starts out at the maximum level. It stays up there for a while, but after a while the blue line drops sharply. From then on, Java does what is always does: allocate and de-allocate memory from the operating system.

This behaviour seems to be controlled from the PS MarkSweep garbage collector. As you can see in the graph below, Java leaves the committed memory (relatively) untouched, until a full GC is performed. The first PS MarkSweep (which does full garbage collects) spike coincides with the sharp drop in committed memory. In the full GC, it ignores the -Xms setting and returns a large portion of the freed memory to the operating system.

So, to summarise: feel free to keep setting -Xms to match -Xmx if you like. It won't make any difference for a server which runs for longer periods of time.

Kees Jan

PS. Yes, the blue line sometimes crosses up higher than the red line. I don't know why that is, but I believe that Java requests memory in certain fixed size blocks. The crossings may indicate rounding artefacts, where Java decides it is better to ask just a little more so that it can fill an entire block. This is just speculation, tough, so don't take it from me.
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump