Spill (memory)
| Also known as | Spill to disk, memory spill |
|---|---|
| Field | Distributed data processing |
| Key parts | Execution memory, spill files on local disk, spill metrics |
| Open source implementations | Apache Spark, Trino, Apache Flink |
| Related | Spark memory management, Shuffle, Data skew, Executor |
Spill is the act of a query engine writing intermediate data from memory to local disk while an operation runs, because the data for a sort, aggregation, join or shuffle does not fit in the memory the operation is allowed to use. In Apache Spark, a task spills when its share of execution memory is full; the task keeps running, reads the spilled data back later, and finishes slower instead of failing.[1][2] Trino and Apache Flink spill too, under different rules.
What is spill in Apache Spark?
Spark divides each executor's unified memory region into execution memory, used for shuffles, joins, sorts and aggregations, and storage memory, used for cached data.[2] Shuffle operations build in-memory structures to organize records; when these do not fit, Spark spills them to disk, which adds disk I/O and garbage collection.[1] Spill files go to the scratch directories in spark.local.dir (default /tmp), and data spilled during shuffles is compressed by default (spark.shuffle.spill.compress).[3]
Spill is not the same as shuffle files. Shuffle files are the normal output of the map side of a shuffle, written by every shuffle; spill files are temporary overflow inside one task. A shuffle with no spill still writes shuffle files.[1]
Spill metrics in the Spark UI
The Spark UI reports spill in two places.
- Stage page. The task summary and the per-executor table show Shuffle spill (memory), the size of the spilled data in its deserialized form in memory, and Shuffle spill (disk), the size of its serialized form on disk.[4] The memory figure is usually the larger of the two, because the serialized and compressed form on disk is smaller.
- SQL tab. Operators such as
SortandHashAggregateshow aspill sizemetric (bytes spilled to disk by that operator) next topeak memory.[4]
The same numbers are in the task metrics of the REST API and event log as memoryBytesSpilled and diskBytesSpilled.[5]
What causes spill?
- Too few shuffle partitions. Each task gets a larger slice of data.
spark.sql.shuffle.partitionsdefaults to 200; with Adaptive Query Execution on, Spark starts from that number and coalesces small partitions.[6] - Data skew. One task gets most of the data, so only that task spills.
- Little execution memory per task. All running tasks on an executor share its execution memory, so more cores per executor means less memory per task. The region size is set by
spark.executor.memoryandspark.memory.fraction(default 0.6).[2][3] - Large cached datasets. Cached blocks occupy storage memory. Execution can evict them, but only down to
spark.memory.storageFraction(default 0.5) of the region.[2]
Common fixes follow from the causes: more shuffle partitions, fixing skew, more memory per executor or fewer cores per executor, and caching less. A small amount of spill is normal; it matters when spill dominates a stage's run time.
Spill compared across engines
| Apache Spark | Trino | Apache Flink | |
|---|---|---|---|
| Default behaviour | Always on; tasks spill execution data when memory runs out[1] | Off (spill-enabled defaults to false); without it, queries over the memory limits are killed[7][8]
|
For batch jobs, Flink spills to disk when managed memory is not enough[9] |
| Memory that spills | Execution memory in the executor's unified region (heap, or off-heap if enabled)[2] | Revocable memory, which does not count toward query limits and which the memory manager can take back[8] | Managed memory, native (off-heap) memory used for sorting, hash tables and cached intermediate results; by default 0.4 of total Flink memory (taskmanager.memory.managed.fraction)[10][11]
|
| Where spill goes | spark.local.dir[3]
|
spiller-spill-path, which must be set when spilling is on; a comma-separated list spreads spill over several disks[7]
|
io.tmp.dirs (default: the JVM temporary directory), which also holds RocksDB files and cached jars[11]
|
| Operations that spill | Shuffle, sort, aggregation and join structures[1][4] | Joins, aggregations, ORDER BY and window functions[8]
|
Batch algorithms such as external sorts and hash joins[11] |
| Status | Core part of execution | The Trino docs call spill to disk legacy functionality and point to fault-tolerant execution with the task retry policy instead[8] | Core part of batch execution |
In Trino, spill is enabled per cluster and is limited by max-spill-per-node (all queries on a node) and query-max-spill-per-node (one query on a node), both 100GB by default.[7] The Trino docs warn that a query forced to spill may run orders of magnitude longer than one that runs in memory, and that spill does not guarantee that every memory-intensive query will succeed.[8]
See also
References
- ↑ 1.0 1.1 1.2 1.3 1.4 RDD Programming Guide: Shuffle operations (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ 2.0 2.1 2.2 2.3 2.4 Tuning Spark (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ 3.0 3.1 3.2 Spark Configuration (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ 4.0 4.1 4.2 Web UI (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ Monitoring and Instrumentation (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ Performance Tuning (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ 7.0 7.1 7.2 Spilling properties (Trino 484). Trino Software Foundation.Retrieved 2026-11-23.
- ↑ 8.0 8.1 8.2 8.3 8.4 Spill to disk (Trino 484). Trino Software Foundation.Retrieved 2026-11-23.
- ↑ Memory tuning guide (Apache Flink 2.3). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ Set up TaskManager Memory (Apache Flink 2.3). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ 11.0 11.1 11.2 Configuration (Apache Flink 2.3). Apache Software Foundation.Retrieved 2026-11-23.