-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-10956] Common MemoryManager interface for storage and execution #9000
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
Changes from 1 commit
9e73981
b5df241
700e5d1
933de61
e73e463
52e2014
88faede
5c74063
0bf0d94
b1e8fd1
adb1764
6e2e870
b0af4d2
1ef313c
9de2e20
fc7f9f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
This commit does not represent any change in behavior. The MemoryManager's introduced are not actually used anywhere yet. This will come in the next commit.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark | ||
|
|
||
| /** | ||
| * An abstract memory manager that enforces how memory is shared between execution and storage. | ||
| * | ||
| * In this context, execution memory refers to that used for computation in shuffles, joins, | ||
| * sorts and aggregations, while storage memory refers to that used for caching and propagating | ||
| * internal data across the cluster. | ||
| */ | ||
| private[spark] abstract class MemoryManager { | ||
|
||
|
|
||
| /** | ||
| * Acquire N bytes of memory for execution. | ||
| * @return whether all N bytes are successfully granted. | ||
| */ | ||
| def acquireExecutionMemory(numBytes: Long): Boolean | ||
|
|
||
| /** | ||
| * Acquire N bytes of memory for storage. | ||
| * @return whether all N bytes are successfully granted. | ||
| */ | ||
| def acquireStorageMemory(numBytes: Long): Boolean | ||
|
|
||
| /** | ||
| * Release N bytes of execution memory. | ||
| */ | ||
| def releaseExecutionMemory(numBytes: Long): Unit | ||
|
|
||
| /** | ||
| * Release N bytes of storage memory. | ||
| */ | ||
| def releaseStorageMemory(numBytes: Long): Unit | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,6 +69,8 @@ class SparkEnv ( | |
| val httpFileServer: HttpFileServer, | ||
| val sparkFilesDir: String, | ||
| val metricsSystem: MetricsSystem, | ||
| // TODO: unify these *MemoryManager classes | ||
|
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. There's a JIRA for this, so you could mention the number here. |
||
| val memoryManager: MemoryManager, | ||
| val shuffleMemoryManager: ShuffleMemoryManager, | ||
| val executorMemoryManager: ExecutorMemoryManager, | ||
| val outputCommitCoordinator: OutputCommitCoordinator, | ||
|
|
@@ -323,6 +325,7 @@ object SparkEnv extends Logging { | |
| val shuffleMgrClass = shortShuffleMgrNames.getOrElse(shuffleMgrName.toLowerCase, shuffleMgrName) | ||
| val shuffleManager = instantiateClass[ShuffleManager](shuffleMgrClass) | ||
|
|
||
| val memoryManager = new StaticMemoryManager(conf) | ||
| val shuffleMemoryManager = ShuffleMemoryManager.create(conf, numUsableCores) | ||
|
|
||
| val blockTransferService = new NettyBlockTransferService(conf, securityManager, numUsableCores) | ||
|
|
@@ -407,6 +410,7 @@ object SparkEnv extends Logging { | |
| httpFileServer, | ||
| sparkFilesDir, | ||
| metricsSystem, | ||
| memoryManager, | ||
| shuffleMemoryManager, | ||
| executorMemoryManager, | ||
| outputCommitCoordinator, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark | ||
|
|
||
| import org.apache.spark.shuffle.ShuffleMemoryManager | ||
| import org.apache.spark.storage.BlockManager | ||
|
|
||
|
|
||
| /** | ||
| * A [[MemoryManager]] that statically partitions the heap space into disjoint regions. | ||
| * | ||
| * The sizes of the execution and storage regions are determined through | ||
| * `spark.shuffle.memoryFraction` and `spark.storage.memoryFraction` respectively. The two | ||
| * regions are cleanly separated such that neither usage can borrow memory from the other. | ||
| */ | ||
| private[spark] class StaticMemoryManager(conf: SparkConf) extends MemoryManager { | ||
| private val maxExecutionMemory = ShuffleMemoryManager.getMaxMemory(conf) | ||
| private val maxStorageMemory = BlockManager.getMaxMemory(conf) | ||
| @volatile private var executionMemoryUsed: Long = 0 | ||
| @volatile private var storageMemoryUsed: Long = 0 | ||
|
|
||
| /** | ||
| * Acquire N bytes of memory for execution. | ||
| * @return whether all N bytes are successfully granted. | ||
| */ | ||
| override def acquireExecutionMemory(numBytes: Long): Boolean = { | ||
| if (executionMemoryUsed + numBytes <= maxExecutionMemory) { | ||
| executionMemoryUsed += numBytes | ||
| true | ||
| } else { | ||
| false | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Acquire N bytes of memory for storage. | ||
| * @return whether all N bytes are successfully granted. | ||
| */ | ||
| override def acquireStorageMemory(numBytes: Long): Boolean = { | ||
| if (storageMemoryUsed + numBytes <= maxStorageMemory) { | ||
| storageMemoryUsed += numBytes | ||
| true | ||
| } else { | ||
| false | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Release N bytes of execution memory. | ||
| */ | ||
| override def releaseExecutionMemory(numBytes: Long): Unit = { | ||
| executionMemoryUsed -= numBytes | ||
| } | ||
|
|
||
| /** | ||
| * Release N bytes of storage memory. | ||
| */ | ||
| override def releaseStorageMemory(numBytes: Long): Unit = { | ||
| storageMemoryUsed -= numBytes | ||
| } | ||
|
|
||
| } |
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.
Can you add a comment to clarify whether this is a one-per-JVM component or one-per-task component?