JVM heaps can scale up but not down
Jesper Wilhelmsson
jesper.wilhelmsson at oracle.com
Thu Aug 21 06:47:13 UTC 2014
Hi Andrew,
The flag -XX:MaxHeapFreeRatio was recently made manageable so that you can
change its value during runtime. The motivating use case behind that change was
exactly the scenario you describe, that you want to force a running JVM to
shrink the heap.
Lowering MaxHeapFreeRatio may decrease performance since it will likely increase
garbage collection frequency. The way to use it in a production server would
probably be to lower the ratio, force a System.gc to shrink the heap and then
increase the ratio again.
Unfortunately there can never be any guaranties that the heap can shrink unless
you force a full GC that compacts the entire heap. The heap has to be allocated
as one consecutive memory area and if you're unlucky there can be some long
lived object allocated near the top of the heap which makes it impossible to
shrink the memory area.
Recently there has been plenty of work in the G1 collector to deal with this
situation. In 8u20 we started sorting the memory regions to increase the chances
of allocating long lived objects at the bottom of the heap. In 8u40 we will
introduce the possibility to decommit memory within the heap. This will make it
possible to shrink the heap by cutting out a hole somewhere within the heap
rather than being forced to only shrink from the top. This change will most
likely be pushed to 8u40 within the next few days, it's already present in the
JDK 9 repository.
These features are all default behavior in G1, so if you haven't already, switch
to G1 (-XX:+UseG1GC) and try out the latest bits to see if it solves your problem.
Best regards,
/Jesper
Andrew Ash skrev 21/8/14 00:42:
> // please redirect if this is the wrong list
>
> Hi JDK devs,
>
> I'm occasionally in a situation where I have a JVM running and want to tell
> it to "scale down" to use less heap than its current active set. This
> would be in the space between -Xms and -Xmx bounds. Scaling "up" from -Xms
> towards -Xmx obviously happens automatically, and I've heard conventional
> wisdom that you can't decrease heap size on a running JVM, but I've never
> heard of any work being done to make that possible.
>
> The use case is when I have a long-running JVM in an Apache Mesos [1]
> context, and Mesos wants to "take back" some memory resources from a
> running JVM task.
>
> Is there any work being done to make scaling down possible?
>
> Cheers,
> Andrew
>
>
> [1] https://mesos.apache.org/
>
More information about the jdk9-dev
mailing list