Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-26539][CORE] Remove spark.memory.useLegacyMode and StaticMemoryManager #23457

Closed
wants to merge 2 commits into from

Conversation

srowen
Copy link
Member

@srowen srowen commented Jan 4, 2019

What changes were proposed in this pull request?

Remove spark.memory.useLegacyMode and StaticMemoryManager. Update tests that used the StaticMemoryManager to equivalent use of UnifiedMemoryManager.

How was this patch tested?

Existing tests, with modifications to make them work with a different mem manager.

@@ -45,7 +45,7 @@ import org.apache.spark.storage.BlockId
* it if necessary. Cached blocks can be evicted only if actual
* storage memory usage exceeds this region.
*/
private[spark] class UnifiedMemoryManager private[memory] (
private[spark] class UnifiedMemoryManager(
Copy link
Member Author

Choose a reason for hiding this comment

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

Tests and other internals now need to use this constructor directly

@@ -61,7 +60,7 @@ class MemoryStoreSuite
}

def makeMemoryStore(maxMem: Long): (MemoryStore, BlockInfoManager) = {
val memManager = new StaticMemoryManager(conf, Long.MaxValue, maxMem, numCores = 1)
val memManager = new UnifiedMemoryManager(conf, maxMem, (0.4 * maxMem).toInt, 1)
Copy link
Member Author

Choose a reason for hiding this comment

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

This mimics the behavior of the old memory manager with spark.storage.unrollFraction=0.4

val result4 = putIteratorAsBytes("b4", bigIterator, ClassTag.Any)
assert(result4.isLeft) // unroll was unsuccessful
assert(!memoryStore.contains("b1"))
assert(!memoryStore.contains("b2"))
assert(memoryStore.contains("b2")) // not necessarily evicted
Copy link
Member Author

Choose a reason for hiding this comment

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

This behavior changed after the change above. However, I am not sure this assertion is correct? there are 4800 bytes available. b2 takes 400. An attempt to put 4000 may fail (? well that was the previous and current behavior, anyway), but I don't see that it necessarily requires evicting b2; the allocation failed. We've recently had a very similar discussion about a different change that also uncovered this assertion as an issue.

Copy link
Member

Choose a reason for hiding this comment

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

isn't b2 takes 4000 and b4 takes 40000 ?

I verified the test and I think the assertion is correct.

Actually, for current behaviour with UnifiedMemoryManager, there may be 12000 bytes available. When we try to put b4 into memory, it will require 24064 memory once it unrolled 16 elements (which hit the memoryCheckPeriod for first time). And 24064 bytes exceed the maxMemory of 12000, so, it would just return instread of evicting any blocks.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops yes b2 takes 4000 and b4 40000. OK, certainly b4 can't fit. Yes on thinking this through a second time, this isn't quite the right change. The difference between total and storage memory in the unified memory manager is irrelevant here. It's just that this test needs less total memory available -- a little more than 8000 bytes, not 12000. Let me push a fix.

.set("spark.memory.useLegacyMode", "true")
.set("spark.testing.memory", "100000000")
.set("spark.memory.storageFraction", "0.999")
.set("spark.testing.memory", "471859200")
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the minimum allowed value. The new setting 0.999 mimics having almost no shuffle memory

@SparkQA
Copy link

SparkQA commented Jan 5, 2019

Test build #100757 has finished for PR 23457 at commit 40e4209.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

Copy link
Member

@Ngone51 Ngone51 left a comment

Choose a reason for hiding this comment

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

Pretty Cool!

@@ -61,15 +61,10 @@ package org.apache.spark
* }}}
*
*
* There are two implementations of [[org.apache.spark.memory.MemoryManager]] which vary in how
* they handle the sizing of their memory pools:
* There is one implementations of [[org.apache.spark.memory.MemoryManager]]:
Copy link
Member

Choose a reason for hiding this comment

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

nit: implementations -> implementation

val result4 = putIteratorAsBytes("b4", bigIterator, ClassTag.Any)
assert(result4.isLeft) // unroll was unsuccessful
assert(!memoryStore.contains("b1"))
assert(!memoryStore.contains("b2"))
assert(memoryStore.contains("b2")) // not necessarily evicted
Copy link
Member

Choose a reason for hiding this comment

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

isn't b2 takes 4000 and b4 takes 40000 ?

I verified the test and I think the assertion is correct.

Actually, for current behaviour with UnifiedMemoryManager, there may be 12000 bytes available. When we try to put b4 into memory, it will require 24064 memory once it unrolled 16 elements (which hit the memoryCheckPeriod for first time). And 24064 bytes exceed the maxMemory of 12000, so, it would just return instread of evicting any blocks.

@SparkQA
Copy link

SparkQA commented Jan 5, 2019

Test build #100789 has finished for PR 23457 at commit f4ee34e.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@gatorsmile
Copy link
Member

cc @jiangxb1987

@SparkQA
Copy link

SparkQA commented Jan 8, 2019

Test build #100940 has finished for PR 23457 at commit 69ca3a9.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jan 9, 2019

Test build #4500 has finished for PR 23457 at commit 69ca3a9.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@@ -61,15 +61,10 @@ package org.apache.spark
* }}}
*
*
* There are two implementations of [[org.apache.spark.memory.MemoryManager]] which vary in how
* they handle the sizing of their memory pools:
* There is one implementation of [[org.apache.spark.memory.MemoryManager]]:
*
* - [[org.apache.spark.memory.UnifiedMemoryManager]], the default in Spark 1.6+, enforces soft
Copy link
Member

Choose a reason for hiding this comment

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

nit: since just one implementation now, still need to mention this is default?

@SparkQA
Copy link

SparkQA commented Jan 9, 2019

Test build #100973 has finished for PR 23457 at commit 9990796.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@srowen
Copy link
Member Author

srowen commented Jan 10, 2019

Merged to master

@srowen srowen closed this in 2f8a938 Jan 10, 2019
@srowen srowen deleted the SPARK-26539 branch January 21, 2019 17:57
@@ -29,7 +29,7 @@
@Test
public void leakedPageMemoryIsDetected() {
final TaskMemoryManager manager = new TaskMemoryManager(
new StaticMemoryManager(
new UnifiedMemoryManager(
new SparkConf().set("spark.memory.offHeap.enabled", "false"),
Long.MAX_VALUE,
Long.MAX_VALUE,
Copy link
Member

Choose a reason for hiding this comment

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

What does these mean after the change?

maxHeapMemory = Long.MAX_VALUE and onHeapStorageRegionSize = Long.MAX_VALUE?

@@ -60,7 +59,7 @@ class MemoryStoreSuite
}

def makeMemoryStore(maxMem: Long): (MemoryStore, BlockInfoManager) = {
val memManager = new StaticMemoryManager(conf, Long.MaxValue, maxMem, numCores = 1)
val memManager = new UnifiedMemoryManager(conf, maxMem, maxMem, 1)
Copy link
Member

Choose a reason for hiding this comment

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

The same question here

@gatorsmile
Copy link
Member

Is it fine to simply replace it? Basically, the cases I pointed out above change the semantics. That means, onHeapExecutionMemory will be zero, if maxHeapMemory and onHeapStorageRegionSize are the same.

@srowen
Copy link
Member Author

srowen commented Jan 25, 2019

You're right, the semantics are different, but I don't think they matter in the test context here. It is probably more accurate to pass something like (maxHeapMemory, maxHeapMemory / 2). The tests pass, at least, because I believe they don't care about execution memory, which is 0.

@gatorsmile
Copy link
Member

gatorsmile commented Jan 25, 2019

Opened a ticket https://issues.apache.org/jira/browse/SPARK-26725 I think we should not write an invalid inputs in the test cases.

@@ -94,7 +94,7 @@ private[execution] object HashedRelation {
taskMemoryManager: TaskMemoryManager = null): HashedRelation = {
val mm = Option(taskMemoryManager).getOrElse {
new TaskMemoryManager(
new StaticMemoryManager(
new UnifiedMemoryManager(
new SparkConf().set(MEMORY_OFFHEAP_ENABLED.key, "false"),
Long.MaxValue,
Long.MaxValue,
Copy link
Member

Choose a reason for hiding this comment

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

How about these?

cloud-fan pushed a commit that referenced this pull request Jan 28, 2019
…tructor in test suites

## What changes were proposed in this pull request?

Adjust mem settings in UnifiedMemoryManager used in test suites to ha…ve execution memory > 0
Ref: #23457 (comment)

## How was this patch tested?

Existing tests

Closes #23645 from srowen/SPARK-26725.

Authored-by: Sean Owen <sean.owen@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
jackylee-ch pushed a commit to jackylee-ch/spark that referenced this pull request Feb 18, 2019
…yManager

## What changes were proposed in this pull request?

Remove spark.memory.useLegacyMode and StaticMemoryManager. Update tests that used the StaticMemoryManager to equivalent use of UnifiedMemoryManager.

## How was this patch tested?

Existing tests, with modifications to make them work with a different mem manager.

Closes apache#23457 from srowen/SPARK-26539.

Authored-by: Sean Owen <sean.owen@databricks.com>
Signed-off-by: Sean Owen <sean.owen@databricks.com>
jackylee-ch pushed a commit to jackylee-ch/spark that referenced this pull request Feb 18, 2019
…tructor in test suites

## What changes were proposed in this pull request?

Adjust mem settings in UnifiedMemoryManager used in test suites to ha…ve execution memory > 0
Ref: apache#23457 (comment)

## How was this patch tested?

Existing tests

Closes apache#23645 from srowen/SPARK-26725.

Authored-by: Sean Owen <sean.owen@databricks.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants