Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private[spark] abstract class MemoryManager(
* by looking at the number of cores available to the process, and the total amount of memory,
* and then divide it by a factor of safety.
*
* SPARK-37593 If we are using G1GC, it's better to take the LONG_ARRAY_OFFSET
* SPARK-37593 If we are using G1GC or ZGC, 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 heap region size to reduce memory waste within one G1 region.
*/
Expand All @@ -260,7 +260,7 @@ private[spark] abstract class MemoryManager(
}
val size = ByteArrayMethods.nextPowerOf2(maxTungstenMemory / cores / safetyFactor)
val chosenPageSize = math.min(maxPageSize, math.max(minPageSize, size))
if (Utils.isG1GC && tungstenMemoryMode == MemoryMode.ON_HEAP) {
if ((Utils.isG1GC || Utils.isZGC) && tungstenMemoryMode == MemoryMode.ON_HEAP) {
chosenPageSize - Platform.LONG_ARRAY_OFFSET
} else {
chosenPageSize
Expand Down
15 changes: 11 additions & 4 deletions core/src/main/scala/org/apache/spark/util/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3138,7 +3138,14 @@ private[spark] object Utils
/**
* Return whether we are using G1GC or not
*/
lazy val isG1GC: Boolean = {
lazy val isG1GC: Boolean = checkUseGC("UseG1GC")

/**
* Return whether we are using ZGC or not
*/
lazy val isZGC: Boolean = checkUseGC("UseZGC")

def checkUseGC(useGCObjectStr: String): Boolean = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @wankunde . Thank you for making a PR. Could you spin off this contribution? This sounds like a good idea to add a general utility function to detect GCs. We can proceed this one first.

As @pan3793 mentioned, if you can generalize more to detect other GCs, it would be a perfect contribution.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your review. For this PR, I will only add a function to detect GCs for G1, ZGC and ShenandoahGC

Try {
val clazz = Utils.classForName("com.sun.management.HotSpotDiagnosticMXBean")
.asInstanceOf[Class[_ <: PlatformManagedObject]]
Expand All @@ -3147,9 +3154,9 @@ private[spark] object Utils
val vmOptionMethod = clazz.getMethod("getVMOption", classOf[String])
val valueMethod = vmOptionClazz.getMethod("getValue")

val useG1GCObject = vmOptionMethod.invoke(hotSpotDiagnosticMXBean, "UseG1GC")
val useG1GC = valueMethod.invoke(useG1GCObject).asInstanceOf[String]
"true".equals(useG1GC)
val useGCObject = vmOptionMethod.invoke(hotSpotDiagnosticMXBean, useGCObjectStr)
val useGC = valueMethod.invoke(useGCObject).asInstanceOf[String]
"true".equals(useGC)
}.getOrElse(false)
}

Expand Down