Sunday, August 2, 2009

How is the max value that you can set with the -Xmx param for heap size of the java jvm determined?

I would like to instantiate the java jvm with a larger max heap size. I use the -Xmx parameter to do so. I have discovered though that the value you can specify here differs from box to box. I assume its related to the physical and swap memory. Is there a formula that can be applied to determine the max value? Can you get around physical memory limitations by instructing the jvm to utilize swap memory (I am using linux)

How is the max value that you can set with the -Xmx param for heap size of the java jvm determined?
According to Sun's documentation, the defaults are set as follows:





If not otherwise set on the command line, the sizes of the initial heap and maximum heap are calculated based on the size of the physical memory. If phys_mem is the size of the physical memory on the platform, the initial heap size will be set to phys_mem / DefaultInitialRAMFraction. DefaultInitialRAMFraction is a command line option with a default value of 64. Similarly the maximum heap size will be set to phys_mem / DefaultMaxRAM. DefaultMaxRAMFraction has a default value of 4.





Anyways there is no way to utilize swap memory. All heap increases use methods that try and avoid swapping.


Also heap increases and decreases can be controlled by the


-XX:MinHeapFreeRatio and -XX:MaxHeapFreeRatio options


which looks at the ratio of free space to object space and makes sure that it lies between these option values. Defaults


are 40% and 70% for above ratios respectively.





Otherwise you can try to use the -XX:+AggressiveHeap option to allow the jvm to push the heap to the limit, again unfortunately limited by the physical memory. But key issue is setting max values will also affect other applications running on the server so setting the correct value will depend on what the required service level is.

sd cards

No comments:

Post a Comment