Skip to content

Commit d182bdc

Browse files
committed
Merge pull request #8 from andrewor14/josh-unroll-tests
Rewrite some tests after changes in eviction
2 parents 0eac7da + 528cd85 commit d182bdc

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

core/src/test/scala/org/apache/spark/memory/StaticMemoryManagerSuite.scala

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,20 +148,26 @@ class StaticMemoryManagerSuite extends MemoryManagerSuite {
148148
val dummyBlock = TestBlockId("lonely water")
149149
val (mm, ms) = makeThings(Long.MaxValue, maxStorageMem)
150150
assert(mm.acquireUnrollMemory(dummyBlock, 100L, evictedBlocks))
151+
when(ms.currentUnrollMemory).thenReturn(100L)
151152
assertEvictBlocksToFreeSpaceNotCalled(ms)
152153
assert(mm.storageMemoryUsed === 100L)
153154
mm.releaseUnrollMemory(40L)
154155
assert(mm.storageMemoryUsed === 60L)
155156
when(ms.currentUnrollMemory).thenReturn(60L)
156-
assert(mm.acquireUnrollMemory(dummyBlock, 500L, evictedBlocks))
157-
// `spark.storage.unrollFraction` is 0.4, so the max unroll space is 400 bytes.
158-
// Since we already occupy 60 bytes, we will try to ensure only 400 - 60 = 340 bytes.
157+
assert(mm.acquireStorageMemory(dummyBlock, 800L, evictedBlocks))
159158
assertEvictBlocksToFreeSpaceNotCalled(ms)
160-
assert(mm.storageMemoryUsed === 560L)
161-
when(ms.currentUnrollMemory).thenReturn(560L)
159+
assert(mm.storageMemoryUsed === 860L)
160+
// `spark.storage.unrollFraction` is 0.4, so the max unroll space is 400 bytes.
161+
// Since we already occupy 60 bytes, we will try to evict only 400 - 60 = 340 bytes.
162162
assert(!mm.acquireUnrollMemory(dummyBlock, 800L, evictedBlocks))
163-
assert(mm.storageMemoryUsed === 560L)
164-
// We already have 560 bytes > the max unroll space of 400 bytes, so no bytes are freed
163+
assertEvictBlocksToFreeSpaceCalled(ms, 340L)
164+
assert(mm.storageMemoryUsed === 520L)
165+
// Acquire more unroll memory to exceed our "max unroll space"
166+
assert(mm.acquireUnrollMemory(dummyBlock, 440L, evictedBlocks))
167+
when(ms.currentUnrollMemory).thenReturn(500L)
168+
assert(mm.storageMemoryUsed === 960L)
169+
assert(!mm.acquireUnrollMemory(dummyBlock, 300L, evictedBlocks))
170+
// We already have 500 bytes > the max unroll space of 400 bytes, so no bytes are freed
165171
assertEvictBlocksToFreeSpaceNotCalled(ms)
166172
// Release beyond what was acquired
167173
mm.releaseUnrollMemory(maxStorageMem)

core/src/test/scala/org/apache/spark/memory/UnifiedMemoryManagerSuite.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ class UnifiedMemoryManagerSuite extends MemoryManagerSuite with PrivateMethodTes
131131
// Execution wants 200 bytes but only 150 are free, so storage is evicted
132132
assert(mm.acquireExecutionMemory(200L, taskAttemptId, MemoryMode.ON_HEAP) === 200L)
133133
assert(mm.executionMemoryUsed === 300L)
134+
assert(mm.storageMemoryUsed === 700L)
134135
assertEvictBlocksToFreeSpaceCalled(ms, 50L)
135-
assert(mm.executionMemoryUsed === 300L)
136136
assert(evictedBlocks.nonEmpty)
137137
mm.releaseAllStorageMemory()
138138
evictedBlocks.clear()
@@ -152,18 +152,21 @@ class UnifiedMemoryManagerSuite extends MemoryManagerSuite with PrivateMethodTes
152152
assert(evictedBlocks.isEmpty)
153153
}
154154

155-
test("execution can evict storage blocks when storage memory is below max mem (SPARK-12165)") {
155+
test("execution memory requests smaller than free memory should evict storage (SPARK-12165)") {
156156
val maxMemory = 1000L
157157
val taskAttemptId = 0L
158158
val (mm, ms) = makeThings(maxMemory)
159159
// Acquire enough storage memory to exceed the storage region size
160-
assert(mm.acquireStorageMemory(dummyBlock, 750L, evictedBlocks))
160+
assert(mm.acquireStorageMemory(dummyBlock, 700L, evictedBlocks))
161161
assertEvictBlocksToFreeSpaceNotCalled(ms)
162162
assert(mm.executionMemoryUsed === 0L)
163-
assert(mm.storageMemoryUsed === 750L)
164-
// Should now be able to require up to 500 bytes of memory
163+
assert(mm.storageMemoryUsed === 700L)
164+
// SPARK-12165: previously, MemoryStore would not evict anything because it would
165+
// mistakenly think that the 300 bytes of free space was still available even after
166+
// using it to expand the execution pool. Consequently, no storage memory was released
167+
// and the following call granted only 300 bytes to execution.
165168
assert(mm.acquireExecutionMemory(500L, taskAttemptId, MemoryMode.ON_HEAP) === 500L)
166-
assertEvictBlocksToFreeSpaceCalled(ms, 250L)
169+
assertEvictBlocksToFreeSpaceCalled(ms, 200L)
167170
assert(mm.storageMemoryUsed === 500L)
168171
assert(mm.executionMemoryUsed === 500L)
169172
assert(evictedBlocks.nonEmpty)

0 commit comments

Comments
 (0)