如何在没有写时复制页面的情况下测量内存?


8

如何在不对共享页面和写入时复制页面进行重复计数的情况下,衡量一组(分叉)进程所占用的RSS总内存?


1
非常有趣的问题+1- /proc/*/map尽管我从未找到能做到这一点的工具,但通过对文件的更深入分析,应该有可能。主要的问题在于,要遵循的数据结构看起来要复杂得多。如果您在这里没有很好的答案,也许您也可以尝试unix SE。
peterh-恢复莫妮卡

Answers:


4

我最终为此编写了自己的实用程序:https : //gist.github.com/Eugeny/04ccfe8accf4bc74b0ca

我将其与init(pid 1)进行了测试,报告的总数大致等于物理ram的使用量(按htop),因此我想这是正确的。

使用示例:

~ » pstree -ap 15897
zsh,15897
  └─sudo,9783 make rundev
      └─make,9784 rundev
          └─sh,9785 -c cd ajenti-panel && ./ajenti-panel -v --autologin --plugins ../plugins --dev
              └─python ./ajenti,9786
                  ├─./ajenti-panel ,9834                              
                  ├─./ajenti-panel ,9795                     
                  └─{python ./ajenti},9796

~ » sudo ./memuse.py 15897
PID                 Commandline                          Frames (+unique)           VMEM
 - 15897            (/usr/bin/zsh                  ):      1776  +1776           7104 KB
  -  9783           (sudo make rundev              ):       608  +408            2432 KB
   -  9784          (make rundev                   ):       261  +98             1044 KB
    -  9785         (/bin/sh -c cd ajenti-panel && ):       166  +48              664 KB
     -  9786        (python ./ajenti-panel -v --aut):      9279  +8977          37116 KB
      -  9795       (./ajenti-panel worker [restric):      7637  +1334          30548 KB
      -  9834       (./ajenti-panel worker [session):      8972  +2639          35888 KB
----------------------------------------------------------------------------------------
TOTAL:                                                    15280                 61120 KB

2

我知道在任何工具中都没有明确定义的方法来确定哪些进程共享哪些映射,而无需遍历所有映射和比较地址。

但是,Linux确实提供了合理的估计,称为“ 比例集大小”。报告在/ proc / [pid]> / maps中。

该值是映射的大小除以打开了相同映射的同级/父进程的数量。

因此,对于具有1MiB映射打开的程序,以及与4个其他进程共享的1MiB,程序集的大小为1MiB +(1Mib / 4)或1.250 MiB。在这种情况下,RSS为2MiB。

有一个用于htop浮动的补丁,该补丁将使用PSS来计算使用中的实际内存的“良好估计”。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.