linux - 从/proc/$PID/smaps 读取很慢

标签 linux linux-kernel cron

我们需要通过 cron 每分钟监控我们高负载服务的内存使用情况。

为此,我们正在读取 /proc/PID/smaps 并以某种方式解析它。

但我们每时每刻都在遇到计时问题。 关闭监控 cron 时,不存在计时问题。

我们代码中唯一昂贵且可疑的操作是读取/proc/PID/smaps

在读取 smaps 时,Linux 内核中是否有任何锁/互斥锁/其他东西?

还有其他更透明的方法来检测内存使用情况吗?

最佳答案

根据我的研究,读取/proc/PID/smaps 的成本与进程的内存使用量相关。 看起来内核正忙于检查每个内存页的状态以生成内容。 read smaps cost vs mem usage

"/proc/[pid]/stat"可以告诉您一些有关内存使用情况的信息,例如:

          (23) vsize  %lu
                    Virtual memory size in bytes.

          (24) rss  %ld
                    Resident Set Size: number of pages the process has
                    in real memory.  This is just the pages which count
                    toward text, data, or stack space.  This does not
                    include pages which have not been demand-loaded in,
                    or which are swapped out.

读取此文件的速度很快。

关于linux - 从/proc/$PID/smaps 读取很慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42003801/

相关文章:

python - 如何在 python 中获得单调持续时间?

linux - haskell 中的 Latexpdf 式功能?

linux - 关于linux信号的一些问题

c++ - 如何将目录路径转换为唯一的数字标识符 (Linux/C++)?

单个管道可以用于父级和子级之间的双向通信吗?

cron - OpenERP 和 Gunicorn

java - 如何在指定次数后停止 quartz cron 调度程序?

linux - Linux内核参数中modprobe.blacklist和rd.driver.blacklist的区别

linux - 如何从 Linux 内核镜像获取 .config?

python - Crontab 模式每年运行一次脚本/一生一次