Currently the total used memory is pulling from /sys/fs/cgroup/memory/memory.usage_in_bytes which provides the total used memory, including reclaimable caches. K8s uses the RSS memory (or something approximate to it) when calculating memory use for evictions. This is throwing the % calculation out by a significant factor, causing pods to be flagged as failed before k8s would consider them to be in any OOMKiller danger.
The RSS for the cgroup can be pulled from /sys/fs/cgroup/memory/memory.stat but the parsing is a bit more challenging. The last time I wrote any C was about 15 years ago but I managed to cobble something together which uses a regex to match the appropriate line and adjust the calculation accordingly.
Currently the total used memory is pulling from
/sys/fs/cgroup/memory/memory.usage_in_bytes
which provides the total used memory, including reclaimable caches. K8s uses the RSS memory (or something approximate to it) when calculating memory use for evictions. This is throwing the % calculation out by a significant factor, causing pods to be flagged as failed before k8s would consider them to be in any OOMKiller danger.The RSS for the cgroup can be pulled from
/sys/fs/cgroup/memory/memory.stat
but the parsing is a bit more challenging. The last time I wrote any C was about 15 years ago but I managed to cobble something together which uses a regex to match the appropriate line and adjust the calculation accordingly.Fancy a PR?