$ sudo smem -t -m > m; head -n5 m; echo; tail m
Map PIDs AVGPSS PSS
/dev/dri/card0 2 0 0
/dev/shm/org.chromium.0P27rF 1 0 0
/dev/shm/org.chromium.1LwGBc 1 0 0
/dev/shm/org.chromium.23Bqe3 1 0 0
/dev/shm/org.mozilla.ipc.23887.6343 2 6772 13544
/dev/shm/org.mozilla.ipc.23935.491 2 6772 13544
/memfd:gdk-wayland 6 2890 17344
/SYSV00000000 6 3759 22556
/usr/lib64/firefox/libxul.so 14 8711 121956
/i915 4 38494 153976
[heap] 208 3201 665971
<anonymous> 222 15859 3520738
-----------------------------------------------------------------
1698 20333 280628 5056008
该系统中未计入“[堆]”(666M) 的 3.5 GB“<anonymous>”内存使用量是多少?
总计Shmem
(包括所有 tmpfs 文件和创业板缓冲液)“仅”约 608M(“608004 kB”)。
$ uname -r # Kernel version
5.0.17-200.fc29.x86_64
$ cat /proc/meminfo
MemTotal: 8042664 kB
MemFree: 426436 kB
MemAvailable: 2521060 kB
Buffers: 266884 kB
Cached: 2576424 kB
SwapCached: 14624 kB
Active: 4242740 kB
Inactive: 2647644 kB
Active(anon): 3097748 kB
Inactive(anon): 1561596 kB
Active(file): 1144992 kB
Inactive(file): 1086048 kB
Unevictable: 203436 kB
Mlocked: 13700 kB
SwapTotal: 2097148 kB
SwapFree: 1472816 kB
Dirty: 112 kB
Writeback: 0 kB
AnonPages: 4241276 kB
Mapped: 760472 kB
Shmem: 608004 kB
KReclaimable: 165768 kB
Slab: 332388 kB
SReclaimable: 165768 kB
SUnreclaim: 166620 kB
KernelStack: 21552 kB
PageTables: 47628 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 6118480 kB
Committed_AS: 15395448 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 0 kB
VmallocChunk: 0 kB
Percpu: 3424 kB
HardwareCorrupted: 0 kB
AnonHugePages: 1796096 kB
ShmemHugePages: 0 kB
ShmemPmdMapped: 0 kB
CmaTotal: 0 kB
CmaFree: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
Hugetlb: 0 kB
DirectMap4k: 483892 kB
DirectMap2M: 7782400 kB
DirectMap1G: 1048576 kB
答案1
您可以对其进行过滤。
$ sudo smem -t -M "<anonymous>" > M; head -n5 M; echo; tail M
PID User Command Swap USS PSS RSS
2098 alan /usr/libexec/gdm-wayland-se 232 0 0 0
11759 alan-sysop /usr/libexec/gdm-wayland-se 232 0 0 0
2306 alan /usr/libexec/ibus-dconf 244 4 4 4
2322 alan /usr/libexec/xdg-permission 232 4 4 4
23887 alan /usr/lib64/firefox/firefox 0 67508 67508 67508
20206 alan /usr/lib64/firefox/firefox 0 67960 67960 67960
25791 alan-sysop /usr/lib64/firefox/firefox 0 68176 68176 68176
2673 alan /usr/bin/gnome-software --g 50184 125620 125620 125620
2220 alan /usr/bin/gnome-shell 16768 139076 139076 139076
25686 alan-sysop /usr/lib64/firefox/firefox 0 212396 212396 212396
19977 alan /usr/lib64/firefox/firefox 0 250900 250900 250900
21812 qemu /usr/bin/qemu-system-x86_64 0 1813964 1813964 1813964
-------------------------------------------------------------------------------
221 11 195308 3471748 3472326 3473492
最大的用户是QEMU虚拟机。然而这仅占一半。各种程序都在使用这样的内存。查看完整列表(写入文件M
),我看到了大量传统的旧程序,包括crond
、atd
、 agetty
和bash
。
它可能反映malloc()
直接使用 分配的大型分配(4096 字节页面或更多)mmap()
。
因此,最好将其视为[heap]
的特殊子集<anonymous>
。并且不要认为<anonymous>
这是奇怪的事情。