Linux

MemAvailable 高於預期

  • February 13, 2019
$ free -h
             total        used        free      shared  buff/cache   available
Mem:          7.7Gi       4.5Gi       692Mi       305Mi       2.5Gi       2.6Gi
Swap:         2.0Gi        25Mi       2.0Gi

我的系統怎麼MemAvailable會這麼高?

當我閱讀核心程式碼時,我認為我們可以MemAvailable用一個類似的公式來近似MemFree + (Buffers + Cached - Shmem)/2 + SReclaimable/2。所以我猜 MemAvailable 會更像 1.8G。

我不認為 0.8G 的差異是由於 Reclaimable Slabs 部分,因為我只有 100M:

$ grep SReclaimable /proc/meminfo
SReclaimable:     106492 kB

$ uname -r
4.20.3-200.fc29.x86_64

$ cat /proc/meminfo
MemTotal:        8042592 kB
MemFree:          708864 kB
MemAvailable:    2740432 kB
Buffers:          225472 kB
Cached:          2289436 kB
SwapCached:         1768 kB
Active:          4367844 kB
Inactive:        2538636 kB
Active(anon):    3443868 kB
Inactive(anon):  1265012 kB
Active(file):     923976 kB
Inactive(file):  1273624 kB
Unevictable:       11528 kB
Mlocked:           11528 kB
SwapTotal:       2097148 kB
SwapFree:        2071412 kB
Dirty:                80 kB
Writeback:            44 kB
AnonPages:       4402684 kB
Mapped:           554452 kB
Shmem:            313044 kB
KReclaimable:     106492 kB
Slab:             249164 kB
SReclaimable:     106492 kB
SUnreclaim:       142672 kB
KernelStack:       17888 kB
PageTables:        37020 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     6118444 kB
Committed_AS:   12077056 kB
VmallocTotal:   34359738367 kB
VmallocUsed:           0 kB
VmallocChunk:          0 kB
Percpu:             2688 kB
HardwareCorrupted:     0 kB
AnonHugePages:   2160640 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:      297524 kB
DirectMap2M:     7968768 kB
DirectMap1G:     1048576 kB

這是如何MemAvailable計算的。您必須從中減去低水位/proc/zoneinfo線,但您的可用記憶體不足為奇;添加MemFree, Active(file),Inactive(file)SReclaimable給出 3012956 KiB。

引用自:https://unix.stackexchange.com/questions/500400