zhouyuan commented on code in PR #9066: URL: https://github.com/apache/incubator-gluten/pull/9066#discussion_r2005854976
########## backends-velox/src/main/scala/org/apache/spark/memory/GlobalOffHeapMemory.scala: ########## @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.memory + +import org.apache.gluten.exception.GlutenException + +import org.apache.spark.{SparkEnv, TaskContext} +import org.apache.spark.storage.BlockId + +import java.lang.reflect.Field +import java.util.UUID + +object GlobalOffHeapMemory { + private val FIELD_MEMORY_MANAGER: Field = { + val f = classOf[TaskMemoryManager].getDeclaredField("memoryManager") Review Comment: should we guard on this, if this call on getField() may fail? ########## backends-velox/src/main/scala/org/apache/spark/memory/GlobalOffHeapMemory.scala: ########## @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.memory + +import org.apache.gluten.exception.GlutenException + +import org.apache.spark.{SparkEnv, TaskContext} +import org.apache.spark.storage.BlockId + +import java.lang.reflect.Field +import java.util.UUID + +object GlobalOffHeapMemory { + private val FIELD_MEMORY_MANAGER: Field = { + val f = classOf[TaskMemoryManager].getDeclaredField("memoryManager") + f.setAccessible(true) + f + } + + def acquire(numBytes: Long): Boolean = { + memoryManager().acquireStorageMemory( + BlockId(s"test_${UUID.randomUUID()}"), + numBytes, + MemoryMode.OFF_HEAP) + } + + def free(numBytes: Long): Unit = { + memoryManager().releaseStorageMemory(numBytes, MemoryMode.OFF_HEAP) + } + + private def memoryManager(): MemoryManager = { + val env = SparkEnv.get + if (env != null) { + return env.memoryManager Review Comment: If SparkEnv is not ready, then the following `TaskContext()` should not be ready too? ########## backends-velox/src/main/scala/org/apache/spark/memory/GlobalOffHeapMemory.scala: ########## @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.memory + +import org.apache.gluten.exception.GlutenException + +import org.apache.spark.{SparkEnv, TaskContext} +import org.apache.spark.storage.BlockId + +import java.lang.reflect.Field +import java.util.UUID + +object GlobalOffHeapMemory { + private val FIELD_MEMORY_MANAGER: Field = { + val f = classOf[TaskMemoryManager].getDeclaredField("memoryManager") + f.setAccessible(true) + f + } + + def acquire(numBytes: Long): Boolean = { Review Comment: will this also trigger OOM issue if not enough memory request? ########## backends-velox/src/main/scala/org/apache/spark/memory/GlobalOffHeapMemory.scala: ########## @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.memory + +import org.apache.gluten.exception.GlutenException + +import org.apache.spark.{SparkEnv, TaskContext} +import org.apache.spark.storage.BlockId + +import java.lang.reflect.Field +import java.util.UUID + +object GlobalOffHeapMemory { Review Comment: it seems we are allocating/free on the storage memory in this class, shall we rename with storagememory related? ########## backends-velox/src/main/scala/org/apache/spark/memory/GlobalOffHeapMemory.scala: ########## @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.spark.memory + +import org.apache.gluten.exception.GlutenException + +import org.apache.spark.{SparkEnv, TaskContext} +import org.apache.spark.storage.BlockId + +import java.lang.reflect.Field +import java.util.UUID + +object GlobalOffHeapMemory { + private val FIELD_MEMORY_MANAGER: Field = { + val f = classOf[TaskMemoryManager].getDeclaredField("memoryManager") + f.setAccessible(true) + f + } + + def acquire(numBytes: Long): Boolean = { + memoryManager().acquireStorageMemory( + BlockId(s"test_${UUID.randomUUID()}"), + numBytes, + MemoryMode.OFF_HEAP) Review Comment: it looks like we are using OFF_HEAP only, not sure if this will impact on the fallback case -- 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]
