zhztheplayer commented on a change in pull request #11182:
URL: https://github.com/apache/arrow/pull/11182#discussion_r712599015
##########
File path:
java/memory/memory-core/src/main/java/org/apache/arrow/memory/BaseAllocator.java
##########
@@ -272,18 +282,37 @@ public ArrowBuf buffer(final long initialRequestSize,
BufferManager manager) {
}
boolean success = false;
+ final ArrowBuf buffer;
try {
- ArrowBuf buffer = bufferWithoutReservation(actualRequestSize, manager);
+ buffer = bufferWithoutReservation(actualRequestSize, manager);
success = true;
- listener.onAllocation(actualRequestSize);
- return buffer;
} catch (OutOfMemoryError e) {
throw e;
} finally {
if (!success) {
releaseBytes(actualRequestSize);
}
}
+
+ final long grantedSize = buffer.getReferenceManager().getSize();
+ if (grantedSize != actualRequestSize) {
+ // reallocate bytes using the actual returned chunk size
+ long diff = grantedSize - actualRequestSize;
+ if (diff > 0) {
+ AllocationOutcome reallocateOutcome = allocateBytes(diff);
+ if (!reallocateOutcome.isOk()) {
+ // forcibly allocate for remaining bytes, then release all
+ forceAllocate(diff);
+ buffer.close();
+ throw new OutOfMemoryException(createErrorMsg(this, grantedSize,
actualRequestSize,
+ initialRequestSize), reallocateOutcome.getDetails());
+ }
+ } else {
+ releaseBytes(-diff);
Review comment:
This is a great point... Should we consider the case that the return
size is constantly set to zero by a customizied AM? I was trying to do
something like this to make the allocator yield its local allocation limit to a
user-defined global counter. That says, actually, the AM's size in Arrow is
only used to account bytes to allocators.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]