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

    https://github.com/apache/spark/pull/11874#discussion_r57254579
  
    --- Diff: 
core/src/main/scala/org/apache/spark/memory/StorageMemoryPool.scala ---
    @@ -56,12 +58,30 @@ private[memory] class StorageMemoryPool(lock: Object) 
extends MemoryPool(lock) w
     
       /**
        * Acquire N bytes of memory to cache the given block, evicting existing 
ones if necessary.
    - *
    +   *
        * @return whether all N bytes were successfully granted.
        */
    -  def acquireMemory(blockId: BlockId, numBytes: Long): Boolean = 
lock.synchronized {
    -    val numBytesToFree = math.max(0, numBytes - memoryFree)
    -    acquireMemory(blockId, numBytes, numBytesToFree)
    +  def acquireMemory(blockId: BlockId, numBytes: Long): Boolean = {
    +    // First, attempt to acquire as much memory as we can without 
performing any eviction
    +    val bytesAcquiredWithoutEviction = lock.synchronized {
    +      val bytesAcquired = math.min(numBytes, memoryFree)
    +      _memoryUsed += bytesAcquired
    +      bytesAcquired
    +    }
    +    // Acquire the remainder of the memory by performing eviction
    +    try {
    +      val bytesToAcquireViaEviction = numBytes - 
bytesAcquiredWithoutEviction
    +      if (acquireMemory(blockId, bytesToAcquireViaEviction, 
bytesToAcquireViaEviction)) {
    +        true
    +      } else {
    +        releaseMemory(bytesAcquiredWithoutEviction)
    +        false
    +      }
    +    } catch {
    +      case NonFatal(e) =>
    +        releaseMemory(bytesAcquiredWithoutEviction)
    --- End diff --
    
    same double release comment here


---
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