/proc/pid/smaps 中的 pss 是什么意思 [英] What does pss mean in /proc/pid/smaps

查看:16
本文介绍了/proc/pid/smaps 中的 pss 是什么意思的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对/proc/pid/smaps中的Pss列感到困惑,所以我写了一个程序来测试它:

void sa();int main(int argc,char *argv[]){国际金融;萨();睡眠(1000);}无效的sa(){字符 *pi=新字符[1024*1024*10];for(int i=0;i<4;++i) {for(int j=0;j<1024*1024;++j){*pi='o';pi++;}}int cnt;for(int i=0;i<6;++i) {for(int j=0;j<1024*1024;++j){cnt+=*pi;pi++;}}printf("%d",cnt);}

$cat/proc/`pidof testprogram`/smaps08838000-0885b000 rw-p 00000000 00:00 0 [堆]大小:140 KBRSS:12 KB附:12 KBShared_Clean: 0 kBShared_Dirty: 0 kBPrivate_Clean: 0 kBPrivate_Dirty:12 KB参考:12 kB交换:0 KB内核页面大小:4 kBMMUPageSize:4 kBb6dcd000-b77d0000 rw-p 00000000 00:00 0大小:10252 KBRSS:10252 KB附注:4108 KBShared_Clean: 0 kBShared_Dirty: 0 kBPrivate_Clean: 0 kBPrivate_Dirty:4108 KB参考:4108 kB交换:0 KB内核页面大小:4 kBMMUPageSize:4 kB

在这里我发现 Pss 等于 Private_Dirty,但我想知道为什么.

顺便说一句:smaps 有没有详细的文档?

解决方案

引用自 lwn.net

<块引用>

进程的比例集大小"(PSS)是页数它在内存中,其中每页除以进程共享它.所以如果一个进程本身有 1000 个页面,1000 与另一个进程共享,其 PSS 将为 1500

来自 Linux 内核文档

/proc/PID/smaps是基于map的扩展,显示内存每个进程的映射的消耗.对于每个映射有是一系列如下所示的行:

08048000-080bc000 r-xp 00000000 03:02 13130/bin/bash大小:1084 KBRSS:892 KB附:374 KBShared_Clean:892 KBShared_Dirty: 0 kBPrivate_Clean: 0 kBPrivate_Dirty:0 KB参考:892 kB匿名:0 kB交换:0 KB内核页面大小:4 kBMMUPageSize:4 kB锁定:374 KB

<块引用>

这些行中的第一行显示的信息与显示的相同对于 /proc/PID/maps 中的映射.其余行显示大小映射(大小),当前映射的数量驻留在 RAM (RSS) 中,进程在此映射中的比例份额(PSS),映射中干净和脏的私有页面的数量.请注意,即使页面是 MAP_SHARED 映射的一部分,但具有只有一个 pte 被映射,即当前只被一个进程使用,被视为私有而不是共享.引用"表示当前标记为引用或访问的内存量.匿名"显示不属于任何人的内存量文件.甚至与文件关联的映射也可能包含匿名pages:当 MAP_PRIVATE 和一个页面被修改时,文件页面是由私人匿名副本代替.交换"显示了多少也使用了匿名内存,但在交换时使用.

这个问题 on Unix and Linux Stackexchange 几乎涵盖了这个主题.请参阅 Mat 的出色回答,它肯定会消除您的所有疑虑.

I was confused about the Pss column in /proc/pid/smaps, so I wrote a program to test it:

void sa();
int main(int argc,char *argv[])
{
    int fd;
    sa();
    sleep(1000);
}

void sa()
{
   char *pi=new char[1024*1024*10];
   for(int i=0;i<4;++i) {
        for(int j=0;j<1024*1024;++j){
                *pi='o';
                pi++;
        }
   }
   int cnt;
   for(int i=0;i<6;++i) {
        for(int j=0;j<1024*1024;++j){
                cnt+=*pi;
                pi++;
        }
   }
   printf("%d",cnt);
}

$cat /proc/`pidof testprogram`/smaps

08838000-0885b000 rw-p 00000000 00:00 0          [heap]
Size:                140 kB
Rss:                  12 kB
Pss:                  12 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:        12 kB
Referenced:           12 kB
Swap:                  0 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
b6dcd000-b77d0000 rw-p 00000000 00:00 0 
Size:              10252 kB
Rss:               10252 kB
Pss:                4108 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:      4108 kB
Referenced:         4108 kB
Swap:                  0 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB

Here I found Pss equal to Private_Dirty, but I wonder why.

BTW: Is there any detailed documentation for smaps?

解决方案

Quoting from lwn.net

The "proportional set size" (PSS) of a process is the count of pages it has in memory, where each page is divided by the number of processes sharing it. So if a process has 1000 pages all to itself, and 1000 shared with one other process, its PSS will be 1500

From Linux Kernel Documentation,

The /proc/PID/smaps is an extension based on maps, showing the memory consumption for each of the process's mappings. For each of mappings there is a series of lines such as the following:

08048000-080bc000 r-xp 00000000 03:02 13130      /bin/bash
Size:               1084 kB
Rss:                 892 kB
Pss:                 374 kB
Shared_Clean:        892 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:         0 kB
Referenced:          892 kB
Anonymous:             0 kB
Swap:                  0 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Locked:              374 kB

The first of these lines shows the same information as is displayed for the mapping in /proc/PID/maps. The remaining lines show the size of the mapping (size), the amount of the mapping that is currently resident in RAM (RSS), the process' proportional share of this mapping (PSS), the number of clean and dirty private pages in the mapping. Note that even a page which is part of a MAP_SHARED mapping, but has only a single pte mapped, i.e. is currently used by only one process, is accounted as private and not as shared. "Referenced" indicates the amount of memory currently marked as referenced or accessed. "Anonymous" shows the amount of memory that does not belong to any file. Even a mapping associated with a file may contain anonymous pages: when MAP_PRIVATE and a page is modified, the file page is replaced by a private anonymous copy. "Swap" shows how much would-be-anonymous memory is also used, but out on swap.

This Question on Unix and Linux Stackexchange covers almost the topic. See Mat's excellent answer which will surely clear all your doubts.

这篇关于/proc/pid/smaps 中的 pss 是什么意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆