kubectl top与docker stats内存不一致
名称 | 类型 | 单位 | 说明 |
---|---|---|---|
container_memory_rss | gauge | 字节数 bytes | RSS内存,即常驻内存集(Resident Set Size),是分配给进程使用实际物理内存,而不是磁盘上缓存的虚拟内存。RSS内存包括所有分配的栈内存和堆内存,以及加载到物理内存中的共享库占用的内存空间,但不包括进入交换分区的内存。 |
container_memory_usage_bytes | gauge | 字节数 bytes | 当前使用的内存量,包括所有使用的内存,不管有没有被访问。 |
container_memory_max_usage_bytes | gauge | 字节数 bytes | 最大内存使用量的记录。 |
container_memory_cache | gauge | 字节数 bytes | 高速缓存(cache)的使用量。cache是位于CPU与主内存间的一种容量较小但速度很高的存储器,是为了提高cpu和内存之间的数据交换速度而设计的 Size),是分配给进程使用实际物理内存,而不是磁盘上缓存的虚拟内存。RSS内存包括所有分配的栈内存和堆内存,以及加载到物理内存中的共享库占用的内存空间,但不包括进入交换分区的内存。 |
container_memory_swap | gauge | 字节数 bytes | 虚拟内存使用量。虚拟内存(swap)指的是用磁盘来模拟内存使用。当物理内存快要使用完或者达到一定比例,就可以把部分不用的内存数据交换到硬盘保存,需要使用时再调入物理内存 |
container_memory_working_set_bytes | gauge | 字节数 bytes | 当前内存工作集(working set)使用量。 |
container_memory_failcnt | counter | 次 | 申请内存失败次数计数。 |
container_memory_failures_total | counter | 次 | 累计的内存申请错误次数。 |
- 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更为准确
- https://segmentfault.com/a/1190000021402244?utm_source=tag-newest
- https://blog.****.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
docker stats 11.42G
memory_stats和memory.usage_in_bytes
使用kubectl top(container_memory_working_set_bytes) = memory.usage_in_bytes - inactive_file 可以得出数值12.5G
使用docker stats(memory used) = memory.usage_in_bytes - cache可以得到数值11.42G