神秘的 Linux RAM 使用情况 (5.14)

神秘的 Linux RAM 使用情况 (5.14)

我的系统报告 RAM 使用率 >50%,运行的进程很少,这导致我的系统在我打开任何重要应用程序时立即开始交换。我的内存在用什么?

  • 系统:戴尔 G5 5505 笔记本电脑
  • CPU:锐龙5 4600H
  • 显卡:Radeon RX 5600M
  • 内核:5.14.12(Fedora)
[root@apollo ~]# free -h
               total        used        free      shared  buff/cache   available
Mem:           7.1Gi       3.9Gi       1.6Gi        69Mi       1.6Gi       2.9Gi
Swap:          7.1Gi       527Mi       6.6Gi
[root@apollo ~]# ps -eo rss,pid,comm | sort -rh | head -20
165020  13318 chrome
159116  10484 chrome
113576  10754 chrome
109856  10778 chrome
73456   10533 chrome
67356   10600 chrome
65984   13340 chrome
54128   13369 chrome
52760   10534 chrome
38768    2778 pipewire-pulse
37780   13254 chrome
35660   10630 chrome
28236    2576 Xwayland
24496   10083 alacritty
19372   10543 chrome
15760    2721 pipewire
15276    2545 waybar
14220    2772 waycalbar
11972    2447 sway
11524    1555 tailscaled
[root@apollo ~]# cat /proc/meminfo
MemTotal:        7474768 kB
MemFree:         1681176 kB
MemAvailable:    3046376 kB
Buffers:             132 kB
Cached:          1608296 kB
SwapCached:         4888 kB
Active:           780348 kB
Inactive:        1242848 kB
Active(anon):     108156 kB
Inactive(anon):   379708 kB
Active(file):     672192 kB
Inactive(file):   863140 kB
Unevictable:        5676 kB
Mlocked:            5676 kB
SwapTotal:       7474172 kB
SwapFree:        6935636 kB
Dirty:               368 kB
Writeback:             0 kB
AnonPages:        416420 kB
Mapped:           259452 kB
Shmem:             68036 kB
KReclaimable:     107188 kB
Slab:             266500 kB
SReclaimable:     107188 kB
SUnreclaim:       159312 kB
KernelStack:       12400 kB
PageTables:        22008 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:    11211556 kB
Committed_AS:    5374908 kB
VmallocTotal:   34359738367 kB
VmallocUsed:       73660 kB
VmallocChunk:          0 kB
Percpu:            14400 kB
HardwareCorrupted:     0 kB
AnonHugePages:         0 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
FileHugePages:         0 kB
FilePmdMapped:         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:     5527436 kB
DirectMap2M:     2199552 kB
DirectMap1G:     1048576 kB

删除缓存后echo 3 > /proc/sys/vm/drop_caches情况暂时改善:

[root@apollo ~]# free -h
               total        used        free      shared  buff/cache   available
Mem:           7.1Gi       1.2Gi       5.6Gi        80Mi       401Mi       5.6Gi
Swap:          7.1Gi       524Mi       6.6Gi
[root@apollo ~]# cat /proc/meminfo
MemTotal:        7474768 kB
MemFree:         5915228 kB
MemAvailable:    5958520 kB
Buffers:              36 kB
Cached:           314144 kB
SwapCached:         4888 kB
Active:           255264 kB
Inactive:         478060 kB
Active(anon):     102660 kB
Inactive(anon):   394848 kB
Active(file):     152604 kB
Inactive(file):    83212 kB
Unevictable:        5676 kB
Mlocked:            5676 kB
SwapTotal:       7474172 kB
SwapFree:        6935636 kB
Dirty:              1320 kB
Writeback:             0 kB
AnonPages:        420932 kB
Mapped:           266348 kB
Shmem:             73216 kB
KReclaimable:      62404 kB
Slab:             217648 kB
SReclaimable:      62404 kB
SUnreclaim:       155244 kB
KernelStack:       12192 kB
PageTables:        21992 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:    11211556 kB
Committed_AS:    5331100 kB
VmallocTotal:   34359738367 kB
VmallocUsed:       73532 kB
VmallocChunk:          0 kB
Percpu:            14400 kB
HardwareCorrupted:     0 kB
AnonHugePages:         0 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
FileHugePages:         0 kB
FilePmdMapped:         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:     5527436 kB
DirectMap2M:     2199552 kB
DirectMap1G:     1048576 kB

答案1

我相信这个神秘的 RAM 使用情况的原因是 swap-on-zram,它在 Fedora 33 中默认启用。一旦 zram 被禁用(通过删除 zram-generator-defaults 包),我就不再看到神秘的 RAM 使用情况,我的性能显着提高。我的理论是,交换碎片导致感知到的 RAM 使用量增加,在内存压力下导致大量交换和性能不佳(这个问题的原始动机)。

有关 Fedora 中 zram 的更多信息:https://fedoraproject.org/wiki/Changes/Scale_ZRAM_to_full_memory_size

相关内容