最近遇到一個Lost RAM占用內存達到1.5GB的問題,所以先統計一下Lost RAM的計算方法:
根據計算公式:
long lostRAM = memInfo.getTotalSizeKb() - (totalPss - totalSwapPss)
- memInfo.getFreeSizeKb() - memInfo.getCachedSizeKb()
- memInfo.getKernelUsedSizeKb() - memInfo.getZramTotalSizeKb();
解讀:
Lost RAM=total memory(減掉kernel reserve部分)-(process total pss - swap占用空間總和(除去native process所占用swap空間))-dumpsys meminfo(free+cached kernel+kernel+ZRAM used見下文)
即:Lost ram=883248-(193417+476988-74453)-(64008+81368+100892+59368)=-18340
Total RAM: 883,248K (status normal)
Free RAM: 338,793K ( 193,417K cached pss + 81,368K cached kernel + 64,008K free)
Used RAM: 577,880K ( 476,988K used pss + 100,892K kernel)
Lost RAM: -18,340K
ZRAM: 59,368K physical used for 179,388K in swap ( 661,184K total swap)
Tuning: 128 (large 256), oom 184,320K, restore limit 61,440K (low-ram)
