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-21090][core]Optimize the unified memory manager code #18296

Closed
wants to merge 1 commit into from

Conversation

10110346
Copy link
Contributor

@10110346 10110346 commented Jun 14, 2017

What changes were proposed in this pull request?

1.In acquireStorageMemory, when the Memory Mode is OFF_HEAP ,the maxOffHeapMemory should be modified to maxOffHeapStorageMemory. after this PR,it will same as ON_HEAP Memory Mode.
Because when acquire memory is between maxOffHeapStorageMemory and maxOffHeapMemory,it will fail surely, so if acquire memory is greater than maxOffHeapStorageMemory(not greater than maxOffHeapMemory),we should fail fast.
2. Borrow memory from execution, numBytes modified to numBytes - storagePool.memoryFree will be more reasonable.
Because we just acquire (numBytes - storagePool.memoryFree), unnecessary borrowed numBytes from execution

How was this patch tested?

added unit test case

@SparkQA
Copy link

SparkQA commented Jun 14, 2017

Test build #78030 has finished for PR 18296 at commit a93f7af.

  • This patch fails Scala style tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Jun 14, 2017

Test build #78032 has started for PR 18296 at commit bafc18f.

@10110346
Copy link
Contributor Author

retest this please

Copy link
Member

@srowen srowen left a comment

Choose a reason for hiding this comment

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

You generally haven't exchanged why you think this change is necessary. Explaining what it is doesn't do that.

@10110346
Copy link
Contributor Author

@srowen I have updated the description of this PR,thanks

@srowen
Copy link
Member

srowen commented Jun 14, 2017

I don't quite understand how that addresses the question, but I don't know this code. @JoshRosen is the most likely reviewer, but maybe you can elaborate the example more.

@SparkQA
Copy link

SparkQA commented Jun 14, 2017

Test build #78037 has finished for PR 18296 at commit bafc18f.

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

@10110346
Copy link
Contributor Author

@JoshRosen Could you help to review it, thanks

Copy link
Contributor

@JoshRosen JoshRosen left a comment

Choose a reason for hiding this comment

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

LGTM. I commented inline on why I think this is a good and correct change.

@@ -160,7 +160,7 @@ private[spark] class UnifiedMemoryManager private[memory] (
case MemoryMode.OFF_HEAP => (
offHeapExecutionMemoryPool,
offHeapStorageMemoryPool,
maxOffHeapMemory)
maxOffHeapStorageMemory)
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like a bug in the old code. Good catch.

@@ -171,7 +171,8 @@ private[spark] class UnifiedMemoryManager private[memory] (
if (numBytes > storagePool.memoryFree) {
// There is not enough free memory in the storage pool, so try to borrow free memory from
// the execution pool.
val memoryBorrowedFromExecution = Math.min(executionPool.memoryFree, numBytes)
val memoryBorrowedFromExecution = Math.min(executionPool.memoryFree,
numBytes - storagePool.memoryFree)
Copy link
Contributor

Choose a reason for hiding this comment

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

This change makes sense: if we hit this branch then we've failed to acquire enough memory to store a block. In particular, we might need M bytes of memory but only A are available in storage. In this case, we should only request the (M - A) bytes of extra memory that we need, but the old code was incorrectly requesting all M which would cause us to over-evict. Therefore, I think this change is correct.

@gatorsmile
Copy link
Member

Also cc @cloud-fan @jiangxb1987

@cloud-fan
Copy link
Contributor

LGTM, merging to master!

@asfgit asfgit closed this in 112bd9b Jun 19, 2017
asfgit pushed a commit that referenced this pull request Jun 19, 2017
## What changes were proposed in this pull request?
1.In `acquireStorageMemory`, when the Memory Mode is OFF_HEAP ,the `maxOffHeapMemory` should be modified to `maxOffHeapStorageMemory`. after this PR,it will same as ON_HEAP Memory Mode.
Because when acquire memory is between `maxOffHeapStorageMemory` and `maxOffHeapMemory`,it will fail surely, so if acquire memory is greater than  `maxOffHeapStorageMemory`(not greater than `maxOffHeapMemory`),we should fail fast.
2. Borrow memory from execution, `numBytes` modified to `numBytes - storagePool.memoryFree` will be more reasonable.
Because we just acquire `(numBytes - storagePool.memoryFree)`, unnecessary borrowed `numBytes` from execution

## How was this patch tested?
added unit test case

Author: liuxian <[email protected]>

Closes #18296 from 10110346/wip-lx-0614.

(cherry picked from commit 112bd9b)
Signed-off-by: Wenchen Fan <[email protected]>
@cloud-fan
Copy link
Contributor

Actually this is a bug fix, and it's a small fix(without tests, only 3 lines), so backporting in to 2.2

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