Jump to content

Executor memory overhead

From Open Lakehouse Wiki
Executor memory overhead
Also known as spark.executor.memoryOverhead, memory overhead, non-heap memory
Field Distributed data processing
Key parts JVM native memory, Python workers, other processes in the container, container memory limit
Open source implementations Apache Spark on YARN and Kubernetes
Related Spark memory management, Executor, Garbage collection in Spark
Last verified 23 November 2026 against the v4.3.0 tag of apache/spark (docs/configuration.md, docs/running-on-kubernetes.md, docs/running-on-yarn.md), Hadoop yarn-default.xml (stable docs) and the Kubernetes "Assign Memory Resources to Containers" task page.

In Apache Spark, executor memory overhead is the memory that Spark requests for each executor container on top of the JVM heap, to cover everything in the container that is not on the heap: JVM internals, native libraries, Python worker processes and other processes. It is set by spark.executor.memoryOverhead and applies on YARN and Kubernetes.[1] When the executor process as a whole uses more memory than its container allows, the cluster manager kills the container, even if the JVM heap still has room.

How is memory overhead sized?

By default, spark.executor.memoryOverhead is spark.executor.memory × spark.executor.memoryOverheadFactor, with a minimum of spark.executor.minMemoryOverhead.[1]

Setting Default Since
spark.executor.memoryOverhead executor memory × factor, at least the minimum 2.3.0
spark.executor.memoryOverheadFactor 0.10; 0.40 for non-JVM jobs on Kubernetes 3.3.0
spark.executor.minMemoryOverhead 384 MiB 4.0.0

Source: Spark 4.3.0 configuration reference.[1]

The full container size is the sum of spark.executor.memory, spark.executor.memoryOverhead, spark.memory.offHeap.size and spark.executor.pyspark.memory.[1] An executor with spark.executor.memory=8g and no other settings gets about 819 MiB of overhead, so a container of about 9 GiB. The higher factor for non-JVM jobs on Kubernetes exists because, in the words of the Spark docs, such tasks "commonly fail with 'Memory Overhead Exceeded' errors".[1]

What lives outside the JVM heap?

  • JVM and native overheads. The Spark docs list VM overheads, interned strings and other native overheads.[1]
  • Python workers. In PySpark, Python worker processes run beside the executor JVM in the same container. Their memory is counted in the overhead unless spark.executor.pyspark.memory is set, in which case it is a separate, limited amount added to the container request.[1] Python UDFs and pandas UDFs that load large objects use this memory.
  • Other processes in the container. Anything else started in the executor's container counts against the overhead.[1]
  • RAM-backed local directories on Kubernetes. With spark.kubernetes.local.dirs.tmpfs=true, shuffle and spill files live in memory and count toward the pod's memory, so the overhead factor should be raised.[2]

Off-heap memory set with spark.memory.offHeap.size is not part of the overhead; it is added to the container separately.[1] See Spark memory management.

Why do executor containers get killed?

YARN and Kubernetes both enforce the container's memory limit from outside the JVM. The JVM heap cannot grow beyond spark.executor.memory, but native and Python memory can, and when the process as a whole goes over the limit the container is terminated.

  • On YARN, the NodeManager enforces physical memory limits for containers by default (yarn.nodemanager.pmem-check-enabled, default true).[3]
  • On Kubernetes, a container that allocates more memory than its limit becomes a candidate for termination; the pod status then shows OOMKilled and exit code 137.[4] The Spark Kubernetes docs also describe exit code 137 as a SIGKILL, possibly a container OOM, and exit code 52 as a JVM out-of-memory error.[2]

A container kill and a JVM OutOfMemoryError are different failures. A JVM heap OOM means the heap was too small for the task; the fix is more spark.executor.memory, more partitions, or less data per task. A container kill with a healthy heap means the non-heap side was too small; the fix is more overhead, setting spark.executor.pyspark.memory, or reducing native or Python memory use. On YARN, Spark 4.3.0 adds -XX:OnOutOfMemoryError='kill %p' to executor JVM options by default (spark.yarn.executor.oomKill.enabled), so a heap OOM also ends the executor process.[5]

Spark 4.3.0 on Kubernetes can also react to these failures with org.apache.spark.scheduler.cluster.k8s.ExecutorResizePlugin, which is enabled by registering it in spark.plugins. Every spark.kubernetes.executor.resizeInterval, the driver reads each executor container's memory usage, and when usage exceeds spark.kubernetes.executor.resizeThreshold of the current limit it raises the memory request and limit in place by spark.kubernetes.executor.resizeFactor, with no configured upper bound. It requires Kubernetes 1.33 or later (in-place pod resize through the pods/resize subresource), a metrics server or other provider of the metrics.k8s.io API, and a driver service account allowed to list pods, get pods in the metrics.k8s.io API group and patch pods/resize. The heap size does not change, so the extra memory goes to off-heap and native use, and Kubernetes may reject or defer a resize when the node lacks free memory.[6]

spark.plugins                              org.apache.spark.scheduler.cluster.k8s.ExecutorResizePlugin
spark.kubernetes.executor.resizeInterval   1m

Example

A PySpark job whose Python UDFs need about 2 GiB per executor:

spark.executor.memory            8g
spark.executor.memoryOverhead    1g
spark.executor.pyspark.memory    2g

Each executor container is then 11 GiB: 8 GiB heap, 1 GiB overhead and 2 GiB reserved for Python.[1]

See also

References

  1. ↑ 1.00 1.01 1.02 1.03 1.04 1.05 1.06 1.07 1.08 1.09 Spark Configuration (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
  2. ↑ 2.0 2.1 Running Spark on Kubernetes (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
  3. ↑ yarn-default.xml. Apache Software Foundation.Retrieved 2026-11-23.
  4. ↑ Assign Memory Resources to Containers and Pods. The Kubernetes Authors.Retrieved 2026-11-23.
  5. ↑ Running Spark on YARN (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
  6. ↑ Running Spark on Kubernetes: Executor Memory Resize (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.