liyafan82 commented on a change in pull request #6323:
URL: https://github.com/apache/arrow/pull/6323#discussion_r415203808



##########
File path: 
java/memory/src/main/java/org/apache/arrow/memory/NettyAllocationManager.java
##########
@@ -17,48 +17,97 @@
 
 package org.apache.arrow.memory;
 
-import org.apache.arrow.memory.util.LargeMemoryUtil;
-
 import io.netty.buffer.PooledByteBufAllocatorL;
 import io.netty.buffer.UnsafeDirectLittleEndian;
+import io.netty.util.internal.PlatformDependent;
 
 /**
- * The default implementation of AllocationManagerBase. The implementation is 
responsible for managing when memory
+ * The default implementation of {@link AllocationManager}. The implementation 
is responsible for managing when memory
  * is allocated and returned to the Netty-based PooledByteBufAllocatorL.
  */
 public class NettyAllocationManager extends AllocationManager {
 
   public static final Factory FACTORY = new Factory();
 
+  /**
+   * The default cut-off value for switching allocation strategies.
+   * If the request size is not greater than the cut-off value, we will 
allocate memory by
+   * {@link PooledByteBufAllocatorL} APIs,
+   * otherwise, we will use {@link PlatformDependent} APIs.
+   */
+  public static final long DEFAULT_ALLOCATION_CUTOFF_VALUE;
+
+  public static final String DEFAULT_ALLOCATION_CUTOFF_NAME = 
"default.allocation.cutoff.name";
+
+  static {
+    long cutOffValue;
+    try {
+      cutOffValue = 
Long.parseLong(System.getProperty(DEFAULT_ALLOCATION_CUTOFF_NAME));
+    } catch (Exception e) {
+      cutOffValue = Integer.MAX_VALUE;
+    }
+    DEFAULT_ALLOCATION_CUTOFF_VALUE = cutOffValue;
+  }
+
   private static final PooledByteBufAllocatorL INNER_ALLOCATOR = new 
PooledByteBufAllocatorL();
   static final UnsafeDirectLittleEndian EMPTY = INNER_ALLOCATOR.empty;
   static final long CHUNK_SIZE = INNER_ALLOCATOR.getChunkSize();
 
-  private final int allocatedSize;
+  private final long allocatedSize;
   private final UnsafeDirectLittleEndian memoryChunk;
+  private final long allocatedAddress;
+
+  /**
+   * The cut-off value for switching allocation strategies.
+   */
+  private final long allocationCutOffValue;
 
-  NettyAllocationManager(BaseAllocator accountingAllocator, int requestedSize) 
{
+  NettyAllocationManager(BaseAllocator accountingAllocator, long 
requestedSize, long allocationCutOffValue) {
     super(accountingAllocator);
-    this.memoryChunk = INNER_ALLOCATOR.allocate(requestedSize);
-    this.allocatedSize = memoryChunk.capacity();
+    if (allocationCutOffValue > Integer.MAX_VALUE) {
+      throw new IllegalArgumentException("The cut-off value cannot be larger 
than Integer.MAX_VALUE");
+    }
+    this.allocationCutOffValue = allocationCutOffValue;
+
+    if (requestedSize > allocationCutOffValue) {
+      this.memoryChunk = null;
+      this.allocatedAddress = PlatformDependent.allocateMemory(requestedSize);
+      this.allocatedSize = requestedSize;
+    } else {
+      this.memoryChunk = INNER_ALLOCATOR.allocate(requestedSize);
+      this.allocatedAddress = memoryChunk.memoryAddress();
+      this.allocatedSize = memoryChunk.capacity();
+    }
+  }
+
+  NettyAllocationManager(BaseAllocator accountingAllocator, long 
requestedSize) {
+    this(accountingAllocator, requestedSize, DEFAULT_ALLOCATION_CUTOFF_VALUE);
   }
 
   /**
    * Get the underlying memory chunk managed by this AllocationManager.
-   * @return buffer
+   * @return the underlying memory chunk if the request size is not greater 
than the
+   *   {@link NettyAllocationManager#allocationCutOffValue}, or null otherwise.
+   *
+   * @deprecated this method will be removed in a future release.
    */
+  @Deprecated
   UnsafeDirectLittleEndian getMemoryChunk() {
-    return memoryChunk;
+    return allocatedSize > allocationCutOffValue ? null : memoryChunk;

Review comment:
       Sorry. This is not needed. Reverted.




----------------------------------------------------------------
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


Reply via email to