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

    https://github.com/apache/spark/pull/9000#discussion_r41588629
  
    --- Diff: core/src/main/scala/org/apache/spark/StaticMemoryManager.scala ---
    @@ -0,0 +1,229 @@
    +/*
    + * 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 scala.collection.mutable
    +
    +import org.apache.spark.storage.{BlockId, BlockStatus, MemoryStore}
    +
    +
    +/**
    + * 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,
    +    override val maxExecutionMemory: Long,
    +    override val maxStorageMemory: Long)
    +  extends MemoryManager with Logging {
    +
    +  // Max number of bytes worth of blocks to evict when unrolling
    +  private val maxMemoryToEvictForUnroll: Long = {
    +    (maxStorageMemory * conf.getDouble("spark.storage.unrollFraction", 
0.2)).toLong
    +  }
    +
    +  // Amount of execution memory in use. Accesses must be synchronized on 
`executionLock`.
    +  private var _executionMemoryUsed: Long = 0
    +  private val executionLock = new Object
    +
    +  // Amount of storage memory in use. Accesses must be synchronized on 
`storageLock`.
    +  private var _storageMemoryUsed: Long = 0
    +  private val storageLock = new Object
    +
    +  // The memory store used to evict cached blocks
    +  private var _memoryStore: MemoryStore = _
    +  private def memoryStore: MemoryStore = {
    +    if (_memoryStore == null) {
    +      _memoryStore = SparkEnv.get.blockManager.memoryStore
    +    }
    +    _memoryStore
    +  }
    +
    +  // For testing only
    +  def setMemoryStore(store: MemoryStore): Unit = {
    +    _memoryStore = store
    +  }
    +
    +  def this(conf: SparkConf) {
    +    this(
    +      conf,
    +      StaticMemoryManager.getMaxExecutionMemory(conf),
    +      StaticMemoryManager.getMaxStorageMemory(conf))
    +  }
    +
    +  /**
    +   * Acquire N bytes of memory for execution.
    +   * @return number of bytes successfully granted (<= N).
    +   */
    +  override def acquireExecutionMemory(numBytes: Long): Long = {
    +    executionLock.synchronized {
    +      assert(_executionMemoryUsed <= maxExecutionMemory)
    +      val bytesToGrant = math.min(numBytes, maxExecutionMemory - 
_executionMemoryUsed)
    +      _executionMemoryUsed += bytesToGrant
    +      bytesToGrant
    +    }
    +  }
    +
    +  /**
    +   * Acquire N bytes of memory to cache the given block, evicting existing 
ones if necessary.
    +   * Blocks evicted in the process, if any, are added to `evictedBlocks`.
    +   * @return number of bytes successfully granted (0 or N).
    +   */
    +  override def acquireStorageMemory(
    +      blockId: BlockId,
    +      numBytes: Long,
    +      evictedBlocks: mutable.Buffer[(BlockId, BlockStatus)]): Long = {
    +    acquireStorageMemory(blockId, numBytes, numBytes, evictedBlocks)
    +  }
    +
    +  /**
    +   * Acquire N bytes of memory to unroll the given block, evicting 
existing ones if necessary.
    +   *
    +   * This evicts at most M bytes worth of existing blocks, where M is a 
fraction of the storage
    +   * space specified by `spark.storage.unrollFraction`. Blocks evicted in 
the process, if any,
    +   * are added to `evictedBlocks`.
    +   *
    +   * @return number of bytes successfully granted (0 or N).
    +   */
    +  override def acquireUnrollMemory(
    +      blockId: BlockId,
    +      numBytes: Long,
    +      evictedBlocks: mutable.Buffer[(BlockId, BlockStatus)]): Long = {
    +    val currentUnrollMemory = memoryStore.currentUnrollMemory
    --- End diff --
    
    added in `reserveUnrollMemoryForThisTask`


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to