HDDS-10592. [hsync]Use Direct ByteBuffer in Output stream lastChunkBuffer.
What changes were proposed in this pull request?
Change lastChunkBuffer to use off-heap memory to reduce heap consumption in the output stream.
What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-10592
How was this patch tested?
Existing test https://github.com/ashishkumar50/ozone/actions/runs/9013881546/workflow
actually, if output stream simply allocate direct buffer without managing/recycling the buffer upon the closure of the output stream itself, it's going to run out of memory quite easily.
In theory when a direct buffer is no longer hard-referenced, JVM GC will be able to clean the object up (and free() the referenced memory) just like regular heap buffer.
But, because direct buffer does not count towards JVM heap usage I am not sure if JVM still tracks the size of those directly malloc()ed memory size. And thus unlike heap memory pressure which JVM can sense and trigger GC to recycle unused (non-referenced) objects, I am not sure JVM would do the same for direct buffer ones. If not that could explain why it can still get OutOfMemoryError: Direct buffer memory if unused direct buffer objects are not GC'ed quickly enough (when a low -XX:MaxDirectMemorySize number is set).
So yes proactively cleaning is better.
Related:
By default, the JVM does not set a limit on how much memory is used for Direct Byte Buffers. A soft limit of 64 MB is set, which the JVM automatically expands in 32 MB chunks, as required.
https://www.ibm.com/docs/de/sdk-java-technology/8?topic=options-xxmaxdirectmemorysize
It's expensive to allocate direct buffer than on heap buffer. So in HDFS client, direct buffer pool is used to reuse the direct buffer, I think we should consider use it too in Ozone client, so we don't need to worry about the reclaim of direct buffer if too much is allocated.
It's expensive to allocate direct buffer than on heap buffer. So in HDFS client, direct buffer pool is used to reuse the direct buffer, I think we should consider use it too in Ozone client, so we don't need to worry about the reclaim of direct buffer if too much is allocated.
I have updated with buffer pool.