Add limit for MemorySegment.allocateNative
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Mon Jun 22 09:58:05 UTC 2020
Hi Robert,
you are right in that the foreign memory API does not respect the memory
limit set by XX:MaxDirectMemorySize; and we're aware if that. The reason
as to why we did not add a limit (or reuse existing ones) is that the
allocation story is still in flux; right now memory allocation uses
separate mallocs (as ByteBuffer.allocateDirect does). But it is possible
that, in the not-so-distant future we will add other ways to allocate
memory, which will yield significantly better allocation performances
over malloc. Since the allocators we were looking at were based on the
idea of reserving a fixed size of memory at VM startup (say 2G) and then
commit said memory incrementally, as allocation requests are coming in,
limiting the allocation size in a scheme such as this one is much much
simpler, and requires no locking (if you run out of virtual address
space, you simply fail to allocate). This is the main reason as to why
we didn't tackle the memory limit problem (yet), but we'll get there -
hopefully soon.
That said, if you happen to have a patch ready, it'd be useful to take a
look and evaluate the impact of the size check on the segment allocation
performances (IIRC that logic does some locking/CASing in order to
ensure consistency across multiple threads).
Maurizio
On 21/06/2020 04:59, Robert Lu wrote:
> The jdk.incubator.foreign is really fast, but unlike
> ByteBuffer.allocateDirect , there is no such limit like
> XX:MaxDirectMemorySize .
>
> How could the user set max memory size used by jdk.incubator.foreign?
>
> Could I submit a patch to count jdk.incubator.foreign's memory to
> java.nio.Bits#RESERVED_MEMORY, and follow the limit of
> XX:MaxDirectMemorySize?
>
>
>
More information about the panama-dev
mailing list