@@ -132,8 +132,6 @@ private[spark] class MemoryStore(blockManager: BlockManager, maxMemory: Long)
132
132
PutResult (res.size, res.data, droppedBlocks)
133
133
case Right (iteratorValues) =>
134
134
// Not enough space to unroll this block; drop to disk if applicable
135
- logWarning(s " Not enough space to store block $blockId in memory! " +
136
- s " Free memory is $freeMemory bytes. " )
137
135
if (level.useDisk && allowPersistToDisk) {
138
136
logWarning(s " Persisting block $blockId to disk instead. " )
139
137
val res = blockManager.diskStore.putIterator(blockId, iteratorValues, level, returnValues)
@@ -265,6 +263,7 @@ private[spark] class MemoryStore(blockManager: BlockManager, maxMemory: Long)
265
263
Left (vector.toArray)
266
264
} else {
267
265
// We ran out of space while unrolling the values for this block
266
+ logUnrollFailureMessage(blockId, vector.estimateSize())
268
267
Right (vector.iterator ++ values)
269
268
}
270
269
@@ -424,7 +423,7 @@ private[spark] class MemoryStore(blockManager: BlockManager, maxMemory: Long)
424
423
* Reserve additional memory for unrolling blocks used by this thread.
425
424
* Return whether the request is granted.
426
425
*/
427
- private [spark] def reserveUnrollMemoryForThisThread (memory : Long ): Boolean = {
426
+ def reserveUnrollMemoryForThisThread (memory : Long ): Boolean = {
428
427
accountingLock.synchronized {
429
428
val granted = freeMemory > currentUnrollMemory + memory
430
429
if (granted) {
@@ -439,7 +438,7 @@ private[spark] class MemoryStore(blockManager: BlockManager, maxMemory: Long)
439
438
* Release memory used by this thread for unrolling blocks.
440
439
* If the amount is not specified, remove the current thread's allocation altogether.
441
440
*/
442
- private [spark] def releaseUnrollMemoryForThisThread (memory : Long = - 1L ): Unit = {
441
+ def releaseUnrollMemoryForThisThread (memory : Long = - 1L ): Unit = {
443
442
val threadId = Thread .currentThread().getId
444
443
accountingLock.synchronized {
445
444
if (memory < 0 ) {
@@ -457,16 +456,50 @@ private[spark] class MemoryStore(blockManager: BlockManager, maxMemory: Long)
457
456
/**
458
457
* Return the amount of memory currently occupied for unrolling blocks across all threads.
459
458
*/
460
- private [spark] def currentUnrollMemory : Long = accountingLock.synchronized {
459
+ def currentUnrollMemory : Long = accountingLock.synchronized {
461
460
unrollMemoryMap.values.sum
462
461
}
463
462
464
463
/**
465
464
* Return the amount of memory currently occupied for unrolling blocks by this thread.
466
465
*/
467
- private [spark] def currentUnrollMemoryForThisThread : Long = accountingLock.synchronized {
466
+ def currentUnrollMemoryForThisThread : Long = accountingLock.synchronized {
468
467
unrollMemoryMap.getOrElse(Thread .currentThread().getId, 0L )
469
468
}
469
+
470
+ /**
471
+ * Return the number of threads currently unrolling blocks.
472
+ */
473
+ def numThreadsUnrolling : Int = accountingLock.synchronized { unrollMemoryMap.keys.size }
474
+
475
+ /**
476
+ * Log information about current memory usage.
477
+ */
478
+ def logMemoryUsage (): Unit = {
479
+ val blocksMemory = currentMemory
480
+ val unrollMemory = currentUnrollMemory
481
+ val totalMemory = blocksMemory + unrollMemory
482
+ logInfo(
483
+ s " Memory use = ${Utils .bytesToString(blocksMemory)} (blocks) + " +
484
+ s " ${Utils .bytesToString(unrollMemory)} (scratch space shared across " +
485
+ s " $numThreadsUnrolling thread(s)) = ${Utils .bytesToString(totalMemory)}. " +
486
+ s " Storage limit = ${Utils .bytesToString(maxMemory)}. "
487
+ )
488
+ }
489
+
490
+ /**
491
+ * Log a warning for failing to unroll a block.
492
+ *
493
+ * @param blockId ID of the block we are trying to unroll.
494
+ * @param finalVectorSize Final size of the vector before unrolling failed.
495
+ */
496
+ def logUnrollFailureMessage (blockId : BlockId , finalVectorSize : Long ): Unit = {
497
+ logWarning(
498
+ s " Not enough space to cache $blockId in memory! " +
499
+ s " (computed ${Utils .bytesToString(finalVectorSize)} so far) "
500
+ )
501
+ logMemoryUsage()
502
+ }
470
503
}
471
504
472
505
private [spark] case class ResultWithDroppedBlocks (
0 commit comments