linux如何对c++进行内存分析

linux如何对c++进行内存分析

背景

在工作中,我遇到一个问题,需要将c写的进程部署到MCU上。由于MCU上可用的RAM 非常有限,所以在部署时就需要考虑到使用内存大小。所以为了搞清楚,内存的主要消耗在那一块。

分析方法以及原理

原理

在linux 中每个进程在proc 中都有一个对应的文件存储其重要信息。其命令如下:
bash 复制代码
#!/bin/bash

pid=`ps -ef | grep process_name`  # 找到pid
cat /proc/${pid}/smaps   # 这个文件中存储该进程的所有内存映射

其结果如下这是一个例子:

bash 复制代码
5d76f76fb000-5d76f76fc000 r--p 00000000 08:03 3721356                    /home/lhd/fastdds_repo/tmp/micro-dds-client/micro_client/examples/SubscribeHelloWorld/build/SubscribeHelloWorldClient
Size:                  4 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Rss:                   4 kB
Pss:                   4 kB
Pss_Dirty:             4 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:         4 kB
Referenced:            4 kB
Anonymous:             0 kB
KSM:                   0 kB
LazyFree:              0 kB
AnonHugePages:         0 kB
ShmemPmdMapped:        0 kB
FilePmdMapped:         0 kB
Shared_Hugetlb:        0 kB
Private_Hugetlb:       0 kB
Swap:                  0 kB
SwapPss:               0 kB
Locked:                0 kB
THPeligible:           0
VmFlags: rd mr mw me sd 
5d76f76fc000-5d76f7705000 r-xp 00001000 08:03 3721356                    /home/lhd/fastdds_repo/tmp/micro-dds-client/micro_client/examples/SubscribeHelloWorld/build/SubscribeHelloWorldClient
Size:                 36 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Rss:                  36 kB
Pss:                  36 kB
Pss_Dirty:            36 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:        36 kB
Referenced:           36 kB
Anonymous:             0 kB
KSM:                   0 kB
LazyFree:              0 kB
AnonHugePages:         0 kB
ShmemPmdMapped:        0 kB
FilePmdMapped:         0 kB
Shared_Hugetlb:        0 kB
Private_Hugetlb:       0 kB
Swap:                  0 kB
SwapPss:               0 kB
Locked:                0 kB
THPeligible:           0
VmFlags: rd ex mr mw me sd 
5d76f7705000-5d76f770b000 r--p 0000a000 08:03 3721356                    /home/lhd/fastdds_repo/tmp/micro-dds-client/micro_client/examples/SubscribeHelloWorld/build/SubscribeHelloWorldClient
Size:                 24 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Rss:                  24 kB
Pss:                  24 kB
Pss_Dirty:            24 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:        24 kB
Referenced:           24 kB
Anonymous:             0 kB
KSM:                   0 kB
LazyFree:              0 kB
AnonHugePages:         0 kB
ShmemPmdMapped:        0 kB
FilePmdMapped:         0 kB
Shared_Hugetlb:        0 kB
Private_Hugetlb:       0 kB
Swap:                  0 kB
SwapPss:               0 kB
Locked:                0 kB
THPeligible:           0
VmFlags: rd mr mw me sd 
5d76f770b000-5d76f770c000 r--p 0000f000 08:03 3721356                    /home/lhd/fastdds_repo/tmp/micro-dds-client/micro_client/examples/SubscribeHelloWorld/build/SubscribeHelloWorldClient
Size:                  4 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Rss:                   4 kB
Pss:                   4 kB
Pss_Dirty:             4 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:         4 kB
Referenced:            4 kB
Anonymous:             4 kB
KSM:                   0 kB
LazyFree:              0 kB
AnonHugePages:         0 kB
ShmemPmdMapped:        0 kB
FilePmdMapped:         0 kB
Shared_Hugetlb:        0 kB
Private_Hugetlb:       0 kB
Swap:                  0 kB
SwapPss:               0 kB
Locked:                0 kB
THPeligible:           0
VmFlags: rd mr mw me ac sd 
5d76f770c000-5d76f770d000 rw-p 00010000 08:03 3721356                    /home/lhd/fastdds_repo/tmp/micro-dds-client/micro_client/examples/SubscribeHelloWorld/build/SubscribeHelloWorldClient
Size:                  4 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Rss:                   4 kB
Pss:                   4 kB
Pss_Dirty:             4 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:         4 kB
Referenced:            4 kB
Anonymous:             4 kB
KSM:                   0 kB
LazyFree:              0 kB
AnonHugePages:         0 kB
ShmemPmdMapped:        0 kB
FilePmdMapped:         0 kB
Shared_Hugetlb:        0 kB
Private_Hugetlb:       0 kB
Swap:                  0 kB
SwapPss:               0 kB
Locked:                0 kB
THPeligible:           0
VmFlags: rd wr mr mw me ac sd 
5d76f965c000-5d76f967d000 rw-p 00000000 00:00 0                          [heap]
Size:                132 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Rss:                   4 kB
Pss:                   4 kB
Pss_Dirty:             4 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:         4 kB
Referenced:            4 kB
Anonymous:             4 kB
KSM:                   0 kB
LazyFree:              0 kB
AnonHugePages:         0 kB
ShmemPmdMapped:        0 kB
FilePmdMapped:         0 kB
Shared_Hugetlb:        0 kB
Private_Hugetlb:       0 kB
Swap:                  0 kB
SwapPss:               0 kB
Locked:                0 kB
THPeligible:           0
VmFlags: rd wr mr mw me ac sd 
7b4483e00000-7b4483e28000 r--p 00000000 08:03 7603927                    /usr/lib/x86_64-linux-gnu/libc.so.6
Size:                160 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Rss:                 160 kB
Pss:                   1 kB
Pss_Dirty:             0 kB
Shared_Clean:        160 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:         0 kB
Referenced:          160 kB
Anonymous:             0 kB
KSM:                   0 kB
LazyFree:              0 kB
AnonHugePages:         0 kB
ShmemPmdMapped:        0 kB
FilePmdMapped:         0 kB
Shared_Hugetlb:        0 kB
Private_Hugetlb:       0 kB
Swap:                  0 kB
SwapPss:               0 kB
Locked:                0 kB
THPeligible:           0
VmFlags: rd mr mw me sd 
7b4483e28000-7b4483fbd000 r-xp 00028000 08:03 7603927                    /usr/lib/x86_64-linux-gnu/libc.so.6
Size:               1620 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Rss:                1156 kB
Pss:                   9 kB
Pss_Dirty:             0 kB
Shared_Clean:       1156 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:         0 kB
Referenced:         1156 kB
Anonymous:             0 kB
KSM:                   0 kB
LazyFree:              0 kB
AnonHugePages:         0 kB
ShmemPmdMapped:        0 kB
FilePmdMapped:         0 kB
Shared_Hugetlb:        0 kB
Private_Hugetlb:       0 kB
Swap:                  0 kB
SwapPss:               0 kB
Locked:                0 kB
THPeligible:           0
VmFlags: rd ex mr mw me sd 
7b4483fbd000-7b4484015000 r--p 001bd000 08:03 7603927                    /usr/lib/x86_64-linux-gnu/libc.so.6
Size:                352 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Rss:                 168 kB
Pss:                   1 kB
Pss_Dirty:             0 kB
Shared_Clean:        168 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:         0 kB
Referenced:          168 kB
Anonymous:             0 kB
KSM:                   0 kB
LazyFree:              0 kB
AnonHugePages:         0 kB
ShmemPmdMapped:        0 kB
FilePmdMapped:         0 kB
Shared_Hugetlb:        0 kB
Private_Hugetlb:       0 kB
Swap:                  0 kB
SwapPss:               0 kB
Locked:                0 kB
THPeligible:           0
VmFlags: rd mr mw me sd 
7b4484015000-7b4484016000 ---p 00215000 08:03 7603927                    /usr/lib/x86_64-linux-gnu/libc.so.6
Size:                  4 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Rss:                   0 kB
Pss:                   0 kB
Pss_Dirty:             0 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:         0 kB
Referenced:            0 kB
Anonymous:             0 kB
KSM:                   0 kB
LazyFree:              0 kB
AnonHugePages:         0 kB
ShmemPmdMapped:        0 kB
FilePmdMapped:         0 kB
Shared_Hugetlb:        0 kB
Private_Hugetlb:       0 kB
Swap:                  0 kB
SwapPss:               0 kB
Locked:                0 kB
THPeligible:           0
VmFlags: mr mw me sd 
7b4484016000-7b448401a000 r--p 00215000 08:03 7603927                    /usr/lib/x86_64-linux-gnu/libc.so.6
Size:                 16 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Rss:                  16 kB
Pss:                  16 kB
Pss_Dirty:            16 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:        16 kB
Referenced:           16 kB
Anonymous:            16 kB
KSM:                   0 kB
LazyFree:              0 kB
AnonHugePages:         0 kB
ShmemPmdMapped:        0 kB
FilePmdMapped:         0 kB
Shared_Hugetlb:        0 kB
Private_Hugetlb:       0 kB
Swap:                  0 kB
SwapPss:               0 kB
Locked:                0 kB
THPeligible:           0
VmFlags: rd mr mw me ac sd 
7b448401a000-7b448401c000 rw-p 00219000 08:03 7603927                    /usr/lib/x86_64-linux-gnu/libc.so.6
Size:                  8 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Rss:                   8 kB
Pss:                   8 kB
Pss_Dirty:             8 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:         8 kB
Referenced:            8 kB
Anonymous:             8 kB
KSM:                   0 kB
LazyFree:              0 kB
AnonHugePages:         0 kB
ShmemPmdMapped:        0 kB
FilePmdMapped:         0 kB
Shared_Hugetlb:        0 kB
Private_Hugetlb:       0 kB
Swap:                  0 kB
SwapPss:               0 kB
Locked:                0 kB
THPeligible:           0
VmFlags: rd wr mr mw me ac sd 
7b448401c000-7b4484029000 rw-p 00000000 00:00 0 
Size:                 52 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Rss:                  20 kB
Pss:                  20 kB
Pss_Dirty:            20 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:        20 kB
Referenced:           20 kB
Anonymous:            20 kB
KSM:                   0 kB
LazyFree:              0 kB
AnonHugePages:         0 kB
ShmemPmdMapped:        0 kB
FilePmdMapped:         0 kB
Shared_Hugetlb:        0 kB
Private_Hugetlb:       0 kB
Swap:                  0 kB
SwapPss:               0 kB
Locked:                0 kB
THPeligible:           0
VmFlags: rd wr mr mw me ac sd 
7b448419c000-7b448419f000 rw-p 00000000 00:00 0 
Size:                 12 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Rss:                   8 kB
Pss:                   8 kB
Pss_Dirty:             8 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:         8 kB
Referenced:            8 kB
Anonymous:             8 kB
KSM:                   0 kB
LazyFree:              0 kB
AnonHugePages:         0 kB
ShmemPmdMapped:        0 kB
FilePmdMapped:         0 kB
Shared_Hugetlb:        0 kB
Private_Hugetlb:       0 kB
Swap:                  0 kB
SwapPss:               0 kB
Locked:                0 kB
THPeligible:           0
VmFlags: rd wr mr mw me ac sd 
7b44841b4000-7b44841b6000 rw-p 00000000 00:00 0 
Size:                  8 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Rss:                   4 kB
Pss:                   4 kB
Pss_Dirty:             4 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:         4 kB
Referenced:            4 kB
Anonymous:             4 kB
KSM:                   0 kB
LazyFree:              0 kB
AnonHugePages:         0 kB
ShmemPmdMapped:        0 kB
FilePmdMapped:         0 kB
Shared_Hugetlb:        0 kB
Private_Hugetlb:       0 kB
Swap:                  0 kB
SwapPss:               0 kB
Locked:                0 kB
THPeligible:           0
VmFlags: rd wr mr mw me ac sd 
7b44841b6000-7b44841b8000 r--p 00000000 08:03 7602987                    /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
Size:                  8 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Rss:                   8 kB
Pss:                   0 kB
Pss_Dirty:             0 kB
Shared_Clean:          8 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:         0 kB
Referenced:            8 kB
Anonymous:             0 kB
KSM:                   0 kB
LazyFree:              0 kB
AnonHugePages:         0 kB
ShmemPmdMapped:        0 kB
FilePmdMapped:         0 kB
Shared_Hugetlb:        0 kB
Private_Hugetlb:       0 kB
Swap:                  0 kB
SwapPss:               0 kB
Locked:                0 kB
THPeligible:           0
VmFlags: rd mr mw me sd 
7b44841b8000-7b44841e2000 r-xp 00002000 08:03 7602987                    /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
Size:                168 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Rss:                 168 kB
Pss:                   1 kB
Pss_Dirty:             0 kB
Shared_Clean:        168 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:         0 kB
Referenced:          168 kB
Anonymous:             0 kB
KSM:                   0 kB
LazyFree:              0 kB
AnonHugePages:         0 kB
ShmemPmdMapped:        0 kB
FilePmdMapped:         0 kB
Shared_Hugetlb:        0 kB
Private_Hugetlb:       0 kB
Swap:                  0 kB
SwapPss:               0 kB
Locked:                0 kB
THPeligible:           0
VmFlags: rd ex mr mw me sd 
7b44841e2000-7b44841ed000 r--p 0002c000 08:03 7602987                    /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
Size:                 44 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Rss:                  40 kB
Pss:                   0 kB
Pss_Dirty:             0 kB
Shared_Clean:         40 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:         0 kB
Referenced:           40 kB
Anonymous:             0 kB
KSM:                   0 kB
LazyFree:              0 kB
AnonHugePages:         0 kB
ShmemPmdMapped:        0 kB
FilePmdMapped:         0 kB
Shared_Hugetlb:        0 kB
Private_Hugetlb:       0 kB
Swap:                  0 kB
SwapPss:               0 kB
Locked:                0 kB
THPeligible:           0
VmFlags: rd mr mw me sd 
7b44841ee000-7b44841f0000 r--p 00037000 08:03 7602987                    /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
Size:                  8 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Rss:                   8 kB
Pss:                   8 kB
Pss_Dirty:             8 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:         8 kB
Referenced:            8 kB
Anonymous:             8 kB
KSM:                   0 kB
LazyFree:              0 kB
AnonHugePages:         0 kB
ShmemPmdMapped:        0 kB
FilePmdMapped:         0 kB
Shared_Hugetlb:        0 kB
Private_Hugetlb:       0 kB
Swap:                  0 kB
SwapPss:               0 kB
Locked:                0 kB
THPeligible:           0
VmFlags: rd mr mw me ac sd 
7b44841f0000-7b44841f2000 rw-p 00039000 08:03 7602987                    /usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
Size:                  8 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Rss:                   8 kB
Pss:                   8 kB
Pss_Dirty:             8 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:         8 kB
Referenced:            8 kB
Anonymous:             8 kB
KSM:                   0 kB
LazyFree:              0 kB
AnonHugePages:         0 kB
ShmemPmdMapped:        0 kB
FilePmdMapped:         0 kB
Shared_Hugetlb:        0 kB
Private_Hugetlb:       0 kB
Swap:                  0 kB
SwapPss:               0 kB
Locked:                0 kB
THPeligible:           0
VmFlags: rd wr mr mw me ac sd 
7ffd2ac21000-7ffd2acc7000 rw-p 00000000 00:00 0                          [stack]
Size:                664 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Rss:                 664 kB
Pss:                 664 kB
Pss_Dirty:           664 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:       664 kB
Referenced:          664 kB
Anonymous:           664 kB
KSM:                   0 kB
LazyFree:              0 kB
AnonHugePages:         0 kB
ShmemPmdMapped:        0 kB
FilePmdMapped:         0 kB
Shared_Hugetlb:        0 kB
Private_Hugetlb:       0 kB
Swap:                  0 kB
SwapPss:               0 kB
Locked:                0 kB
THPeligible:           0
VmFlags: rd wr mr mw me gd ac 
7ffd2ad1b000-7ffd2ad1f000 r--p 00000000 00:00 0                          [vvar]
Size:                 16 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Rss:                   0 kB
Pss:                   0 kB
Pss_Dirty:             0 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:         0 kB
Referenced:            0 kB
Anonymous:             0 kB
KSM:                   0 kB
LazyFree:              0 kB
AnonHugePages:         0 kB
ShmemPmdMapped:        0 kB
FilePmdMapped:         0 kB
Shared_Hugetlb:        0 kB
Private_Hugetlb:       0 kB
Swap:                  0 kB
SwapPss:               0 kB
Locked:                0 kB
THPeligible:           0
VmFlags: rd mr pf io de dd sd 
7ffd2ad1f000-7ffd2ad21000 r-xp 00000000 00:00 0                          [vdso]
Size:                  8 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Rss:                   4 kB
Pss:                   0 kB
Pss_Dirty:             0 kB
Shared_Clean:          4 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:         0 kB
Referenced:            4 kB
Anonymous:             0 kB
KSM:                   0 kB
LazyFree:              0 kB
AnonHugePages:         0 kB
ShmemPmdMapped:        0 kB
FilePmdMapped:         0 kB
Shared_Hugetlb:        0 kB
Private_Hugetlb:       0 kB
Swap:                  0 kB
SwapPss:               0 kB
Locked:                0 kB
THPeligible:           0
VmFlags: rd ex mr mw me de sd 
ffffffffff600000-ffffffffff601000 --xp 00000000 00:00 0                  [vsyscall]
Size:                  4 kB
KernelPageSize:        4 kB
MMUPageSize:           4 kB
Rss:                   0 kB
Pss:                   0 kB
Pss_Dirty:             0 kB
Shared_Clean:          0 kB
Shared_Dirty:          0 kB
Private_Clean:         0 kB
Private_Dirty:         0 kB
Referenced:            0 kB
Anonymous:             0 kB
KSM:                   0 kB
LazyFree:              0 kB
AnonHugePages:         0 kB
ShmemPmdMapped:        0 kB
FilePmdMapped:         0 kB
Shared_Hugetlb:        0 kB
Private_Hugetlb:       0 kB
Swap:                  0 kB
SwapPss:               0 kB
Locked:                0 kB
THPeligible:           0
VmFlags: ex 

单个内存映射分析

bash 复制代码
VmFlags: rd wr mr mw me ac sd

这一行列出了与该内存映射相关联的虚拟内存标志(VmFlags)。不过,这些标志的具体含义在不同的上下文中可能有所不同,且并非所有系统都会以这种方式列出它们。通常,这些标志包括读(rd)、写(wr)、执行(me,但这里可能是ex的简写,因为me不是常见的标准标志)、访问(ac,表示该内存区域已被访问)、共享(sh,但这里用的是sd,可能是特定于系统的缩写或错误)等。然而,mr和mw可能不是标准的Linux内存映射标志,可能是特定于工具或版本的。

bash 复制代码
7ffd2ac21000-7ffd2acc7000 rw-p 00000000 00:00 0                          [stack]

这是一个内存映射的地址范围和属性。

7ffd2ac21000-7ffd2acc7000:内存映射的起始和结束地址。

rw-p:权限和类型。r表示可读,w表示可写,-表示不可执行,p表示私有。

00000000:文件偏移量(对于堆栈来说,这通常是0,因为堆栈不是映射自文件的)。

00:00 0:设备号和inode号(对于堆栈来说,这些通常是0,因为堆栈不是通过文件系统设备创建的)。

[stack]:该内存映射的注释,表明这是堆栈内存。

bash 复制代码
Size:                664 kB

该内存映射的总大小。

bash 复制代码
KernelPageSize:        4 kB  
MMUPageSize:           4 kB

内核页面大小和MMU页面大小,通常这两个值相同,并且与系统页面大小相匹配。

bash 复制代码
Rss:                 664 kB  
Pss:                 664 kB  
Pss_Dirty:           664 kB

Rss:当前驻留在物理内存中的页面大小。

Pss:按比例设置的大小,考虑了共享内存的情况。

Pss_Dirty:脏页的Pss值(在这个例子中,由于所有页面都是私有的且全部被修改,所以与Rss相同)。

bash 复制代码
Shared_Clean:          0 kB  
Shared_Dirty:          0 kB  
Private_Clean:         0 kB  
Private_Dirty:       664 kB

这些行显示了干净和脏页面的共享和私有部分的大小。在这个例子中,所有页面都是私有的且都是脏的(即已被修改)。

bash 复制代码
Referenced:          664 kB

自上次内存报告以来被访问过的页面大小。

bash 复制代码
Anonymous:           664 kB

没有映射到任何文件的内存区域(如堆内存或堆栈)的大小。

bash 复制代码
KSM:                   0 kB  
LazyFree:              0 kB  
AnonHugePages:         0 kB  
ShmemPmdMapped:        0 kB  
FilePmdMapped:         0 kB  
Shared_Hugetlb:        0 kB  
Private_Hugetlb:       0 kB

这些行涉及更高级的内存管理技术,如内核同页合并(KSM)、懒释放、大页内存(AnonHugePages)、PMD映射等。在这个例子中,它们都没有被使用。

bash 复制代码
Swap:                  0 kB  
SwapPss:               0 kB

交换到磁盘的页面大小和按比例设置的交换大小。在这个例子中,没有页面被交换。

bash 复制代码
Locked:                0 kB

被锁定的内存量。在这个例子中,没有内存被锁定。

bash 复制代码
THPeligible:           0

这可能表示该内存区域是否符合透明大页(THP)的资格。0表示不符合或THP未启用。不过,请注意,这个字段的确切含义可能取决于您的系统和工具版本。

分析结果以及重点关注

根据以上的分析,我们这里重点关注

bash 复制代码
7ffd2ac21000-7ffd2acc7000 rw-p 00000000 00:00 0                          [stack]
bash 复制代码
Rss:                 664 kB 

RSS 表示实际占用物理内存大小

这个例子中体现出来:

该进程占用 stack 664KB。

这个例子我最终分析出来的结果是:

这里的demo 是 SubscribeHelloWorldClient。

相关推荐
幺零九零零9 分钟前
【C++】socket套接字编程
linux·服务器·网络·c++
TangKenny11 分钟前
计算网络信号
java·算法·华为
肘击鸣的百k路12 分钟前
Java 代理模式详解
java·开发语言·代理模式
城南vision18 分钟前
Docker学习—Docker核心概念总结
java·学习·docker
wyh要好好学习26 分钟前
SpringMVC快速上手
java·spring
尢词28 分钟前
SpringMVC
java·spring·java-ee·tomcat·maven
Mr. zhihao34 分钟前
享元模式在 JDK 中的应用解析
java·享元模式
茶馆大橘38 分钟前
微服务系列五:避免雪崩问题的限流、隔离、熔断措施
java·jmeter·spring cloud·微服务·云原生·架构·sentinel
wrx繁星点点38 分钟前
享元模式:高效管理共享对象的设计模式
java·开发语言·spring·设计模式·maven·intellij-idea·享元模式
真的想不出名儿41 分钟前
Java基础——反射
java·开发语言