Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
b7c9c23
Move Unsafe mem. mgrs. to spark-core subproject.
JoshRosen Oct 14, 2015
25ba4b5
Merge ExecutorMemoryManager into MemoryManager.
JoshRosen Oct 14, 2015
3d997ce
Naming and formatting fixes.
JoshRosen Oct 16, 2015
d9e6b84
Move Tungsten-related methods to end of MemoryManager file.
JoshRosen Oct 16, 2015
98ef86b
Add taskAttemptId to TaskMemoryManager constructor.
JoshRosen Oct 16, 2015
8f93e94
Move ShuffleMemoryManager into memory package.
JoshRosen Oct 16, 2015
3bbc54d
Merge remote-tracking branch 'origin/master' into SPARK-10984
JoshRosen Oct 16, 2015
88a7970
Fix bug in AbstractBytesToBytesMapSuite.
JoshRosen Oct 16, 2015
ec48ff9
Refactor the existing Tungsten TaskMemoryManager interactions so Tung…
JoshRosen Oct 16, 2015
6f98bc4
Move TaskMemoryManager from unsafe to memory.
JoshRosen Oct 16, 2015
6459397
Further minimization of ShuffleMemoryManager usage.
JoshRosen Oct 16, 2015
60c66b2
Merge ShuffleMemoryManager into MemoryManager.
JoshRosen Oct 17, 2015
7d6a37f
Clean up interaction between TaskMemoryManager and MemoryManager.
JoshRosen Oct 17, 2015
0dc21dc
Merge remote-tracking branch 'origin/master' into SPARK-10984
JoshRosen Oct 22, 2015
f21b767
Fix compilation.
JoshRosen Oct 22, 2015
46ad693
Fix Scalastyle
JoshRosen Oct 22, 2015
c33e330
Fix import ordering in Executor.scala
JoshRosen Oct 22, 2015
ef45d91
Fix import ordering in Task.scala
JoshRosen Oct 22, 2015
c7eac69
Fix import ordering in TaskContextImpl
JoshRosen Oct 22, 2015
d86f435
Fix spillable collection tests
JoshRosen Oct 22, 2015
bba5550
Integrate TaskMemoryManager acquire/releasePage with MemoryManager bo…
JoshRosen Oct 22, 2015
66ae259
Move pooling logic into allocators themselves.
JoshRosen Oct 22, 2015
b1d5151
Scaladoc updates.
JoshRosen Oct 22, 2015
d0c0dd9
Update Spillable to properly integrate with TaskMemoryManager.
JoshRosen Oct 22, 2015
48149fc
Move pageSizeBytes to Tungsten section
JoshRosen Oct 23, 2015
c8ba196
Cleanup after merging of ShuffleMemoryManager into MemoryManager.
JoshRosen Oct 23, 2015
63a6cbc
Rename getMemoryConsumptionForThisTask to getExecutionMemoryUsageForTask
JoshRosen Oct 23, 2015
6ec9c30
Properly thread numCores to memory manager.
JoshRosen Oct 23, 2015
1593fad
Explain why MemoryBlock.pageNumber is public
JoshRosen Oct 23, 2015
64bec0b
Fix TaskMemoryManagerSuite tests.
JoshRosen Oct 23, 2015
f9240e9
Fix compilation
JoshRosen Oct 23, 2015
a95bc08
Fix a memory leak in UnsafeShuffleWriter's sorter
JoshRosen Oct 23, 2015
b3ad761
Remove println
JoshRosen Oct 23, 2015
a7e8320
Fix Scalastyle.
JoshRosen Oct 23, 2015
e874a45
Fix remaining TODOs in UnsafeShuffleWriterSuite.
JoshRosen Oct 23, 2015
2ba6e51
Fix DeveloperAPI change
JoshRosen Oct 23, 2015
0c13723
Address comments in MemoryManager
JoshRosen Oct 23, 2015
04ec429
Release memory acquired after unsuccessful allocatePage() call
JoshRosen Oct 23, 2015
e56d039
Fix EAOM compilation.
JoshRosen Oct 23, 2015
aa14113
Port tests from ShuffleMemoryManagerSuite
JoshRosen Oct 23, 2015
7addf8b
Remove unused non-page-memory allocation methods.
JoshRosen Oct 23, 2015
5af0b17
Update Tungsten tests
JoshRosen Oct 23, 2015
a264703
Fix execution memory leaks in Spillable collections
JoshRosen Oct 24, 2015
f2ab708
Fix NPE in UnsafeRowSerializerSuite
JoshRosen Oct 24, 2015
0b5c72f
Update EAOM tests to reflect fact that iterator() is destructive.
JoshRosen Oct 24, 2015
f68fdb1
Fix streaming test compilation
JoshRosen Oct 26, 2015
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
Prev Previous commit
Next Next commit
Update Tungsten tests
  • Loading branch information
JoshRosen committed Oct 23, 2015
commit 5af0b17803dd33051daafdffae069b0f38c13495
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ public abstract class AbstractBytesToBytesMapSuite {

private final Random rand = new Random(42);

private GrantEverythingMemoryManager memoryManager;
private TaskMemoryManager taskMemoryManager;
private final long PAGE_SIZE_BYTES = 1L << 26; // 64 megabytes

@Before
public void setup() {
taskMemoryManager = new TaskMemoryManager(
memoryManager =
new GrantEverythingMemoryManager(
new SparkConf().set("spark.unsafe.offHeap", "" + useOffHeapMemoryAllocator())), 0);
new SparkConf().set("spark.unsafe.offHeap", "" + useOffHeapMemoryAllocator()));
taskMemoryManager = new TaskMemoryManager(memoryManager, 0);
}

@After
Expand Down Expand Up @@ -413,8 +415,9 @@ public void randomizedTestWithRecordsLargerThanPageSize() {

@Test
public void failureToAllocateFirstPage() {
// TODO(josh) shuffleMemoryManager = ShuffleMemoryManager.createForTesting(1024);
memoryManager.markExecutionAsOutOfMemory();
BytesToBytesMap map = new BytesToBytesMap(taskMemoryManager, 1, PAGE_SIZE_BYTES);
memoryManager.markExecutionAsOutOfMemory();
try {
final long[] emptyArray = new long[0];
final BytesToBytesMap.Location loc =
Expand All @@ -430,12 +433,14 @@ public void failureToAllocateFirstPage() {

@Test
public void failureToGrow() {
// TODO(josh) shuffleMemoryManager = ShuffleMemoryManager.createForTesting(1024 * 10);
BytesToBytesMap map = new BytesToBytesMap(taskMemoryManager, 1, 1024);
try {
boolean success = true;
int i;
for (i = 0; i < 1024; i++) {
for (i = 0; i < 127; i++) {
if (i > 0) {
memoryManager.markExecutionAsOutOfMemory();
}
final long[] arr = new long[]{i};
final BytesToBytesMap.Location loc = map.lookup(arr, Platform.LONG_ARRAY_OFFSET, 8);
success =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@
public class UnsafeExternalSorterSuite {

final LinkedList<File> spillFilesCreated = new LinkedList<File>();
final TaskMemoryManager taskMemoryManager = new TaskMemoryManager(
new GrantEverythingMemoryManager(new SparkConf().set("spark.unsafe.offHeap", "false")), 0);
final GrantEverythingMemoryManager memoryManager =
new GrantEverythingMemoryManager(new SparkConf().set("spark.unsafe.offHeap", "false"));
final TaskMemoryManager taskMemoryManager = new TaskMemoryManager(memoryManager, 0);
// Use integer comparison for comparing prefixes (which are partition ids, in this case)
final PrefixComparator prefixComparator = new PrefixComparator() {
@Override
Expand Down Expand Up @@ -225,12 +226,16 @@ public void testSortingEmptyArrays() throws Exception {

@Test
public void spillingOccursInResponseToMemoryPressure() throws Exception {
// TODO(josh): shuffleMemoryManager = ShuffleMemoryManager.create(pageSizeBytes * 2, pageSizeBytes);
final UnsafeExternalSorter sorter = newSorter();
final int numRecords = (int) pageSizeBytes / 4;
for (int i = 0; i <= numRecords; i++) {
// This should be enough records to completely fill up a data page:
final int numRecords = (int) (pageSizeBytes / (4 + 4));
for (int i = 0; i < numRecords; i++) {
insertNumber(sorter, numRecords - i);
}
assertEquals(1, sorter.getNumberOfAllocatedPages());
memoryManager.markExecutionAsOutOfMemory();
// The insertion of this record should trigger a spill:
insertNumber(sorter, 0);
// Ensure that spill files were created
assertThat(tempDir.listFiles().length, greaterThanOrEqualTo(1));
// Read back the sorted data:
Expand All @@ -244,6 +249,7 @@ public void spillingOccursInResponseToMemoryPressure() throws Exception {
assertEquals(i, Platform.getInt(iter.getBaseObject(), iter.getBaseOffset()));
i++;
}
assertEquals(numRecords + 1, i);
sorter.cleanupResources();
assertSpillFilesWereCleanedUp();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,31 @@ import org.apache.spark.storage.{BlockStatus, BlockId}

class GrantEverythingMemoryManager(conf: SparkConf) extends MemoryManager(conf, numCores = 1) {
private[memory] override def doAcquireExecutionMemory(
numBytes: Long,
evictedBlocks: mutable.Buffer[(BlockId, BlockStatus)]): Long = numBytes
numBytes: Long,
evictedBlocks: mutable.Buffer[(BlockId, BlockStatus)]): Long = synchronized {
if (oom) {
oom = false
0
} else {
_executionMemoryUsed += numBytes // To suppress warnings when freeing unallocated memory
numBytes
}
}
override def acquireStorageMemory(
blockId: BlockId,
numBytes: Long,
evictedBlocks: mutable.Buffer[(BlockId, BlockStatus)]): Boolean = true
blockId: BlockId,
numBytes: Long,
evictedBlocks: mutable.Buffer[(BlockId, BlockStatus)]): Boolean = true
override def acquireUnrollMemory(
blockId: BlockId,
numBytes: Long,
evictedBlocks: mutable.Buffer[(BlockId, BlockStatus)]): Boolean = true
blockId: BlockId,
numBytes: Long,
evictedBlocks: mutable.Buffer[(BlockId, BlockStatus)]): Boolean = true
override def releaseStorageMemory(numBytes: Long): Unit = { }
override def maxExecutionMemory: Long = Long.MaxValue
override def maxStorageMemory: Long = Long.MaxValue

private var oom = false

def markExecutionAsOutOfMemory(): Unit = {
oom = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class UnsafeFixedWidthAggregationMapSuite
private def emptyAggregationBuffer: InternalRow = InternalRow(0)
private val PAGE_SIZE_BYTES: Long = 1L << 26; // 64 megabytes

private var memoryManager: GrantEverythingMemoryManager = null
private var taskMemoryManager: TaskMemoryManager = null

def testWithMemoryLeakDetection(name: String)(f: => Unit) {
Expand All @@ -61,7 +62,8 @@ class UnsafeFixedWidthAggregationMapSuite

test(name) {
val conf = new SparkConf().set("spark.unsafe.offHeap", "false")
taskMemoryManager = new TaskMemoryManager(new GrantEverythingMemoryManager(conf), 0)
memoryManager = new GrantEverythingMemoryManager(conf)
taskMemoryManager = new TaskMemoryManager(memoryManager, 0)

TaskContext.setTaskContext(new TaskContextImpl(
stageId = 0,
Expand Down Expand Up @@ -206,7 +208,7 @@ class UnsafeFixedWidthAggregationMapSuite
sorter.insertKV(keyConverter.apply(k), valueConverter.apply(v))

if ((i % 100) == 0) {
// TODO(josh): Fix shuffleMemoryManager.markAsOutOfMemory()
memoryManager.markExecutionAsOutOfMemory()
sorter.closeCurrentPage()
}
}
Expand Down Expand Up @@ -249,7 +251,7 @@ class UnsafeFixedWidthAggregationMapSuite
sorter.insertKV(keyConverter.apply(k), valueConverter.apply(v))

if ((i % 100) == 0) {
// TODO(josh): FIX shuffleMemoryManager.markAsOutOfMemory()
memoryManager.markExecutionAsOutOfMemory()
sorter.closeCurrentPage()
}
}
Expand Down Expand Up @@ -301,7 +303,7 @@ class UnsafeFixedWidthAggregationMapSuite
sorter.insertKV(UnsafeRow.createFromByteArray(0, 0), UnsafeRow.createFromByteArray(0, 0))

if ((i % 100) == 0) {
// TODO(josh): fix shuffleMemoryManager.markAsOutOfMemory()
memoryManager.markExecutionAsOutOfMemory()
sorter.closeCurrentPage()
}
}
Expand All @@ -322,34 +324,28 @@ class UnsafeFixedWidthAggregationMapSuite
}

testWithMemoryLeakDetection("convert to external sorter under memory pressure (SPARK-10474)") {
// TODO(josh) val smm = ShuffleMemoryManager.createForTesting(65536)
val pageSize = 4096
val map = new UnsafeFixedWidthAggregationMap(
emptyAggregationBuffer,
aggBufferSchema,
groupKeySchema,
taskMemoryManager,
// smm, // TODO(josh): needs to be updated.
128, // initial capacity
pageSize,
false // disable perf metrics
)

// Insert into the map until we've run out of space
val rand = new Random(42)
var hasSpace = true
while (hasSpace) {
for (i <- 1 to 100) {
val str = rand.nextString(1024)
val buf = map.getAggregationBuffer(InternalRow(UTF8String.fromString(str)))
if (buf == null) {
hasSpace = false
} else {
buf.setInt(0, str.length)
}
buf.setInt(0, str.length)
}

// Ensure we're actually maxed out by asserting that we can't acquire even just 1 byte
// TODO(josh): fix assert(smm.tryToAcquire(1) === 0)
// Simulate running out of space
memoryManager.markExecutionAsOutOfMemory()
val str = rand.nextString(1024)
val buf = map.getAggregationBuffer(InternalRow(UTF8String.fromString(str)))
assert(buf == null)

// Convert the map into a sorter. This used to fail before the fix for SPARK-10474
// because we would try to acquire space for the in-memory sorter pointer array before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ class UnsafeKVExternalSorterSuite extends SparkFunSuite with SharedSQLContext {
inputData: Seq[(InternalRow, InternalRow)],
pageSize: Long,
spill: Boolean): Unit = {

val taskMemMgr = new TaskMemoryManager(
new GrantEverythingMemoryManager(new SparkConf().set("spark.unsafe.offHeap", "false")), 0)
val memoryManager =
new GrantEverythingMemoryManager(new SparkConf().set("spark.unsafe.offHeap", "false"))
val taskMemMgr = new TaskMemoryManager(memoryManager, 0)
TaskContext.setTaskContext(new TaskContextImpl(
stageId = 0,
partitionId = 0,
Expand All @@ -128,7 +128,7 @@ class UnsafeKVExternalSorterSuite extends SparkFunSuite with SharedSQLContext {
sorter.insertKV(k.asInstanceOf[UnsafeRow], v.asInstanceOf[UnsafeRow])
// 1% chance we will spill
if (rand.nextDouble() < 0.01 && spill) {
// shuffleMemMgr.markAsOutOfMemory() // TODO(josh): update this test
memoryManager.markExecutionAsOutOfMemory()
sorter.closeCurrentPage()
}
}
Expand Down