我制作如下程序:
#include <stdio.h>
int main(int argc, char *argv[])
{
int sec = 1;
sec = atoi(argv[1]);
while(1) {
sleep(sec);
}
}
运行它时,我得到它的pid并检查其/ proc / $ pid / status,如下所示:
# cat status | grep Vm
VmPeak: 1580 kB
VmSize: 1580 kB
VmLck: 0 kB
VmPin: 0 kB
VmHWM: 156 kB
VmRSS: 156 kB
VmData: 44 kB
VmStk: 132 kB
VmExe: 4 kB
VmLib: 1316 kB
VmPTE: 16 kB
VmPMD: 12 kB
VmSwap: 0 kB
所以VmRSS是156 kB。
然后我检查其smaps文件中的Rss值,如下所示:
cat smaps | grep Pss -B 3
00400000-00401000 r-xp 00000000 00:13 95 /data/test_hello
Size: 4 kB
Rss: 4 kB
Pss: 4 kB
--
Shared_Hugetlb: 0 kB
Private_Hugetlb: 0 kB
Swap: 0 kB
SwapPss: 0 kB
--
00410000-00411000 rw-p 00000000 00:13 95 /data/test_hello
Size: 4 kB
Rss: 4 kB
Pss: 4 kB
--
Shared_Hugetlb: 0 kB
Private_Hugetlb: 0 kB
Swap: 0 kB
SwapPss: 0 kB
--
7f8acd2000-7f8adfe000 r-xp 00000000 00:0e 3167 /lib/libc-2.23.so
Size: 1200 kB
Rss: 476 kB
Pss: 19 kB
--
Shared_Hugetlb: 0 kB
Private_Hugetlb: 0 kB
Swap: 0 kB
SwapPss: 0 kB
--
7f8adfe000-7f8ae0d000 ---p 0012c000 00:0e 3167 /lib/libc-2.23.so
Size: 60 kB
Rss: 0 kB
Pss: 0 kB
--
Shared_Hugetlb: 0 kB
Private_Hugetlb: 0 kB
Swap: 0 kB
SwapPss: 0 kB
--
7f8ae0d000-7f8ae11000 r--p 0012b000 00:0e 3167 /lib/libc-2.23.so
Size: 16 kB
Rss: 16 kB
Pss: 16 kB
--
Shared_Hugetlb: 0 kB
Private_Hugetlb: 0 kB
Swap: 0 kB
SwapPss: 0 kB
--
7f8ae11000-7f8ae13000 rw-p 0012f000 00:0e 3167 /lib/libc-2.23.so
Size: 8 kB
Rss: 8 kB
Pss: 8 kB
--
Shared_Hugetlb: 0 kB
Private_Hugetlb: 0 kB
Swap: 0 kB
SwapPss: 0 kB
--
7f8ae13000-7f8ae17000 rw-p 00000000 00:00 0
Size: 16 kB
Rss: 8 kB
Pss: 8 kB
--
Shared_Hugetlb: 0 kB
Private_Hugetlb: 0 kB
Swap: 0 kB
SwapPss: 0 kB
--
7f8ae17000-7f8ae33000 r-xp 00000000 00:0e 3152 /lib/ld-2.23.so
Size: 112 kB
Rss: 112 kB
Pss: 3 kB
--
Shared_Hugetlb: 0 kB
Private_Hugetlb: 0 kB
Swap: 0 kB
SwapPss: 0 kB
--
7f8ae3e000-7f8ae40000 rw-p 00000000 00:00 0
Size: 8 kB
Rss: 8 kB
Pss: 8 kB
--
Shared_Hugetlb: 0 kB
Private_Hugetlb: 0 kB
Swap: 0 kB
SwapPss: 0 kB
--
7f8ae40000-7f8ae41000 r--p 00000000 00:00 0 [vvar]
Size: 4 kB
Rss: 0 kB
Pss: 0 kB
--
Shared_Hugetlb: 0 kB
Private_Hugetlb: 0 kB
Swap: 0 kB
SwapPss: 0 kB
--
7f8ae41000-7f8ae42000 r-xp 00000000 00:00 0 [vdso]
Size: 4 kB
Rss: 4 kB
Pss: 0 kB
--
Shared_Hugetlb: 0 kB
Private_Hugetlb: 0 kB
Swap: 0 kB
SwapPss: 0 kB
--
7f8ae42000-7f8ae43000 r--p 0001b000 00:0e 3152 /lib/ld-2.23.so
Size: 4 kB
Rss: 4 kB
Pss: 4 kB
--
Shared_Hugetlb: 0 kB
Private_Hugetlb: 0 kB
Swap: 0 kB
SwapPss: 0 kB
--
7f8ae43000-7f8ae45000 rw-p 0001c000 00:0e 3152 /lib/ld-2.23.so
Size: 8 kB
Rss: 8 kB
Pss: 8 kB
--
Shared_Hugetlb: 0 kB
Private_Hugetlb: 0 kB
Swap: 0 kB
SwapPss: 0 kB
--
7fc8b96000-7fc8bb7000 rw-p 00000000 00:00 0 [stack]
Size: 132 kB
Rss: 12 kB
Pss: 12 kB
--
Shared_Hugetlb: 0 kB
Private_Hugetlb: 0 kB
Swap: 0 kB
SwapPss: 0 kB
#
如您所见,仅对于libc部分,Rss值已经比VmRSS值大得多。为什么?
7f8acd2000-7f8adfe000 r-xp 00000000 00:0e 3167 /lib/libc-2.23.so
Size: 1200 kB
Rss: 476 kB
Pss: 19 kB