You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`MemoryAllocator` is an [abstraction](#contract) of [memory allocators](#implementations) that [TaskMemoryManager](TaskMemoryManager.md) uses to [allocate](#allocate) and [release](#free) memory.
4
+
5
+
`MemoryAllocator` creates the available [MemoryAllocator](#implementations)s to be available under the names [HEAP](#HEAP) and [UNSAFE](#UNSAFE).
6
+
7
+
A [MemoryAllocator](#implementations) to use is selected when `MemoryManager` is [created](MemoryManager.md#tungstenMemoryAllocator) (based on [MemoryMode](MemoryManager.md#tungstenMemoryMode)).
8
+
9
+
## Contract
10
+
11
+
### <spanid="allocate"> Allocating Contiguous Block of Memory
12
+
13
+
```java
14
+
MemoryBlock allocate(
15
+
long size)
16
+
```
17
+
18
+
Used when:
19
+
20
+
*`TaskMemoryManager` is requested to [allocate a memory page](TaskMemoryManager.md#allocatePage)
21
+
22
+
### <spanid="free"> Releasing Memory
23
+
24
+
```java
25
+
void free(
26
+
MemoryBlock memory)
27
+
```
28
+
29
+
Used when:
30
+
31
+
*`TaskMemoryManager` is requested to [release a memory page](TaskMemoryManager.md#freePage) and [clean up all the allocated memory](TaskMemoryManager.md#cleanUpAllAllocatedMemory)
`tungstenMemoryMode` tracks whether Tungsten memory will be allocated on the JVM heap or off-heap (using `sun.misc.Unsafe`).
185
185
186
+
!!! note "final val"
187
+
`tungstenMemoryMode` is a `final val`ue so initialized once when `MemoryManager` is [created](#creating-instance).
188
+
186
189
`tungstenMemoryMode` is `OFF_HEAP` when the following are all met:
187
190
188
191
*[spark.memory.offHeap.enabled](../configuration-properties.md#spark.memory.offHeap.enabled) configuration property is enabled
@@ -198,5 +201,25 @@ Otherwise, `tungstenMemoryMode` is `ON_HEAP`.
198
201
199
202
`tungstenMemoryMode` is used when:
200
203
201
-
*`MemoryManager` is created (and initializes the [pageSizeBytes](MemoryManager.md#pageSizeBytes) and [tungstenMemoryAllocator](MemoryManager.md#tungstenMemoryAllocator) internal properties)
204
+
*`MemoryManager` is [created](#creating-instance) (and initializes the [pageSizeBytes](#pageSizeBytes) and [tungstenMemoryAllocator](#tungstenMemoryAllocator) internal properties)
202
205
*`TaskMemoryManager` is [created](TaskMemoryManager.md#tungstenMemoryMode)
*`TaskMemoryManager` is requested to [allocate a memory page](TaskMemoryManager.md#allocatePage), [release a memory page](TaskMemoryManager.md#freePage) and [clean up all the allocated memory](TaskMemoryManager.md#cleanUpAllAllocatedMemory)
0 commit comments