gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 10:01:39 25 4
gpt4 key购买 nike

我们需要通过 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com