xintongsong commented on a change in pull request #9747: [FLINK-13985] Use 
unsafe memory for managed memory
URL: https://github.com/apache/flink/pull/9747#discussion_r328422193
 
 

 ##########
 File path: 
flink-core/src/main/java/org/apache/flink/core/memory/MemorySegmentFactory.java
 ##########
 @@ -86,16 +86,16 @@ public static MemorySegment 
allocateUnpooledOffHeapMemory(int size) {
        }
 
        /**
-        * Allocates some unpooled off-heap memory and creates a new memory 
segment that
-        * represents that memory.
+        * Allocates an unpooled off-heap memory and creates a new memory 
segment to represent that memory.
         *
         * @param size The size of the off-heap memory segment to allocate.
         * @param owner The owner to associate with the off-heap memory segment.
         * @return A new memory segment, backed by unpooled off-heap memory.
         */
        public static MemorySegment allocateUnpooledOffHeapMemory(int size, 
Object owner) {
-               ByteBuffer memory = ByteBuffer.allocateDirect(size);
-               return new HybridMemorySegment(memory, owner);
+               long address = MemoryUtils.allocateUnsafe(size);
+               ByteBuffer offHeapBuffer = 
MemoryUtils.wrapUnsafeMemoryWithByteBuffer(address, size);
+               return new HybridMemorySegment(offHeapBuffer, owner, 
MemoryUtils.createMemoryGcCleaner(offHeapBuffer, address));
 
 Review comment:
   We intend to use unsafe memory for memory manager (off-heap managed memory) 
only. This interface is also used by other components (`FileChannelBoundedData` 
and `NetworkBufferPool`), where direct memory limited by 
`-XX:MaxDirectMemorySize` is expected.
   
   I think we should not change this interface, but add another 
`allocateUnpooledUnsafeOffHeapMemory` and use it only in memory manager.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to