wecharyu opened a new issue, #13660:
URL: https://github.com/apache/gluten/issues/13660

   ### Backend
   
   VL (Velox)
   
   ### Bug description
   
   When enabling building broadcast hash table in driver side 
(https://github.com/apache/gluten/pull/11993), the executor may fail by OOM:
   ```bash
   Global off-heap target stats: 
        GlobalOffHeap.0: Current used bytes: 0.0 B, peak bytes: 0.0 B
   
   Serialization trace:
   serializedData (org.apache.gluten.execution.SerializedBroadcastHashTable)
   serializedHashTable 
(org.apache.spark.sql.execution.SerializedHashTableBroadcastRelation)
        at org.apache.spark.util.Utils$.tryOrIOException(Utils.scala:1532)
        at 
org.apache.spark.broadcast.TorrentBroadcast.readBroadcastBlock(TorrentBroadcast.scala:228)
        at 
org.apache.spark.broadcast.TorrentBroadcast.getValue(TorrentBroadcast.scala:105)
        at org.apache.spark.broadcast.Broadcast.value(Broadcast.scala:70)
        at 
org.apache.gluten.execution.VeloxSerializedBroadcastRDD.genBroadcastBuildSideIterator(VeloxSerializedBroadcastRDD.scala:35)
        at 
org.apache.gluten.execution.ColumnarInputRDDsWrapper.$anonfun$getIterators$1(WholeStageTransformer.scala:564)
        at scala.collection.immutable.List.flatMap(List.scala:366)
        at 
org.apache.gluten.execution.ColumnarInputRDDsWrapper.getIterators(WholeStageTransformer.scala:562)
        at 
org.apache.gluten.execution.WholeStageZippedPartitionsRDD.$anonfun$compute$1(WholeStageZippedPartitionsRDD.scala:48)
        at org.apache.gluten.utils.Arm$.withResource(Arm.scala:25)
        at 
org.apache.gluten.metrics.GlutenTimeMetric$.millis(GlutenTimeMetric.scala:37)
        at 
org.apache.gluten.execution.WholeStageZippedPartitionsRDD.compute(WholeStageZippedPartitionsRDD.scala:46)
   ```
   
   **Root Cause**
   The broadcast receive buffer uses the global Arrow allocator. Its allocation 
listener reserves memory through `GlobalOffHeapMemory.target`, which ultimately 
calls Spark’s `acquireStorageMemory`. So when the full memory is occupied by 
execution memory, the executor will throw an OOM directly.
   
   **Solution**
   We can follow the vanilla Spark's behavior for broadcast hash table: 
reconstructs its table using an independent UnifiedMemoryManager([driver 
build](https://github.com/apache/spark/blob/master/sql/core/src/main/scala/org/apache/spark/sql/execution/joins/HashedRelation.scala#L144-L151),
 [executor 
restore](https://github.com/apache/spark/blob/master/sql/core/src/main/scala/org/apache/spark/sql/execution/joins/HashedRelation.scala#L403-L412)),
 and then use 
[MemoryStore](https://github.com/apache/spark/blob/master/core/src/main/scala/org/apache/spark/storage/memory/MemoryStore.scala#L276)
 to attempt to account for the memory usage in Spark's storage memory pool. If 
the reservation fails, keep the table usable instead of failing the task. 
   
   Gluten should adopt the same separation between reconstruction and storage 
accounting while retaining off-heap allocation:
   - Use independent broadcast allocators for receive buffers and native hash 
table construction/restoration.
   - Attempt Spark storage accounting after an executor has built or restored 
the table.
   - Keep the table usable if the reservation fails.
   - Repay successful reservations when cache entries are removed, without 
charging shared clones twice.
   
   ### Gluten version
   
   _No response_
   
   ### Spark version
   
   None
   
   ### Spark configurations
   
   
spark.gluten.sql.columnar.backend.velox.driverSideBroadcastHashTableBuild=true
   
   ### System information
   
   _No response_
   
   ### Relevant logs
   
   ```bash
   
   ```


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