You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/12/15 14:53:04 UTC

[GitHub] [spark] WangGuangxin commented on a change in pull request #34846: [SPARK-37593][CORE] Optimize HeapMemoryAllocator to avoid memory waste when using G1GC

WangGuangxin commented on a change in pull request #34846:
URL: https://github.com/apache/spark/pull/34846#discussion_r769700852



##########
File path: core/src/main/scala/org/apache/spark/memory/MemoryManager.scala
##########
@@ -255,7 +256,17 @@ private[spark] abstract class MemoryManager(
     }
     val size = ByteArrayMethods.nextPowerOf2(maxTungstenMemory / cores / safetyFactor)
     val default = math.min(maxPageSize, math.max(minPageSize, size))
-    conf.get(BUFFER_PAGESIZE).getOrElse(default)
+    val sizeAsBytes = conf.get(BUFFER_PAGESIZE).getOrElse(default)
+    // If we are using G1 GC, it's better to take the LONG_ARRAY_OFFSET into consideration
+    // so that the requested memory size is power of 2 and can be divided by G1 region size
+    // to reduce memory waste within one G1 region
+    if (Utils.isG1GarbageCollector &&
+      tungstenMemoryMode == MemoryMode.ON_HEAP &&
+      sizeAsBytes % (1024 * 1024) == 0) {
+      sizeAsBytes - Platform.LONG_ARRAY_OFFSET

Review comment:
       I see what you mean, you are right




-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org