<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=Spark_memory_management</id>
	<title>Spark memory management - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=Spark_memory_management"/>
	<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Spark_memory_management&amp;action=history"/>
	<updated>2026-12-06T00:13:42Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.11</generator>
	<entry>
		<id>https://openlakehouse.io/w/index.php?title=Spark_memory_management&amp;diff=191&amp;oldid=prev</id>
		<title>Open Lakehouse Wiki sync: Sync from open-lakehouse/wiki@7c9abaa</title>
		<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Spark_memory_management&amp;diff=191&amp;oldid=prev"/>
		<updated>2026-11-25T00:52:55Z</updated>

		<summary type="html">&lt;p&gt;Sync from open-lakehouse/wiki@7c9abaa&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Infobox concept&lt;br /&gt;
| name            = Spark memory management&lt;br /&gt;
| also_known_as   = Unified memory model, unified memory manager&lt;br /&gt;
| field           = Distributed data processing&lt;br /&gt;
| introduced      = Apache Spark 1.6.0 (unified memory manager)&lt;br /&gt;
| key_parts       = Reserved memory, user memory, unified region (execution and storage), memory overhead, off-heap memory&lt;br /&gt;
| implementations = [[Apache Spark]]&lt;br /&gt;
| related         = [[Executor]], [[Executor memory overhead]], [[Spill (memory)]], [[Caching and persistence]], [[Garbage collection in Spark]], [[Project Tungsten]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (docs/tuning.md, docs/configuration.md, core/memory/UnifiedMemoryManager.scala) and SPARK-10000}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Spark memory management&amp;#039;&amp;#039;&amp;#039; is the way [[Apache Spark]] divides the memory of each [[executor]] between running tasks, cached data, user code and the JVM itself. Since Spark 1.6.0, a &amp;#039;&amp;#039;&amp;#039;unified memory manager&amp;#039;&amp;#039;&amp;#039; lets execution memory (for shuffles, joins, sorts and aggregations) and storage memory (for cached data) share one region and borrow from each other.&amp;lt;ref name=&amp;quot;spark10000&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-10000 |title=SPARK-10000: Consolidate storage and execution memory management |publisher=Apache Software Foundation JIRA |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;tuning&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/tuning.html |title=Tuning Spark (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Memory outside the JVM heap is requested separately as [[executor memory overhead]].&lt;br /&gt;
&lt;br /&gt;
== How is executor memory divided? ==&lt;br /&gt;
An executor&amp;#039;s JVM heap is set by &amp;lt;code&amp;gt;spark.executor.memory&amp;lt;/code&amp;gt; (default &amp;lt;code&amp;gt;1g&amp;lt;/code&amp;gt;).&amp;lt;ref name=&amp;quot;config&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/configuration.html |title=Spark Configuration (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Spark splits the heap into three parts:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Part !! Size !! What it holds&lt;br /&gt;
|-&lt;br /&gt;
| Reserved memory&lt;br /&gt;
| 300 MiB, fixed&lt;br /&gt;
| Kept back by Spark; the heap must be at least 1.5 times this (450 MiB) or the executor does not start&amp;lt;ref name=&amp;quot;umm&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/memory/UnifiedMemoryManager.scala |title=UnifiedMemoryManager.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| User memory&lt;br /&gt;
| (heap − 300 MiB) × (1 − &amp;lt;code&amp;gt;spark.memory.fraction&amp;lt;/code&amp;gt;), 40% by default&lt;br /&gt;
| User data structures, Spark internal metadata, and a margin for unusually large records&amp;lt;ref name=&amp;quot;tuning&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Unified region (M)&lt;br /&gt;
| (heap − 300 MiB) × &amp;lt;code&amp;gt;spark.memory.fraction&amp;lt;/code&amp;gt; (default 0.6)&lt;br /&gt;
| Execution memory and storage memory, shared&amp;lt;ref name=&amp;quot;tuning&amp;quot; /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
For an 8 GiB heap with the defaults, the unified region is (8192 − 300) × 0.6 ≈ 4,735 MiB and user memory is about 3,157 MiB. This follows the formula in &amp;lt;code&amp;gt;UnifiedMemoryManager&amp;lt;/code&amp;gt;, which subtracts the 300 MiB reserve from the heap size the JVM reports (&amp;lt;code&amp;gt;Runtime.getRuntime.maxMemory&amp;lt;/code&amp;gt;) and multiplies the rest by &amp;lt;code&amp;gt;spark.memory.fraction&amp;lt;/code&amp;gt;; the JVM may report slightly less than &amp;lt;code&amp;gt;spark.executor.memory&amp;lt;/code&amp;gt;, so the real figures can be a little lower.&amp;lt;ref name=&amp;quot;umm&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;tuning&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Execution memory and storage memory ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Execution memory&amp;#039;&amp;#039;&amp;#039; is used for computation in shuffles, joins, sorts and aggregations. &amp;#039;&amp;#039;&amp;#039;Storage memory&amp;#039;&amp;#039;&amp;#039; is used for caching and for propagating internal data across the cluster.&amp;lt;ref name=&amp;quot;tuning&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The two share the unified region M. When no execution memory is in use, storage can take all of M, and the other way round. Execution can evict cached blocks to get memory back, but only until storage falls to a protected share R, set by &amp;lt;code&amp;gt;spark.memory.storageFraction&amp;lt;/code&amp;gt; (default 0.5 of M). Storage cannot evict execution memory.&amp;lt;ref name=&amp;quot;tuning&amp;quot; /&amp;gt; Applications that do not cache can therefore use the whole region for execution, and applications that cache keep at least R for their blocks.&amp;lt;ref name=&amp;quot;tuning&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When execution memory runs out, tasks [[Spill (memory)|spill]] to disk instead of failing. When storage memory runs out, cached blocks are dropped in least-recently-used order, or written to disk if their storage level allows it.&amp;lt;ref name=&amp;quot;rddguide&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/rdd-programming-guide.html#rdd-persistence |title=RDD Programming Guide: RDD Persistence (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The Spark docs recommend leaving both fractions at their defaults for most workloads.&amp;lt;ref name=&amp;quot;tuning&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Off-heap memory ==&lt;br /&gt;
With &amp;lt;code&amp;gt;spark.memory.offHeap.enabled&amp;lt;/code&amp;gt; (default false) set to true, Spark can use off-heap memory for certain operations, in an amount set by &amp;lt;code&amp;gt;spark.memory.offHeap.size&amp;lt;/code&amp;gt; (default 0, must be positive when enabled). This memory is outside the JVM heap and does not change heap usage, so the heap should be shrunk if the total must fit a fixed limit.&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt; The &amp;lt;code&amp;gt;OFF_HEAP&amp;lt;/code&amp;gt; storage level, marked experimental in the Spark docs, caches data in this memory.&amp;lt;ref name=&amp;quot;rddguide&amp;quot; /&amp;gt; Spark&amp;#039;s task memory manager allocates the memory pages for sorting, hashing and shuffle either on the heap or, with this setting, off-heap; see [[Project Tungsten]].&amp;lt;ref name=&amp;quot;tmm&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/java/org/apache/spark/memory/TaskMemoryManager.java |title=TaskMemoryManager.java (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Memory outside the heap ==&lt;br /&gt;
On YARN and Kubernetes, the container for an executor is the sum of &amp;lt;code&amp;gt;spark.executor.memory&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;spark.executor.memoryOverhead&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;spark.memory.offHeap.size&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;spark.executor.pyspark.memory&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt; Overhead covers JVM overheads, interned strings and other native memory, and by default is 10% of executor memory with a minimum of 384 MiB. Python worker memory is part of the overhead unless &amp;lt;code&amp;gt;spark.executor.pyspark.memory&amp;lt;/code&amp;gt; is set.&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt; See [[Executor memory overhead]].&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
spark.executor.memory              8g&lt;br /&gt;
spark.executor.cores               4&lt;br /&gt;
spark.memory.fraction              0.6&lt;br /&gt;
spark.memory.storageFraction       0.5&lt;br /&gt;
spark.memory.offHeap.enabled       true&lt;br /&gt;
spark.memory.offHeap.size          2g&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With this configuration on YARN or Kubernetes, each executor container is sized at 8 GiB of heap plus about 819 MiB of overhead (10% of 8 GiB) plus 2 GiB of off-heap memory. The four tasks that run at once on the executor share one pool of execution memory.&amp;lt;ref name=&amp;quot;config&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Executor]]&lt;br /&gt;
* [[Executor memory overhead]]&lt;br /&gt;
* [[Spill (memory)]]&lt;br /&gt;
* [[Caching and persistence]]&lt;br /&gt;
* [[Garbage collection in Spark]]&lt;br /&gt;
* [[Project Tungsten]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Navbox open lakehouse}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Concepts]]&lt;br /&gt;
[[Category:Glossary terms]]&lt;br /&gt;
[[Category:Apache Spark]]&lt;/div&gt;</summary>
		<author><name>Open Lakehouse Wiki sync</name></author>
	</entry>
</feed>