Github user andrewor14 commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10170#discussion_r47028671
  
    --- Diff: 
core/src/main/scala/org/apache/spark/memory/StorageMemoryPool.scala ---
    @@ -73,27 +73,31 @@ class StorageMemoryPool(lock: Object) extends 
MemoryPool(lock) with Logging {
        *
        * @param blockId the ID of the block we are acquiring storage memory for
        * @param numBytesToAcquire the size of this block
    -   * @param numBytesToFree the size of space to be freed through evicting 
blocks
    +   * @param maxNumBytesToFree the maximum amount of space to be freed 
through evicting blocks
        * @return whether all N bytes were successfully granted.
        */
       def acquireMemory(
           blockId: BlockId,
           numBytesToAcquire: Long,
    -      numBytesToFree: Long,
    +      maxNumBytesToFree: Long,
           evictedBlocks: mutable.Buffer[(BlockId, BlockStatus)]): Boolean = 
lock.synchronized {
         assert(numBytesToAcquire >= 0)
    -    assert(numBytesToFree >= 0)
    +    assert(maxNumBytesToFree >= 0)
         assert(memoryUsed <= poolSize)
    -    memoryStore.ensureFreeSpace(blockId, numBytesToFree, evictedBlocks)
    -    // Register evicted blocks, if any, with the active task metrics
    -    Option(TaskContext.get()).foreach { tc =>
    -      val metrics = tc.taskMetrics()
    -      val lastUpdatedBlocks = 
metrics.updatedBlocks.getOrElse(Seq[(BlockId, BlockStatus)]())
    -      metrics.updatedBlocks = Some(lastUpdatedBlocks ++ 
evictedBlocks.toSeq)
    +    if (numBytesToAcquire > memoryFree && maxNumBytesToFree > 0) {
    +      val additionalMemoryRequired = numBytesToAcquire - memoryFree
    +      memoryStore.evictBlocksToFreeSpace(
    --- End diff --
    
    after looking at the test case I think we should add a check here to do 
this only if there's a chance that evicting can free us enough memory, i.e.
    ```
    val additionalMemoryRequired = math.max(0, numBytesToAcquire - memoryFree)
    val numBytesToFree = math.min(maxNumBytesToFree, additionalMemoryRequired)
    // Only evict blocks if there is a chance that doing so will grant us what 
we want
    if (numBytesToFree > 0 && numBytesToFree <= memoryUsed) {
      memoryStore.evictBlocksToFreeSpace(...)
      ...
    }
    ```
    If we do this then we can't have the case where we try to free 150B from 
evicting blocks when there are only 100B worth of blocks.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to