3月 272017
 

缘起:

监控(docker stats)显示容器内存被用完了,进入容器瞅了瞅,没有发现使用内存多的进程,使用awk等工具把容器所有进程使用的内存加起来看看,距离用完还远了去了,何故?

分析:

该不会docker stats计算错误?

进入/sys/fs/cgroup/memory/docker/xxxxx/ 查看memory.usage ,确认计算没有错误

 

我们知道,系统内存会有一部分被buffer、cache之类占用,linux也会把这部分内存算到已使用,对于容器来讲,也应该存在此“问题”,而且非常有可能linux会把某容器引发的cache占用算到容器占用的内存上;验证很简单,进容器dd一个大文件就知道了:

dd 大文件后,docker stat显示已用内存变多

宿主机上: echo 3 > /proc/sys/vm/drop_caches 后,docker stat显示已用内存变少

 

至此,原因查明

问题:

对于宿主机来讲,计算内存占用时,可以拿已用内存减去cache/buffer ,那么对于容器来讲,如果减去容器部分的cache/buffer 呢?如果不减去,也会造成误报警

 

测试发现: dd 产生的文件cache占用的内存会计算到 inactive_file 的头上

参考: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Resource_Management_Guide/sec-memory.html

 

 Posted by at 下午 5:30

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

(required)

(required)

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据