-
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
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -107,12 +107,10 @@ private[spark] class StaticMemoryManager( | |
| blockId: BlockId, | ||
| numBytes: Long, | ||
| evictedBlocks: mutable.Buffer[(BlockId, BlockStatus)]): Long = { | ||
| storageLock.synchronized { | ||
| val currentUnrollMemory = memoryStore.currentUnrollMemory | ||
| val maxNumBytesToFree = math.max(0, maxMemoryToEvictForUnroll - currentUnrollMemory) | ||
| val numBytesToFree = math.min(numBytes, maxNumBytesToFree) | ||
| acquireStorageMemory(blockId, numBytes, numBytesToFree, evictedBlocks) | ||
| } | ||
| val currentUnrollMemory = memoryStore.currentUnrollMemory | ||
|
||
| val maxNumBytesToFree = math.max(0, maxMemoryToEvictForUnroll - currentUnrollMemory) | ||
| val numBytesToFree = math.min(numBytes, maxNumBytesToFree) | ||
| acquireStorageMemory(blockId, numBytes, numBytesToFree, evictedBlocks) | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -129,8 +127,9 @@ private[spark] class StaticMemoryManager( | |
| numBytesToAcquire: Long, | ||
| numBytesToFree: Long, | ||
| evictedBlocks: mutable.Buffer[(BlockId, BlockStatus)]): Long = { | ||
| // Note: Keep this outside synchronized block to avoid potential deadlocks! | ||
| memoryStore.ensureFreeSpace(blockId, numBytesToFree, evictedBlocks) | ||
| storageLock.synchronized { | ||
| memoryStore.ensureFreeSpace(blockId, numBytesToFree, evictedBlocks) | ||
| assert(_storageMemoryUsed <= maxStorageMemory) | ||
| val enoughMemory = _storageMemoryUsed + numBytesToAcquire <= maxStorageMemory | ||
| val bytesToGrant = if (enoughMemory) numBytesToAcquire else 0 | ||
|
|
@@ -169,6 +168,15 @@ private[spark] class StaticMemoryManager( | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Release all storage memory acquired. | ||
| */ | ||
| override def releaseStorageMemory(): Unit = { | ||
| storageLock.synchronized { | ||
| _storageMemoryUsed = 0 | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Release N bytes of unroll memory. | ||
| */ | ||
|
|
@@ -179,15 +187,19 @@ private[spark] class StaticMemoryManager( | |
| /** | ||
| * Amount of execution memory currently in use, in bytes. | ||
| */ | ||
| override def executionMemoryUsed: Long = executionLock.synchronized { | ||
| _executionMemoryUsed | ||
| override def executionMemoryUsed: Long = { | ||
| executionLock.synchronized { | ||
| _executionMemoryUsed | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Amount of storage memory currently in use, in bytes. | ||
| */ | ||
| override def storageMemoryUsed: Long = storageLock.synchronized { | ||
| _storageMemoryUsed | ||
| override def storageMemoryUsed: Long = { | ||
| storageLock.synchronized { | ||
| _storageMemoryUsed | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
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.
This releases all storage memory acquired JVM-wide, across all tasks?
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.
yes, it's called in
MemoryStore#clearThere 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.
Ah. It looks like
BlockStore#clearis only called during SparkContext shutdown, so I guess it technically doesn't matter if you update the memory accounting there. Doesn't hurt, I guess, but not strictly necessary.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 know, if
def releaseStorageMemory(numBytes: Long)doesn't throw when releasing more than the total amount of storage memory, you could just eliminate this method and callreleaseStorageMemory(Long.MAX_VALUE)instead.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.
I think releasing more than you have is a bad sign. I actually log a warning for that. It's probably OK to just keep this method.