Github user tedyu commented on a diff in the pull request:
https://github.com/apache/spark/pull/9241#discussion_r43311051
--- Diff: core/src/main/java/org/apache/spark/memory/TaskMemoryManager.java
---
@@ -101,27 +106,97 @@
private final boolean inHeap;
/**
+ * The size of memory granted to each consumer.
+ */
+ private final HashMap<MemoryConsumer, Long> consumers;
+
+ /**
* Construct a new TaskMemoryManager.
*/
public TaskMemoryManager(MemoryManager memoryManager, long
taskAttemptId) {
this.inHeap = memoryManager.tungstenMemoryIsAllocatedInHeap();
this.memoryManager = memoryManager;
this.taskAttemptId = taskAttemptId;
+ this.consumers = new HashMap<>();
}
/**
- * Acquire N bytes of memory for execution, evicting cached blocks if
necessary.
+ * Acquire N bytes of memory for a consumer. If there is no enough
memory, it will call
+ * spill() of consumers to release more memory.
+ *
* @return number of bytes successfully granted (<= N).
*/
- public long acquireExecutionMemory(long size) {
- return memoryManager.acquireExecutionMemory(size, taskAttemptId);
+ public long acquireExecutionMemory(long size, MemoryConsumer consumer)
throws IOException {
+ assert(size >= 0);
+ synchronized (this) {
+ long got = memoryManager.acquireExecutionMemory(size, taskAttemptId);
+
+ // call spill() on itself to release some memory
+ if (got < size && consumer != null) {
+ consumer.spill(size - got, consumer);
+ got += memoryManager.acquireExecutionMemory(size - got,
taskAttemptId);
--- End diff --
Maybe add an assert got == size
---
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]