zl程序教程

您现在的位置是:首页 >  后端

当前栏目

k8s pod 内存 所以判断container_memory_working_set_bytes会比container_memory_usage_bytes更为准确

k8s内存set 判断 memory Pod container 准确
2023-09-11 14:20:30 时间

container_memory_working_set_bytes = container_memory_usage_bytes - total_inactive_anon - total_inactive_file
memory used =container_memory_usage_bytes - cache
cache = total_inactive_file + total_active_file
PS:kubelet比较container_memory_working_set_bytes和container_spec_memory_limit_bytes来决定oom container

total_inactive_anon、total_inactive_file为非活动内存,可以被交换到磁盘 cache 缓存存储器存储当前保存在内存中的磁盘数据,所以判断container_memory_working_set_bytes会比container_memory_usage_bytes更为准确

这里workingSet的计算是先比较memory.memory.usage_in_bytes的大小是不是比memory.stats里面的total_inactive_file小,如果没有,就减去total_inactive_file的值,最后为workingSet的值,这部分的值我们可以认为是linux占用的hot(正在使用)内存值(容器同理)。

https://segmentfault.com/a/1190000021402244?utm_source=tag-newest
https://blog.csdn.net/palet/article/details/82889493
https://zhuanlan.zhihu.com/p/96597715
https://www.ibm.com/support/pages/kubectl-top-pods-and-docker-stats-show-different-memory-statistics
kubectl top 12.5G

container_memory_working_set_bytes = container_memory_usage_bytes - total_inactive_anon - total_inactive_file
rss = total_inactive_anon + total_active_anon
cache = total_inactive_file + total_active_file

kubelet比较container_memory_working_set_bytes和container_spec_memory_limit_bytes来决定oom container