zhztheplayer commented on code in PR #13834:
URL: https://github.com/apache/gluten/pull/13834#discussion_r4760162894


##########
gluten-core/src/main/scala/org/apache/gluten/config/GlutenCoreConfig.scala:
##########
@@ -42,7 +43,10 @@ class GlutenCoreConfig(conf: SQLConf) extends Logging {
   def taskOffHeapMemorySize: Long = 
getConf(COLUMNAR_TASK_OFFHEAP_SIZE_IN_BYTES)
 
   def conservativeTaskOffHeapMemorySize: Long =
-    getConf(COLUMNAR_CONSERVATIVE_TASK_OFFHEAP_SIZE_IN_BYTES)
+    SparkResourceUtil
+      .currentTaskOffHeapBudget()
+      .map(_.conservativeBytes)
+      .getOrElse(getConf(COLUMNAR_CONSERVATIVE_TASK_OFFHEAP_SIZE_IN_BYTES))

Review Comment:
   Can we move `getOrElse` to callsites, to keep this simply 
`getConf(COLUMNAR_CONSERVATIVE_TASK_OFFHEAP_SIZE_IN_BYTES)`?



##########
gluten-core/src/main/scala/org/apache/spark/util/SparkResourceUtil.scala:
##########
@@ -16,16 +16,46 @@
  */
 package org.apache.spark.util
 
-import org.apache.spark.{SparkConf, SparkMasterRegex}
+import org.apache.spark.{SparkConf, SparkEnv, SparkMasterRegex, TaskContext}
 import org.apache.spark.internal.Logging
-import org.apache.spark.internal.config.{EXECUTOR_MEMORY, 
EXECUTOR_MEMORY_OVERHEAD}
+import org.apache.spark.internal.config.{EXECUTOR_MEMORY, 
EXECUTOR_MEMORY_OVERHEAD, MEMORY_OFFHEAP_ENABLED, MEMORY_OFFHEAP_SIZE, 
MEMORY_STORAGE_FRACTION}
 import org.apache.spark.network.util.ByteUnit
 import org.apache.spark.sql.internal.SQLConf
 
 object SparkResourceUtil extends Logging {
   private val MEMORY_OVERHEAD_FACTOR = "spark.executor.memoryOverheadFactor"
   private val MIN_MEMORY_OVERHEAD = "spark.executor.minMemoryOverhead"
 
+  case class TaskOffHeapBudget(bytes: Long, conservativeBytes: Long)
+
+  def taskOffHeapBudget(
+      offHeapSize: Long,
+      taskSlots: Int,
+      storageFraction: Double): TaskOffHeapBudget = {
+    // Isolation reserves room for non-borrowable storage memory.
+    val executionSize = (offHeapSize * (1.0d - storageFraction)).toLong
+    TaskOffHeapBudget(offHeapSize / taskSlots, executionSize / taskSlots)
+  }

Review Comment:
   Should this be private? 



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