-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-12081] Make unified memory manager work with small heaps #10081
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,7 @@ import org.apache.spark.storage.{BlockStatus, BlockId} | |
| * A [[MemoryManager]] that enforces a soft boundary between execution and storage such that | ||
| * either side can borrow memory from the other. | ||
| * | ||
| * The region shared between execution and storage is a fraction of the total heap space | ||
| * The region shared between execution and storage is a fraction of (the total heap space - 300MB) | ||
| * configurable through `spark.memory.fraction` (default 0.75). The position of the boundary | ||
| * within this space is further determined by `spark.memory.storageFraction` (default 0.5). | ||
| * This means the size of the storage region is 0.75 * 0.5 = 0.375 of the heap space by default. | ||
|
|
@@ -48,7 +48,7 @@ import org.apache.spark.storage.{BlockStatus, BlockId} | |
| */ | ||
| private[spark] class UnifiedMemoryManager private[memory] ( | ||
| conf: SparkConf, | ||
| maxMemory: Long, | ||
| val maxMemory: Long, | ||
| private val storageRegionSize: Long, | ||
| numCores: Int) | ||
| extends MemoryManager( | ||
|
|
@@ -130,6 +130,12 @@ private[spark] class UnifiedMemoryManager private[memory] ( | |
|
|
||
| object UnifiedMemoryManager { | ||
|
|
||
| // Set aside a fixed amount of memory for non-storage, non-execution purposes. | ||
| // This serves a function similar to `spark.memory.fraction`, but guarantees that we reserve | ||
| // sufficient memory for the system even for small heaps. E.g. if we have a 1GB JVM, then | ||
| // the memory used for execution and storage will be (1024 - 300) * 0.75 = 543MB by default. | ||
| private val RESERVED_SYSTEM_MEMORY_BYTES = 300 * 1024 * 1024 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For non-small heap, the above memory doesn't need to be reserved, right ? |
||
|
|
||
| def apply(conf: SparkConf, numCores: Int): UnifiedMemoryManager = { | ||
| val maxMemory = getMaxMemory(conf) | ||
| new UnifiedMemoryManager( | ||
|
|
@@ -144,8 +150,16 @@ object UnifiedMemoryManager { | |
| * Return the total amount of memory shared between execution and storage, in bytes. | ||
| */ | ||
| private def getMaxMemory(conf: SparkConf): Long = { | ||
| val systemMaxMemory = conf.getLong("spark.testing.memory", Runtime.getRuntime.maxMemory) | ||
| val systemMemory = conf.getLong("spark.testing.memory", Runtime.getRuntime.maxMemory) | ||
| val reservedMemory = conf.getLong("spark.testing.reservedMemory", | ||
| if (conf.contains("spark.testing")) 0 else RESERVED_SYSTEM_MEMORY_BYTES) | ||
| val minSystemMemory = reservedMemory * 1.5 | ||
| if (systemMemory < minSystemMemory) { | ||
| throw new IllegalArgumentException(s"System memory $systemMemory must " + | ||
| s"be at least $minSystemMemory. Please use a larger heap size.") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comes out as scientific notation, which made me laugh. |
||
| } | ||
| val usableMemory = systemMemory - reservedMemory | ||
| val memoryFraction = conf.getDouble("spark.memory.fraction", 0.75) | ||
| (systemMaxMemory * memoryFraction).toLong | ||
| (usableMemory * memoryFraction).toLong | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should document what this is and update the classdoc for UnifiedMemoryManager