class TaskMemoryManager extends AnyRef
Manages the memory allocated by an individual task.
Most of the complexity in this class deals with encoding of off-heap addresses into 64-bit longs. In off-heap mode, memory can be directly addressed with 64-bit longs. In on-heap mode, memory is addressed by the combination of a base Object reference and a 64-bit offset within that object. This is a problem when we want to store pointers to data structures inside of other structures, such as record pointers inside hashmaps or sorting buffers. Even if we decided to use 128 bits to address memory, we can't just store the address of the base object since it's not guaranteed to remain stable as the heap gets reorganized due to GC.
Instead, we use the following approach to encode record pointers in 64-bit longs: for off-heap mode, just store the raw address, and for on-heap mode use the upper 13 bits of the address to store a "page number" and the lower 51 bits to store an offset within this page. These page numbers are used to index into a "page table" array inside of the MemoryManager in order to retrieve the base object.
This allows us to address 8192 pages. In on-heap mode, the maximum page size is limited by the maximum size of a long[] array, allowing us to address 8192 * (2^31 - 1) * 8 bytes, which is approximately 140 terabytes of memory.
- Alphabetic
- By Inheritance
- TaskMemoryManager
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
- new TaskMemoryManager(memoryManager: MemoryManager, taskAttemptId: Long)
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
acquireExecutionMemory(required: Long, consumer: MemoryConsumer): Long
Acquire N bytes of memory for a consumer.
Acquire N bytes of memory for a consumer. If there is no enough memory, it will call spill() of consumers to release more memory.
- returns
number of bytes successfully granted (<= N).
-
def
allocatePage(size: Long, consumer: MemoryConsumer): MemoryBlock
Allocate a block of memory that will be tracked in the MemoryManager's page table; this is intended for allocating large blocks of Tungsten memory that will be shared between operators.
Allocate a block of memory that will be tracked in the MemoryManager's page table; this is intended for allocating large blocks of Tungsten memory that will be shared between operators.
Returns
null
if there was not enough memory to allocate the page. May return a page that contains fewer bytes than requested, so callers should verify the size of returned pages.- Exceptions thrown
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
cleanUpAllAllocatedMemory(): Long
Clean up all allocated memory and pages.
Clean up all allocated memory and pages. Returns the number of bytes freed. A non-zero return value can be used to detect memory leaks.
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
def
encodePageNumberAndOffset(page: MemoryBlock, offsetInPage: Long): Long
Given a memory page and offset within that page, encode this address into a 64-bit long.
Given a memory page and offset within that page, encode this address into a 64-bit long. This address will remain valid as long as the corresponding page has not been freed.
- page
a data page allocated by
TaskMemoryManager#allocatePage
/- offsetInPage
an offset in this page which incorporates the base offset. In other words, this should be the value that you would pass as the base offset into an UNSAFE call (e.g. page.baseOffset() + something).
- returns
an encoded page address.
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
freePage(page: MemoryBlock, consumer: MemoryConsumer): Unit
Free a block of memory allocated via
TaskMemoryManager#allocatePage
. -
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
getMemoryConsumptionForThisTask(): Long
Returns the memory consumption, in bytes, for the current task.
-
def
getOffsetInPage(pagePlusOffsetAddress: Long): Long
Get the offset associated with an address encoded by
long)
-
def
getPage(pagePlusOffsetAddress: Long): AnyRef
Get the page associated with an address encoded by
long)
-
def
getTungstenMemoryMode(): MemoryMode
Returns Tungsten memory mode
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
pageSizeBytes(): Long
Return the page size in bytes.
-
def
releaseExecutionMemory(size: Long, consumer: MemoryConsumer): Unit
Release N bytes of execution memory for a MemoryConsumer.
-
def
showMemoryUsage(): Unit
Dump the memory usage of all consumers.
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()