How to configure memory limits in Kubernetes (memory.min, memory.max, memory.high) (Edited)
How should I properly configure memory limits in Kubernetes using cgroup v2 parameters (memory.min, memory.max, memory.high)?
I am setting memory limits for containers in Kubernetes, which uses cgroup v2. In the Kubernetes manifest, I define memory.request and memory.limit, which are translated into the following cgroup parameters:
memory.min =
memory.max = memory.high = * 0.8 # memory.low = not set
When the memory.max limit is exceeded, the OOM killer is triggered. But how should I correctly use memory.high? What happens when a container exceeds this threshold? Is there any point in configuring memory.high if there is no swap on the Kubernetes nodes and only cache pages can be reclaimed?
Would it be better to simply configure a lower memory.max if using memory.high doesn’t provide significant benefits?
Answers
Rasmus Sørensen
7 months ago
Rating
If your application heavily utilizes cache (e.g., for storing file data or libraries), memory.high can help avoid a sudden OOM kill by giving the system time to free up cache and allow the container to continue running. This is useful if the cache can be regenerated.
If the application doesn’t rely much on caching, the effect of memory.high will be minimal. In such cases, it might be simpler to set a lower memory.max and monitor memory usage more closely.
Erik Pedersen
7 months ago
Rating
When a container exceeds the memory.high threshold, it triggers "high memory reclaim pressure," meaning the system will start throttling the container by attempting to reclaim memory pages without triggering the OOM killer. However, if there is no swap on the node, the only memory that can be reclaimed is from the page cache. This cache would still be reclaimed when memory.max is reached, so memory.high may simply slow down the container without providing significant benefits.