Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -125,6 +125,16 @@ private[execution] sealed trait HashedRelation extends KnownSizeEstimation {

private[execution] object HashedRelation {

def createTaskMemoryManager(): TaskMemoryManager = {
new TaskMemoryManager(
new UnifiedMemoryManager(
new SparkConf().set(MEMORY_OFFHEAP_ENABLED.key, "false"),
Runtime.getRuntime.maxMemory,
Runtime.getRuntime.maxMemory / 2,
1),
0)
}

/**
* Create a HashedRelation from an Iterator of InternalRow.
*
Expand All @@ -142,13 +152,7 @@ private[execution] object HashedRelation {
allowsNullKey: Boolean = false,
ignoresDuplicatedKey: Boolean = false): HashedRelation = {
val mm = Option(taskMemoryManager).getOrElse {
new TaskMemoryManager(
new UnifiedMemoryManager(
new SparkConf().set(MEMORY_OFFHEAP_ENABLED.key, "false"),
Runtime.getRuntime.maxMemory,
Runtime.getRuntime.maxMemory / 2,
1),
0)
createTaskMemoryManager()
}

if (!input.hasNext && !allowsNullKey) {
Expand Down Expand Up @@ -400,13 +404,7 @@ private[joins] class UnsafeHashedRelation(
// This is used in Broadcast, shared by multiple tasks, so we use on-heap memory
// TODO(josh): This needs to be revisited before we merge this patch; making this change now
// so that tests compile:
val taskMemoryManager = new TaskMemoryManager(
new UnifiedMemoryManager(
new SparkConf().set(MEMORY_OFFHEAP_ENABLED.key, "false"),
Runtime.getRuntime.maxMemory,
Runtime.getRuntime.maxMemory / 2,
1),
0)
val taskMemoryManager = HashedRelation.createTaskMemoryManager()

val pageSizeBytes = Option(SparkEnv.get).map(_.memoryManager.pageSizeBytes)
.getOrElse(new SparkConf().get(BUFFER_PAGESIZE).getOrElse(16L * 1024 * 1024))
Expand Down Expand Up @@ -574,15 +572,7 @@ private[execution] final class LongToUnsafeRowMap(

// needed by serializer
def this() = {
this(
new TaskMemoryManager(
new UnifiedMemoryManager(
new SparkConf().set(MEMORY_OFFHEAP_ENABLED.key, "false"),
Runtime.getRuntime.maxMemory,
Runtime.getRuntime.maxMemory / 2,
1),
0),
0)
this(HashedRelation.createTaskMemoryManager(), 0)
}

private def init(): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import org.apache.spark.SparkConf
import org.apache.spark.SparkException
import org.apache.spark.internal.config.{MEMORY_OFFHEAP_ENABLED, MEMORY_OFFHEAP_SIZE}
import org.apache.spark.internal.config.Kryo._
import org.apache.spark.memory.{TaskMemoryManager, UnifiedMemoryManager}
import org.apache.spark.memory.{TaskMemoryManager, TestMemoryConsumer, UnifiedMemoryManager}
import org.apache.spark.network.util.ByteUnit
import org.apache.spark.serializer.KryoSerializer
import org.apache.spark.sql.catalyst.InternalRow
Expand Down Expand Up @@ -758,6 +758,13 @@ abstract class HashedRelationSuite extends SharedSparkSession {
map.free()
}
}

test("Verify TaskMemoryManager creation") {
val taskMemoryManager = HashedRelation.createTaskMemoryManager()
val testMemoryConsumer = new TestMemoryConsumer(taskMemoryManager)
val memoryPage = taskMemoryManager.allocatePage(100, testMemoryConsumer)
assert(memoryPage.size() > 0)
}
}

class HashedRelationOnHeapSuite extends HashedRelationSuite {
Expand Down