Github user squito commented on a diff in the pull request:
https://github.com/apache/spark/pull/14617#discussion_r106935786
--- Diff: core/src/main/scala/org/apache/spark/storage/StorageUtils.scala
---
@@ -176,17 +185,42 @@ class StorageStatus(val blockManagerId:
BlockManagerId, val maxMem: Long) {
*/
def numRddBlocksById(rddId: Int): Int =
_rddBlocks.get(rddId).map(_.size).getOrElse(0)
+ /** Return the max memory can be used by this block manager. */
+ def maxMem: Long = maxOnHeapMem + maxOffHeapMem
+
/** Return the memory remaining in this block manager. */
- def memRemaining: Long = maxMem - memUsed
+ def memRemaining: Long = onHeapMemRemaining + offHeapMemRemaining
+
+ /** Return the memory used by caching RDDs */
+ def cacheSize: Long = onHeapCacheSize + offHeapCacheSize
/** Return the memory used by this block manager. */
- def memUsed: Long = _nonRddStorageInfo._1 + cacheSize
+ def memUsed: Long = onHeapMemUsed + offHeapMemUsed
- /** Return the memory used by caching RDDs */
- def cacheSize: Long = _rddBlocks.keys.toSeq.map(memUsedByRdd).sum
+ /** Return the on-heap memory remaining in this block manager. */
+ def onHeapMemRemaining: Long = maxOnHeapMem - onHeapMemUsed
+
+ /** Return the off-heap memory remaining in this block manager. */
+ def offHeapMemRemaining: Long = maxOffHeapMem - offHeapMemUsed
+
+ /** Return the on-heap memory used by this block manager. */
+ def onHeapMemUsed: Long = _nonRddStorageInfo._1 + onHeapCacheSize
+
+ /** Return the off-heap memory used by this block manager. */
+ def offHeapMemUsed: Long = _nonRddStorageInfo._2 + offHeapCacheSize
+
+ /** Return the memory used by on-heap caching RDDs */
+ def onHeapCacheSize: Long = {
+ _rddStorageInfo.filter(!_._2._3.useOffHeap).map(_._2._1).sum
--- End diff --
You can combine the filter & map with `collect`. I think its a bit clearer
and also avoids the extra intermediate structure.
```scala
_rddStorageInfo.collect {
case (_, (memoryUsed, _, storageStatus)) if !storageStatus.useOffHeap =>
memoryUsed
}.sum
```
---
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]