【问题标题】:The memory of cgroup rss is much higher than the summary of the memory usage of all processes in the docker containercgroup rss的内存远高于docker容器内所有进程的内存使用汇总
【发布时间】:2021-06-22 02:15:59
【问题描述】:

我有一个在容器中运行的 Redis。 容器内的 cgroup rss show 使用了大约 1283MB 内存。

kmem 内存使用量为 30.75MB。

docker容器中所有进程的内存使用情况汇总为883MB。

我如何找出“消失的内存”(1296-883-30=383MB)。“消失的内存”会随着时间的推移而增长。最终容器将被 oom 杀死。

环境信息是

redis version:4.0.1

docker version:18.09.9

k8s version:1.13

**内存使用量为1283MB **

root@redis-m-s-rbac-0:/opt#cat /sys/fs/cgroup/memory/memory.usage_in_bytes 
1346289664  >>>> 1283.921875 MB

kmem 内存使用量为 30.75MB

root@redis-m-s-rbac-0:/opt#cat /sys/fs/cgroup/memory/memory.kmem.usage_in_bytes 
32194560  >>> 30.703125 MB
root@redis-m-s-rbac-0:/opt#cat /sys/fs/cgroup/memory/memory.stat 
cache 3358720
rss 1359073280 >>>  1296.11328125 MB
rss_huge 515899392
shmem 0
mapped_file 405504
dirty 0
writeback 0
swap 0
pgpgin 11355630
pgpgout 11148885
pgfault 25710366
pgmajfault 0
inactive_anon 0
active_anon 1359245312
inactive_file 2351104
active_file 1966080
unevictable 0
hierarchical_memory_limit 4294967296
hierarchical_memsw_limit 4294967296
total_cache 3358720
total_rss 1359073280
total_rss_huge 515899392
total_shmem 0
total_mapped_file 405504
total_dirty 0
total_writeback 0
total_swap 0
total_pgpgin 11355630
total_pgpgout 11148885
total_pgfault 25710366
total_pgmajfault 0
total_inactive_anon 0
total_active_anon 1359245312
total_inactive_file 2351104
total_active_file 1966080
total_unevictable 0

**docker容器中所有进程的内存使用情况汇总为883MB **

root@redis-m-s-rbac-0:/opt#ps aux | awk '{sum+=$6} END {print sum / 1024}'
883.609

【问题讨论】:

标签: docker kubernetes memory redis cgroups


【解决方案1】:

这是因为usage_in_bytes 没有显示内存和交换使用的确切值。 memory.usage_in_bytes 显示当前内存(RSS+缓存)使用情况。

5.5 usage_in_bytes 为了效率,内存 cgroup 和其他内核组件一样,使用了一些优化来避免不必要的 cacheline 虚假分享。 usage_in_bytes 受方法影响,不影响 显示内存(和交换)使用的“确切”值,这是一个模糊值 有效的访问。 (当然,必要时,它是同步的。)如果 你想知道更准确的内存使用情况,你应该使用 memory.stat 中的 RSS+CACHE(+SWAP) 值(见 5.2)。

参考: https://www.kernel.org/doc/Documentation/cgroup-v1/memory.txt

【讨论】:

猜你喜欢
  • 2018-11-24
  • 2012-09-11
  • 2022-06-14
  • 2023-04-05
  • 2018-05-28
  • 2019-06-26
  • 2012-05-09
  • 2013-09-28
相关资源
最近更新 更多