[jboss-user] [Performance Tuning] - Re: when does java release commited memory back to the OS

PeterJ do-not-reply at jboss.com
Wed Apr 8 11:06:43 EDT 2009


Using the default collectors (CMS and G1 are different), GC does not take place until there is no room in the eden space (within the young generation) to allocate an object. The first thing the JVM does is determine if it needs to collect the old generation before it collects the young generation. The way the Sun JVM does this is it assumes the worst-case scenario that all objects currently occupying the young generation will survive the collection, and thus if the size of the young generation is less than the available space in the old generation, it collects the old generation first, and then the young generation (thus resulting in a full collection).

Example using your settings and assuming the JVM starts with the min heap size. You are starting with:

young gen: 125MB,  old gen: 25MB

Hmm, that is not good - the first collection might result in a full collection but the old gen is empty. My bet is that the heap will immediately be resized, so let's pick a better heap size, say 300MB, then we have:

young gen: 125MB,  old gen: 175MB

Let's say that for the first minor collection 60MB of objects are placed into the old gen (usually not likely, but after several collections you could have that much space used). So now you have only 115MB of free space left in the old gen. The next collection will be a full collection (125MB young gen > 115MB free old gen). Now let's assume the JVM does not adjust the heap size any more, and that there is always around 60MB of objects occupying the old gen. The result: every collection is a full collection.

Now, if the JVM resizes the heap up to the 600MB max, you are in better shape. Then you have:

young gen: 125MB,  old gen: 475MB

Not until the old gen contains > 350MB of objects would the JVM do a major collection. Of course, if your working set size is > 350MB then you will find yourself in the same boat again - major collection each time.

Now in the above I have not taken the size of the survivor spaces into account, nor any fine tuning the that JVM does with heap sizing during each collection, or advances in newer JVMs (an early version of JDK5 was the last one I checked this on). You can easily monitor the exact behavior by turning on one of the GC statistics options.

View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4224392#4224392

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4224392



More information about the jboss-user mailing list