一,检查是否有过多的Lost RAM
可通过如下命令查看结果
adb shell dumpsys meminfo | grep RAM
结果如下:
Applications Memory Usage (in Kilobytes):
Uptime: 347257 Realtime: 347257
Total PSS by process:
189,021K: BeanVRService (pid 1927)
114,683K: com.gwm.app.gwmvrwakeup (pid 2577)
111,974K: system (pid 853)
105,917K: com.gwm.app.hvac (pid 3207)
90,517K: com.android.systemui (pid 1367)
85,671K: com.beantechs.beanmap (pid 14329)
69,019K: com.beantechs.tts.server (pid 2323)
65,958K: com.beantechs.map.watchdog (pid 3336)
62,885K: com.gwm.app.launcher (pid 1692 / activities)
43,224K: com.beantechs.weatherservice (pid 2750)
省略很多
Total RAM: 6,120,992K (status normal)
Free RAM: 2,122,499K ( 203,671K cached pss + 888,700K cached kernel + 1,030,128K free)
Used RAM: 3,044,927K (2,202,219K used pss + 842,708K kernel)
Lost RAM: 953,554K
ZRAM: 12K physical used for 0K in swap (1,048,572K total swap)
Tuning: 512 (large 512), oom 322,560K, restore limit 107,520K (high-end-gfx)
也可以敲 cat /proc/meminfo 查看
二,找到Lost RAM 来源
ION是内核提供的内存管理框架。 Lost RAM与ION相关。
1,查看ION设备节点
adb shell lsof | grep /dev/ion
结果:
[email protected] 458 root 24r CHR 10,62 0t0 14545 /dev/ion
surfaceflinger 626 system 20r CHR 10,62 0t0 14545 /dev/ion
surfaceflinger 626 system 22r CHR 10,62 0t0 14545 /dev/ion
system_server 782 system 115r CHR 10,62 0t0 14545 /dev/ion
system_server 782 system 173r CHR 10,62 0t0 14545 /dev/ion
2,查看DMA BUFFER整体使用情况
adb shell cat /sys/kernel/debug/dma_buf/bufinfo
结果:
Dma-buf Objects:
size flags mode count exp_name buf name
00786432 00000002 00000007 00000001 msm_hab_linux dmabuf2338
Attached Devices:
Total 0 devices attached
00786432 00000002 00000007 00000001 msm_hab_linux dmabuf2337
Attached Devices:
Total 0 devices attached
00028672 00000002 00000007 00000005 ion-system-545-vendor.qti.hard dmabuf2336
Attached Devices:
Total 0 devices attached
...
Total 1619 objects, 765116416 bytes
3,查看dma buf在各个进程的使用情况:
adb shell cat /sys/kernel/debug/dma_buf/dmaprocs | grep PID
如下:
surfaceflinger (PID 629) size: 101464
wmscenelauncher (PID 1928) size: 86856
om.gwm.app.hvac (PID 3431) size: 86848
com.android.car (PID 1142) size: 65136
[email protected] (PID 443) size: 47748
ais_v4l2_proxy (PID 357) size: 46272
system_server (PID 857) size: 21720
ndroid.settings (PID 4639) size: 16364
ndroid.systemui (PID 1157) size: 14980
id.multidisplay (PID 1599) size: 6484
msmartassistant (PID 2342) size: 668
qseecomd (PID 320) size: 544
[email protected] (PID 429) size: 512
gwm.app.account (PID 2735) size: 8
[email protected] (PID 474) size: 8
4,复现问题,查看哪些操作,可以导致模块的size不停增加。如果一直增加说明有异常。
5,adb shell里面查看/sys/kernel/debug/dma_buf/下的dmaprocs和bufinfo,查看异常的dma_buf指向那些模块,并分析问题来源。
6,以上可以发现安卓原生的问题Activity切换的时候,Android会保存快照,申请的GraphicsBuffer如果没有及时释放,会引起内存不足。屏蔽Android快照功能即可。