aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/scala/org/apache/spark/util/io/ChunkedByteBuffer.scala
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/scala/org/apache/spark/util/io/ChunkedByteBuffer.scala')
-rw-r--r--core/src/main/scala/org/apache/spark/util/io/ChunkedByteBuffer.scala27
1 files changed, 22 insertions, 5 deletions
diff --git a/core/src/main/scala/org/apache/spark/util/io/ChunkedByteBuffer.scala b/core/src/main/scala/org/apache/spark/util/io/ChunkedByteBuffer.scala
index 7572cac393..1667516663 100644
--- a/core/src/main/scala/org/apache/spark/util/io/ChunkedByteBuffer.scala
+++ b/core/src/main/scala/org/apache/spark/util/io/ChunkedByteBuffer.scala
@@ -86,7 +86,11 @@ private[spark] class ChunkedByteBuffer(var chunks: Array[ByteBuffer]) {
}
/**
- * Copy this buffer into a new ByteBuffer.
+ * Convert this buffer to a ByteBuffer. If this buffer is backed by a single chunk, its underlying
+ * data will not be copied. Instead, it will be duplicated. If this buffer is backed by multiple
+ * chunks, the data underlying this buffer will be copied into a new byte buffer. As a result, it
+ * is suggested to use this method only if the caller does not need to manage the memory
+ * underlying this buffer.
*
* @throws UnsupportedOperationException if this buffer's size exceeds the max ByteBuffer size.
*/
@@ -132,10 +136,10 @@ private[spark] class ChunkedByteBuffer(var chunks: Array[ByteBuffer]) {
}
/**
- * Attempt to clean up a ByteBuffer if it is memory-mapped. This uses an *unsafe* Sun API that
- * might cause errors if one attempts to read from the unmapped buffer, but it's better than
- * waiting for the GC to find it because that could lead to huge numbers of open files. There's
- * unfortunately no standard API to do this.
+ * Attempt to clean up any ByteBuffer in this ChunkedByteBuffer which is direct or memory-mapped.
+ * See [[StorageUtils.dispose]] for more information.
+ *
+ * See also [[unmap]]
*/
def dispose(): Unit = {
if (!disposed) {
@@ -143,6 +147,19 @@ private[spark] class ChunkedByteBuffer(var chunks: Array[ByteBuffer]) {
disposed = true
}
}
+
+ /**
+ * Attempt to unmap any ByteBuffer in this ChunkedByteBuffer if it is memory-mapped. See
+ * [[StorageUtils.unmap]] for more information.
+ *
+ * See also [[dispose]]
+ */
+ def unmap(): Unit = {
+ if (!disposed) {
+ chunks.foreach(StorageUtils.unmap)
+ disposed = true
+ }
+ }
}
/**