Re-read cgroup memory limit at runtime to support in-place pod resize (GA in Kubernetes 1.35)
Is your feature request related to a problem? Please describe
All VM components read the cgroup memory limit once at startup (lib/memory via lib/cgroup.GetMemoryLimit()) and cache it for the process lifetime. Kubernetes in-place pod resize (KEP-1287) graduated to stable in v1.35, and VPA's InPlaceOrRecreate mode now changes container memory limits under running processes as a normal, supported operation — no restart involved. The cached value goes stale, with three consequences:
- False self-monitoring.
vm_available_memory_byteskeeps reporting the boot-time limit, so the stockvm-healthalertTooHighMemoryUsagemisfires. Observed on our staging (K8s v1.35.2, VPA 1.5.1 withInPlaceOrRecreate, vminsert v1.147.0-cluster, operator v0.73.1): VPA in-place resized the container from 128Mi to 412Mi limit; vminsert still reported 128Mi available, RSS reached 131Mi, and the alert fired at "102% memory usage" while the process actually sat at ~32% of its real limit. - Under-utilization after scale-up. The component keeps sizing caches/buffers against the old smaller limit and never uses the memory it was granted until an unrelated restart.
- OOM risk after scale-down. Kubernetes 1.35 GA explicitly lifted the prohibition on memory-limit decreases. A component that keeps budgeting toward the old, higher limit will run into the new lower cgroup limit and be OOM-killed — by design of the stale cache, not by actual memory pressure.
Note that the VictoriaMetrics operator itself exposes a first-class vpa field (EmbeddedVPA) on its CRDs (per-role on VMCluster since v0.69.0, VMAgent/VMSingle/etc. since v0.72.0), so this isn't an external-integration concern — the operator's own VPA feature produces exactly the limit changes that lib/memory can never observe.
This was raised as a question in #5767 (Feb 2024) but predates the feature going GA; filing as a feature request now that mutable limits are a stable platform contract.
Describe the solution you'd like
Tiered, in increasing order of effort:
- Minimum: periodically re-read the cgroup limit (a single file read, e.g. every 10–30s) and update
vm_available_memory_bytes, so self-monitoring and the shipped alerting rules stay truthful. - Better: on detecting a change, recompute the runtime-adjustable derived caps — concurrency limiters, new-allocation budgets,
debug.SetMemoryLimit— while documenting that fixed-size caches (fastcache) only re-size on restart. - Alternatively/additionally: an explicit
SIGHUPre-read, consistent with the existing config-reload convention.
Additional information
- Kubernetes blog: In-Place Pod Resize graduates to stable in v1.35
- Related: #5767
Source: VictoriaMetrics/VictoriaMetrics