Semantics of `-Xmn` (Re: hotspot-gc-dev Digest, Vol 186, Issue 12)

Ramakrishna, Ramki ysr at amazon.com
Wed Dec 7 22:23:02 UTC 2022


Thank you, StefanK, StefanJ, and Thomas, for your detailed responses!

I guess it's complicated ...

Like StefanJ stated, we could fix `-Xms` to state "initial and minimum", and leave `-Xmn` for now, or may be add some verbiage that includes the phrase `best effort` __

Later,
-- Ramki


------------------------------

Message: 2
Date: Tue, 6 Dec 2022 14:47:04 +0100
From: Stefan Karlsson <stefan.karlsson at oracle.com>
To: hotspot-gc-dev at openjdk.org
Subject: Re: Semantics of `-Xmn`
Message-ID: <5daa4918-4255-61a1-3077-17efdf569bb3 at oracle.com>
Content-Type: text/plain; charset=UTF-8; format=flowed

On 2022-12-04 03:38, Ramakrishna, Ramki wrote:
> Question: Can `-Xmn` be interpreted as "fix young gen size to the specified value, not allowing any resizing"?
>
> $ java -X
> ...
>      -Xmn<size>        sets the initial and maximum size (in bytes) of the heap
>                        for the young generation (nursery)
>      -Xms<size>        set initial Java heap size
>      -Xmx<size>        set maximum Java heap size
> ...
>
> Note that this states "sets the initial and maximum size", as though one might be allowed to make the size smaller, but never larger than this.
>
> Similarly `-Xms` sets the initial heap size and `-Xmx` the maximum heap size. Would one be allowed to make the heap size smaller than the `-Xms` specification
>
> It seems as though at least historically one has (implicitly) identified "initial" with "minimum". Thus, we have asked customers to set `-Xms` and `-Xmx` to the same value to prevent changes to the heap size.

FWIW, a few years ago we went over some of the documentation around
`-Xms` to make it clear that that it meant both "initial" and "minimum".
It would probably be good to change the `java -X` output as well.

I'll let others comment about the `-Xmn` flag.

StefanK
...
    ------------------------------

    Message: 3
    Date: Wed, 7 Dec 2022 08:38:06 +0100
    From: Stefan Johansson <stefan.johansson at oracle.com>
    To: Stefan Karlsson <stefan.karlsson at oracle.com>,
            hotspot-gc-dev at openjdk.org
    Subject: Re: Semantics of `-Xmn`
    Message-ID: <f255be0d-e77d-9b4e-7909-ebbfee714296 at oracle.com>
    Content-Type: text/plain; charset=UTF-8; format=flowed

    Hi Ramki,

    On 2022-12-06 14:47, Stefan Karlsson wrote:
    > On 2022-12-04 03:38, Ramakrishna, Ramki wrote:
    >> Question: Can `-Xmn` be interpreted as "fix young gen size to the
    >> specified value, not allowing any resizing"?
    >>

    Kind of, but not exactly for G1. With G1 setting `-Xmn` will create a
    policy that doesn't recalculate the desired size of the young generation
    and sets it to the given value. But this is just a "desired" size and it
    doesn't set a fixed size for the old generation. So if the application
    keeps a lot of objects alive the old generation might grow "too large"
    and cause the young generation to be smaller than what is set with `-Xmn`.

    Same goes for `-XX:NewSize` in G1 it will not be a hard minimum but set
    the desired minimum to this value.

    Given how G1 work I think the below text for `-Xmn` is ok, but I agree
    with StefanK that we should probably update the text for `-Xms`.

    Hope this helps.

    StefanJ
...
    ------------------------------

    Message: 4
    Date: Wed, 7 Dec 2022 09:20:22 +0100
    From: Thomas Schatzl <thomas.schatzl at oracle.com>
    To: hotspot-gc-dev at openjdk.org
    Subject: Re: Semantics of `-Xmn`
    Message-ID: <483b7d69-670a-945a-99c0-d2967efb50ed at oracle.com>
    Content-Type: text/plain; charset=UTF-8; format=flowed

    Hi,

    On 07.12.22 08:38, Stefan Johansson wrote:
    > Hi Ramki,
    >
    > On 2022-12-06 14:47, Stefan Karlsson wrote:
    >> On 2022-12-04 03:38, Ramakrishna, Ramki wrote:
    >>> Question: Can `-Xmn` be interpreted as "fix young gen size to the
    >>> specified value, not allowing any resizing"?
    >>>
    >
    > Kind of, but not exactly for G1. With G1 setting `-Xmn` will create a
    > policy that doesn't recalculate the desired size of the young generation
    > and sets it to the given value. But this is just a "desired" size and it
    > doesn't set a fixed size for the old generation. So if the application
    > keeps a lot of objects alive the old generation might grow "too large"
    > and cause the young generation to be smaller than what is set with `-Xmn`.
    >  > Same goes for `-XX:NewSize` in G1 it will not be a hard minimum but set
    > the desired minimum to this value.

    +1

    G1's policy in this situation is fairly crude: it by default tries to
    keep this free region reserve (G1ReservePercent) to accommodate
    surviving objects in the next gc.

    Since this is a static measure, this is fairly prone to being wrong in
    either direction, either too large (for large heaps) or too small (for
    small heaps), in the best case using a smaller than expected young gen
    (degrading "nicely") or in the worst case running into Full GCs.

    Not much effort has been put into better behavior in this situation.

    Thanks,
       Thomas



 




More information about the hotspot-gc-dev mailing list