KushShriv opened a new pull request, #13754:
URL: https://github.com/apache/gluten/pull/13754

   ## What changes are proposed in this pull request?
   
   `ColumnarBatches.load` imports the Arrow buffers exported from a native 
batch into Gluten's task allocator (`ArrowBufferAllocators.contextInstance()`). 
Arrow's `wrapForeignAllocation` calls the allocator's listener for imported 
buffers too, so `ManagedAllocationListener` reserves Spark memory for them. But 
the buffers stay owned by the native batch, whose memory is already reserved by 
the Velox memory pool. While the loaded batch is alive, its memory is counted 
twice.
   
   This PR fixes it for the operators that load a batch only to read it and 
close it themselves:
   
   - **`ArrowBufferAllocators.contextUntrackedInstance()`** (new): a separate 
per-task `RootAllocator` whose listener doesn't reserve Spark memory. It's 
released at task end like `contextInstance()`.
   - **`ColumnarPartialProjectExec`**, **`ColumnarPartialGenerateExec`** and 
**`VeloxColumnarWriteFilesExec`** load into it. They read the loaded rows, copy 
any results into new vectors (`ArrowWriter`), and close the loaded batch.
   - **Docs**: `ArrowColumnarConversion.md` describes the untracked allocator 
and where it's used.
   
   It's a separate root, not a child of the task allocator. Arrow reserves a 
buffer through the listener of the allocator that creates it, but repays it 
through the allocator that owns it last (`AllocationManager.release`). When a 
buffer is shared and its owner releases first, `BufferLedger.transferBalance` 
moves ownership without calling either listener. With a child allocator, a 
buffer could be reserved by one listener and repaid by the other, which showed 
up as `Managed memory leak` in the Arrow UDF tests.
   
   Arrow can't move or share buffers across roots, so batches that leave the 
operator stay in the task allocator. That covers `LoadArrowDataExec`, whose 
batches `ColumnarArrowEvalPythonExec` joins with the Python results and 
offloads. That operator is handled in a follow-up change.
   
   ## How was this patch tested?
   
   - `ColumnarBatchTest.testUntrackedLoadDoesNotReserveNativeMemoryTwice` 
(new): builds a native Velox batch of 4M `bigint` rows (32 MiB), loads it into 
the untracked allocator, and checks the task's reserved memory 
(`TaskResources.getSharedUsage()`, shared by the Arrow and Velox reservation 
listeners) before and after the load. Loading into the task allocator, as 
before this PR, reserves 40 MiB more: `Loading 33554432 bytes of native data 
reserved 41943040 more bytes`.
   - Spark 3.5, rebased on current main, all passing: `ColumnarBatchTest` (7 
tests), `UDFPartialProjectSuite`, `VeloxTransitionSuite`, 
`ArrowEvalPythonExecSuite` and `VeloxParquetWriteSuite` (57 tests, 5 ignored, 0 
failed). `spotless:check` and scalastyle pass.
   - Not run locally: other Spark versions (CI).
   
   ## Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Code (claude-sonnet-5-5)
   


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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to