计算嵌入式Linux操作系统内存使用的方法

2019-07-13 02:46发布

0. 记录操作系统启动时打印的内存信息。 Memory: 30048k/32768k available (1738k kernel code, 2720k reserved, 483k data, 128k init, 0k highmem)
1. 执行“echo 3 >/proc/sys/vm/drop_caches”命令把caches清除。 # echo 3 >/proc/sys/vm/drop_caches
**** drop_caches_sysctl_handler: all done timer added ...**** 

2. 执行“cat /proc/meminfo”命令查看内存。 # cat /proc/meminfo
MemTotal:          30176 kB
MemFree:           19688 kB
Buffers:               0 kB
Cached:             2416 kB
SwapCached:            0 kB
Active:             2640 kB
Inactive:           1616 kB
Active(anon):       1848 kB
Inactive(anon):        0 kB
Active(file):        792 kB
Inactive(file):     1616 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:          1848 kB
Mapped:             2064 kB
Slab:               4244 kB
SReclaimable:        232 kB
SUnreclaim:         4012 kB
PageTables:          184 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:       15088 kB
Committed_AS:       3668 kB
VmallocTotal:    1048404 kB
VmallocUsed:        1628 kB
VmallocChunk:    1036424 kB

3. 计算公式: 32768 = 30176(kernel code + data + apps) + reserved - init