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/09 10:35:52 UTC

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

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



##########
File path: core/src/main/scala/org/apache/spark/util/Utils.scala
##########
@@ -3204,6 +3205,27 @@ private[spark] object Utils extends Logging {
     }
     files.toSeq
   }
+
+  private def isG1GarbageCollector: Boolean = {
+    val gcs = ManagementFactory.getGarbageCollectorMXBeans.asScala
+    gcs.exists(_.getName.equalsIgnoreCase("G1 Young Generation")) ||
+      gcs.exists(_.getName.equalsIgnoreCase("G1 Old Generation"))
+  }
+
+  /**
+   * Return true if current GC algorithm is G1 GC and the requested sizeInBytes
+   * are larger than 50% of the region size in G1.
+   */
+  def isHumongousAllocation(sizeInBytes: Long): Boolean = {
+    if (isG1GarbageCollector) {
+      val heapRegionSize = ManagementFactory
+        .getPlatformMXBean(classOf[HotSpotDiagnosticMXBean])
+        .getVMOption("G1HeapRegionSize").getValue.toLong

Review comment:
       I am afraid that this line may throw an exception in the future due to specification changes.   
   How about wrapping this by `try ... catch`? 




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